updated to gethostname::gethostname

This commit is contained in:
Daniel Knuettel 2024-06-11 14:03:28 +02:00
parent 99f02696ee
commit c8ee51d25e
2 changed files with 8 additions and 4 deletions

View File

@ -12,3 +12,4 @@ path = "src/make_prompt.rs"
[dependencies]
git2="*"
gethostname="*"

View File

@ -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
{
@ -173,12 +175,12 @@ 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";
@ -246,7 +248,7 @@ fn main()
}
{
print!("{}{}", shell_color_str(&"╞[", SH_GREEN)
, shell_color_str(&fixed_width(&getenv("HOSTNAME"), 13), 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"), 13), SH_RED));
print!("{}{}", shell_color_str(&"|", SH_GREEN)
@ -265,4 +267,5 @@ fn main()
{
print!("{} {} ", shell_color_str(&"", SH_GREEN), shell_color_str(&"$", SH_PURPLE));
}
Ok(())
}