diff options
Diffstat (limited to 'src/prompt.rs')
-rw-r--r-- | src/prompt.rs | 21 |
1 files changed, 4 insertions, 17 deletions
diff --git a/src/prompt.rs b/src/prompt.rs index acb11e4..e70c958 100644 --- a/src/prompt.rs +++ b/src/prompt.rs @@ -1,10 +1,7 @@ -use std::io::Write; - -#[path = "user.rs"] mod user; pub struct Prompt { - ps1: std::string::String, + pub ps1: std::string::String, pub home: std::path::PathBuf, } @@ -14,7 +11,7 @@ impl Prompt { let hostname = user::hostname()?; let ready = if username == "root" { "#" } else { "$" }.to_owned(); - let ps1 = match std::env::var("PRMOPT") { + let ps1 = match std::env::var("PROMPT") { Ok(val) => val, Err(_) => String::from(" {USER}@{HOST} [{PWD}]\n{$} "), } @@ -30,23 +27,13 @@ impl Prompt { Ok(Prompt { ps1, home }) } - pub fn print(&self, pwd: &std::path::PathBuf) { - if cfg!(debug_assertions) { - println!("pwd={}", pwd.display()); - } - + pub fn print(&self, pwd: &std::path::PathBuf) -> std::string::String { let path = if pwd.starts_with(&self.home) { "~".to_owned() + &pwd.strip_prefix(&self.home).unwrap().display().to_string() } else { pwd.display().to_string() }; - let ps1 = self.ps1.replace("{PWD}", &path); - - print!("{}", ps1); - match std::io::stdout().flush() { - Ok(_) => {} - Err(_) => println!(""), - }; + self.ps1.replace("{PWD}", &path) } } |