From 295982f6e6e01e316f58666e187fd7e03b236c1c Mon Sep 17 00:00:00 2001 From: CrispyPin Date: Tue, 14 Mar 2023 13:04:51 +0100 Subject: [PATCH] show unsaved changes in editor view --- src/editor.rs | 13 +++++-------- src/main.rs | 6 +----- 2 files changed, 6 insertions(+), 13 deletions(-) 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(); }