From 04c41aaa93c74b9396fa548178e594bb6711d113 Mon Sep 17 00:00:00 2001 From: fdai7451 Date: Sat, 21 Jan 2023 17:22:01 +0100 Subject: [PATCH] refactoring: remove prompt format path argument --- src/prompt.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/prompt.rs b/src/prompt.rs index 0d88615..de2120e 100644 --- a/src/prompt.rs +++ b/src/prompt.rs @@ -1,4 +1,4 @@ -use std::path::PathBuf; +use std::env; #[derive(Clone)] pub enum PromptStyle { @@ -7,18 +7,20 @@ pub enum PromptStyle { } impl PromptStyle { - pub fn fmt_style(&self, path: PathBuf) -> String { + pub fn fmt_style(&self) -> String { match self { - PromptStyle::None => self.fmt_none(path), - PromptStyle::SimpleDirectory => self.fmt_simple_directory(path), + PromptStyle::None => self.fmt_none(), + PromptStyle::SimpleDirectory => self.fmt_simple_directory(), } } - fn fmt_none(&self, _: PathBuf) -> String { + fn fmt_none(&self) -> String { return "» ".to_string(); } - fn fmt_simple_directory(&self, path: PathBuf) -> String { + fn fmt_simple_directory(&self) -> String { + let path = env::current_dir().unwrap_or_default(); + return format!("{} » ", path.to_string_lossy()); } } @@ -35,8 +37,6 @@ impl Prompt { } pub fn get_prompt(&mut self) -> String { - let path = std::env::current_dir().unwrap(); - - return self.style.fmt_style(path); + return self.style.fmt_style(); } }