Browse Source

feat: add simple directory prompt

main
fdai7451 2 years ago
parent
commit
19c80dd121
  1. 3
      src/builtins/change_prompt.rs
  2. 6
      src/prompt.rs

3
src/builtins/change_prompt.rs

@ -13,6 +13,9 @@ impl Builtin for ChangePrompt {
} else if let Some(style) = args.get(0) { } else if let Some(style) = args.get(0) {
match style.to_lowercase().as_str() { match style.to_lowercase().as_str() {
"none" => config.prompt_style = PromptStyle::None, "none" => config.prompt_style = PromptStyle::None,
"simple-directory" | "simple_directory" | "simpledirectory" => {
config.prompt_style = PromptStyle::SimpleDirectory
}
_ => { _ => {
return Err(ShellError::ExecuteFailure(format!( return Err(ShellError::ExecuteFailure(format!(
"{} is not a valid prompt style", "{} is not a valid prompt style",

6
src/prompt.rs

@ -3,18 +3,24 @@ use std::path::PathBuf;
#[derive(Clone)] #[derive(Clone)]
pub enum PromptStyle { pub enum PromptStyle {
None, None,
SimpleDirectory,
} }
impl PromptStyle { impl PromptStyle {
pub fn fmt_style(&self, path: PathBuf) -> String { pub fn fmt_style(&self, path: PathBuf) -> String {
match self { match self {
PromptStyle::None => self.fmt_none(path), PromptStyle::None => self.fmt_none(path),
PromptStyle::SimpleDirectory => self.fmt_simple_directory(path),
} }
} }
fn fmt_none(&self, _: PathBuf) -> String { fn fmt_none(&self, _: PathBuf) -> String {
return "» ".to_string(); return "» ".to_string();
} }
fn fmt_simple_directory(&self, path: PathBuf) -> String {
return format!("{} » ", path.to_string_lossy());
}
} }
pub struct Prompt { pub struct Prompt {

Loading…
Cancel
Save