diff --git a/src/editor.rs b/src/editor.rs index b1ea346..9276e66 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -73,23 +73,20 @@ impl Editor { } } - pub fn name(&self) -> String { + pub fn title(&self) -> String { if let Some(path) = &self.path { if let Some(name) = path.file_name() { - return name.to_string_lossy().to_string(); + let decorator = if self.unsaved_changes { "*" } else { " " }; + return format!("{}{}", decorator, name.to_string_lossy()); } } - "untitled".into() + "*untitled".into() } pub fn path(&self) -> Option<&PathBuf> { self.path.as_ref() } - pub fn has_unsaved_changes(&self) -> bool { - self.unsaved_changes - } - pub fn enter(&mut self) { self.active = true; self.find_lines(); @@ -227,7 +224,7 @@ impl Editor { "({},{}) {}", self.cursor.line, self.physical_column(), - self.name(), + self.title(), ); } } diff --git a/src/main.rs b/src/main.rs index 7462caf..e9fe3b1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -100,11 +100,7 @@ impl Navigator { queue!(stdout(), SetColors(Colors::new(Color::Black, Color::White))).unwrap(); } queue!(stdout(), MoveTo(1, index as u16 + 1)).unwrap(); - print!( - "{}{}", - editor.has_unsaved_changes().then_some("*").unwrap_or(" "), - editor.name() - ); + print!("{}", editor.title()); queue!(stdout(), ResetColor).unwrap(); }