Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
d9c63253aa | |||
066a86539e | |||
c8ee51d25e | |||
99f02696ee | |||
15e15322d5 | |||
c05c7874e3 | |||
af84040321 |
|
@ -12,3 +12,4 @@ path = "src/make_prompt.rs"
|
|||
|
||||
[dependencies]
|
||||
git2="*"
|
||||
gethostname="*"
|
||||
|
|
|
@ -2,6 +2,8 @@ use std::fs::File;
|
|||
use std::io::Read;
|
||||
use std::io::BufReader;
|
||||
use std::io::BufRead;
|
||||
use gethostname::gethostname;
|
||||
use std::ffi::OsString;
|
||||
|
||||
fn fixed_width(input: &String, len: usize) -> String
|
||||
{
|
||||
|
@ -10,9 +12,9 @@ fn fixed_width(input: &String, len: usize) -> String
|
|||
|
||||
if clen > len
|
||||
{
|
||||
let cut_to = len - 2_usize;
|
||||
let cut_to = len - 1_usize;
|
||||
let start_from = clen - cut_to;
|
||||
let cutted_result = &input[start_from..];
|
||||
let cutted_result: String = input.chars().skip(start_from).collect();
|
||||
let mut result: String = String::from(PLACE_HOLDER);
|
||||
|
||||
result.push_str(&cutted_result);
|
||||
|
@ -52,6 +54,11 @@ fn battery_info(width_to: usize) -> String
|
|||
|
||||
let mut percentage = String::new();
|
||||
let _ = file.read_to_string(&mut percentage);
|
||||
|
||||
if percentage.ends_with('\n')
|
||||
{
|
||||
percentage.pop();
|
||||
}
|
||||
|
||||
let status_path = bat_path.join("status");
|
||||
let mut file = match File::open(&status_path) {
|
||||
|
@ -63,11 +70,11 @@ fn battery_info(width_to: usize) -> String
|
|||
|
||||
if status.contains("Charging") || status.contains("Full")
|
||||
{
|
||||
fixed_width(&format!("{SYMB_POWER} {percentage}%"), width_to + 1)
|
||||
fixed_width(&format!("{SYMB_POWER} {percentage}%"), width_to)
|
||||
}
|
||||
else
|
||||
{
|
||||
fixed_width(&format!("{SYMB_BATT} {percentage}%"), width_to)
|
||||
fixed_width(&format!("{SYMB_BATT} {percentage}%"), width_to - 1)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -161,19 +168,19 @@ fn get_editor() -> String
|
|||
|
||||
fn shell_color_str<T: std::fmt::Display>(string_in: &T, color: &str) -> String
|
||||
{
|
||||
format!("\x1b[{color}m{string_in}\x1b[00m")
|
||||
format!("\x01\x1b[{color}m\x02{string_in}\x01\x1b[00m\x02")
|
||||
}
|
||||
|
||||
fn getenv(varname: &str) -> String
|
||||
{
|
||||
match std::env::var(varname)
|
||||
{
|
||||
Ok(hostname) => hostname,
|
||||
Err(_) => "".to_string()
|
||||
Ok(var) => var,
|
||||
Err(_err) => {"".to_string()}
|
||||
}
|
||||
}
|
||||
|
||||
fn main()
|
||||
fn main() ->Result<(), OsString>
|
||||
{
|
||||
const SH_GREEN: &str = "1;32";
|
||||
const SH_RED: &str = "01;31";
|
||||
|
@ -230,22 +237,22 @@ fn main()
|
|||
print!("\n");
|
||||
{
|
||||
print!("{}{}", shell_color_str(&"┌[", SH_GREEN)
|
||||
, battery_info(12));
|
||||
, fixed_width(&get_git_branch(& std::path::Path::new(&raw_cwd)), 13));
|
||||
print!("{}{}", shell_color_str(&"|", SH_GREEN)
|
||||
, fixed_width(&get_git_branch(& std::path::Path::new(&raw_cwd)), 10));
|
||||
, fixed_width(&get_editor(), 13));
|
||||
print!("{}{}", shell_color_str(&"|", SH_GREEN)
|
||||
, fixed_width(&get_editor(), 12));
|
||||
, battery_info(8));
|
||||
print!("{}{}", shell_color_str(&"|", SH_GREEN)
|
||||
, fixed_width(lastexit, 3));
|
||||
println!("{}", shell_color_str(&"]┐", SH_GREEN));
|
||||
}
|
||||
{
|
||||
print!("{}{}", shell_color_str(&"╞[", SH_GREEN)
|
||||
, shell_color_str(&fixed_width(&getenv("HOSTNAME"), 12), SH_CYAN));
|
||||
, shell_color_str(&fixed_width(&gethostname().into_string()?, 13), SH_CYAN));
|
||||
print!("{}{}", shell_color_str(&"|", SH_GREEN)
|
||||
, shell_color_str(&fixed_width(&getenv("USER"), 10), SH_RED));
|
||||
, shell_color_str(&fixed_width(&getenv("USER"), 13), SH_RED));
|
||||
print!("{}{}", shell_color_str(&"|", SH_GREEN)
|
||||
, fixed_width(&cpu_arch, 12));
|
||||
, fixed_width(&cpu_arch, 8));
|
||||
print!("{}{}", shell_color_str(&"|", SH_GREEN)
|
||||
, fixed_width(&bgjobs, 3));
|
||||
|
||||
|
@ -260,4 +267,5 @@ fn main()
|
|||
{
|
||||
print!("{} {} ", shell_color_str(&"└", SH_GREEN), shell_color_str(&"$", SH_PURPLE));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user