mirror of
https://github.com/msfjarvis/text-editor.git
synced 2024-06-03 04:18:57 +05:30
feat(editor): add file name to status bar
This commit is contained in:
parent
5ea82d6a71
commit
58e6618e6b
|
@ -7,6 +7,7 @@ use termion::event::Key;
|
|||
const NAME: &str = env!("CARGO_PKG_NAME");
|
||||
const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
const STATUS_BG_COLOR: Rgb = Rgb(26, 28, 30);
|
||||
const STATUS_FG_COLOR: Rgb = Rgb(225, 226, 229);
|
||||
|
||||
pub struct Editor {
|
||||
should_quit: bool,
|
||||
|
@ -209,9 +210,22 @@ impl Editor {
|
|||
}
|
||||
|
||||
fn draw_status_bar(&self) {
|
||||
let spaces = " ".repeat(self.terminal.size().width as usize);
|
||||
let mut status;
|
||||
let width = self.terminal.size().width as usize;
|
||||
let mut file_name = "[No name]".to_string();
|
||||
if let Some(filename) = &self.document.file_name {
|
||||
file_name = filename.to_string();
|
||||
file_name.truncate(20);
|
||||
}
|
||||
status = format!("{}", file_name);
|
||||
if width > status.len() {
|
||||
status.push_str(&" ".repeat(width - status.len()));
|
||||
}
|
||||
status.truncate(width);
|
||||
Terminal::set_bg_color(STATUS_BG_COLOR);
|
||||
println!("{}\r", spaces);
|
||||
Terminal::set_fg_color(STATUS_FG_COLOR);
|
||||
println!("{}\r", status);
|
||||
Terminal::reset_fg_color();
|
||||
Terminal::reset_bg_color();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::Position;
|
||||
use std::io::{self, stdout, Error, Write};
|
||||
use termion::color::{Bg, Reset, Rgb};
|
||||
use termion::color::{Bg, Fg, Reset, Rgb};
|
||||
use termion::event::Key;
|
||||
use termion::input::TermRead;
|
||||
use termion::raw::{IntoRawMode, RawTerminal};
|
||||
|
@ -75,4 +75,12 @@ impl Terminal {
|
|||
pub fn reset_bg_color() {
|
||||
print!("{}", Bg(Reset));
|
||||
}
|
||||
|
||||
pub fn set_fg_color(color: Rgb) {
|
||||
print!("{}", Fg(color));
|
||||
}
|
||||
|
||||
pub fn reset_fg_color() {
|
||||
print!("{}", Fg(Reset));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user