Compare commits
No commits in common. "main" and "master" have entirely different histories.
|
@ -12,4 +12,3 @@ path = "src/make_prompt.rs"
|
|||
|
||||
[dependencies]
|
||||
git2="*"
|
||||
gethostname="*"
|
||||
|
|
|
@ -2,8 +2,6 @@ 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
|
||||
{
|
||||
|
@ -12,9 +10,9 @@ fn fixed_width(input: &String, len: usize) -> String
|
|||
|
||||
if clen > len
|
||||
{
|
||||
let cut_to = len - 1_usize;
|
||||
let cut_to = len - 2_usize;
|
||||
let start_from = clen - cut_to;
|
||||
let cutted_result: String = input.chars().skip(start_from).collect();
|
||||
let cutted_result = &input[start_from..];
|
||||
let mut result: String = String::from(PLACE_HOLDER);
|
||||
|
||||
result.push_str(&cutted_result);
|
||||
|
@ -54,11 +52,6 @@ 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) {
|
||||
|
@ -70,11 +63,11 @@ fn battery_info(width_to: usize) -> String
|
|||
|
||||
if status.contains("Charging") || status.contains("Full")
|
||||
{
|
||||
fixed_width(&format!("{SYMB_POWER} {percentage}%"), width_to)
|
||||
fixed_width(&format!("{SYMB_POWER} {percentage}%"), width_to + 1)
|
||||
}
|
||||
else
|
||||
{
|
||||
fixed_width(&format!("{SYMB_BATT} {percentage}%"), width_to - 1)
|
||||
fixed_width(&format!("{SYMB_BATT} {percentage}%"), width_to)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -168,19 +161,19 @@ fn get_editor() -> String
|
|||
|
||||
fn shell_color_str<T: std::fmt::Display>(string_in: &T, color: &str) -> String
|
||||
{
|
||||
format!("\x01\x1b[{color}m\x02{string_in}\x01\x1b[00m\x02")
|
||||
format!("\x1b[{color}m{string_in}\x1b[00m")
|
||||
}
|
||||
|
||||
fn getenv(varname: &str) -> String
|
||||
{
|
||||
match std::env::var(varname)
|
||||
{
|
||||
Ok(var) => var,
|
||||
Err(_err) => {"".to_string()}
|
||||
Ok(hostname) => hostname,
|
||||
Err(_) => "".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
fn main() ->Result<(), OsString>
|
||||
fn main()
|
||||
{
|
||||
const SH_GREEN: &str = "1;32";
|
||||
const SH_RED: &str = "01;31";
|
||||
|
@ -237,22 +230,22 @@ fn main() ->Result<(), OsString>
|
|||
print!("\n");
|
||||
{
|
||||
print!("{}{}", shell_color_str(&"┌[", SH_GREEN)
|
||||
, fixed_width(&get_git_branch(& std::path::Path::new(&raw_cwd)), 13));
|
||||
, battery_info(12));
|
||||
print!("{}{}", shell_color_str(&"|", SH_GREEN)
|
||||
, fixed_width(&get_editor(), 13));
|
||||
, fixed_width(&get_git_branch(& std::path::Path::new(&raw_cwd)), 10));
|
||||
print!("{}{}", shell_color_str(&"|", SH_GREEN)
|
||||
, battery_info(8));
|
||||
, fixed_width(&get_editor(), 12));
|
||||
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(&gethostname().into_string()?, 13), SH_CYAN));
|
||||
, shell_color_str(&fixed_width(&getenv("HOSTNAME"), 12), SH_CYAN));
|
||||
print!("{}{}", shell_color_str(&"|", SH_GREEN)
|
||||
, shell_color_str(&fixed_width(&getenv("USER"), 13), SH_RED));
|
||||
, shell_color_str(&fixed_width(&getenv("USER"), 10), SH_RED));
|
||||
print!("{}{}", shell_color_str(&"|", SH_GREEN)
|
||||
, fixed_width(&cpu_arch, 8));
|
||||
, fixed_width(&cpu_arch, 12));
|
||||
print!("{}{}", shell_color_str(&"|", SH_GREEN)
|
||||
, fixed_width(&bgjobs, 3));
|
||||
|
||||
|
@ -267,5 +260,4 @@ fn main() ->Result<(), OsString>
|
|||
{
|
||||
print!("{} {} ", shell_color_str(&"└", SH_GREEN), shell_color_str(&"$", SH_PURPLE));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user