show unsaved changes in editor view

This commit is contained in:
Crispy 2023-03-14 13:04:51 +01:00
parent baba71fff7
commit 295982f6e6
2 changed files with 6 additions and 13 deletions

View file

@ -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(),
);
}
}

View file

@ -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();
}