restructure ps.rs
This commit is contained in:
parent
31b16fca17
commit
54ae2f4b1c
37
src/ps.rs
37
src/ps.rs
@ -1,21 +1,26 @@
|
|||||||
use const_format::formatcp;
|
use const_format::formatcp;
|
||||||
use color_print::{cformat, cprint};
|
|
||||||
|
|
||||||
pub const DEFAULT_PS: &str = formatcp!("lambdashell-{}", env!("CARGO_PKG_VERSION"));
|
pub const DEFAULT_PS: &str = formatcp!("lambdashell-{}", env!("CARGO_PKG_VERSION"));
|
||||||
|
|
||||||
pub fn working_dir_name() -> String {
|
struct Ps(String);
|
||||||
std::env::current_dir().map_or("?".to_owned(), |path| {
|
impl Ps {
|
||||||
path.file_name().map_or("?".to_owned(), |name| {
|
fn set(prompt: String) -> Self {
|
||||||
let name_os_string = name.to_os_string();
|
Self(prompt)
|
||||||
match name_os_string == whoami::username_os() && name_os_string != "root" {
|
}
|
||||||
true => "~".to_owned(),
|
|
||||||
false => name.to_string_lossy().to_string(),
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn display(ps1: &String) {
|
fn working_dir_name(&self) -> String {
|
||||||
let working_dir_name = cformat!(" <bold>{}</> ", working_dir_name());
|
std::env::current_dir().map_or("?".to_owned(), |path| {
|
||||||
cprint!("{}{}λ ", ps1, working_dir_name);
|
path.file_name().map_or("?".to_owned(), |name| {
|
||||||
}
|
let name_os_string = name.to_os_string();
|
||||||
|
match name_os_string == whoami::username_os() && name_os_string != "root" {
|
||||||
|
true => "~".to_owned(),
|
||||||
|
false => name.to_string_lossy().to_string(),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn display(&self) {
|
||||||
|
print!("{}", self.0);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user