diff options
author | Kyohei Uto <kyoheiu@outlook.com> | 2022-10-13 06:01:56 +0900 |
---|---|---|
committer | Kyohei Uto <kyoheiu@outlook.com> | 2022-10-13 06:01:56 +0900 |
commit | 7806ece3a27b46d145fc7bb92fa4973f592acd2a (patch) | |
tree | 31c950e23c93a4186a2b473955ef684988cfa3d3 | |
parent | d9c0bafb085a8e47bde46739cae47a92936a488c (diff) |
Remove termion from layout.rs
-rw-r--r-- | src/config.rs | 4 | ||||
-rw-r--r-- | src/layout.rs | 24 | ||||
-rw-r--r-- | src/state.rs | 2 |
3 files changed, 12 insertions, 18 deletions
diff --git a/src/config.rs b/src/config.rs index 7162daa..dc05a92 100644 --- a/src/config.rs +++ b/src/config.rs @@ -59,13 +59,13 @@ symlink_fg = \"LightYellow\" pub struct Config { pub default: String, pub exec: Option<HashMap<String, Vec<String>>>, - pub color: Color, + pub color: ConfigColor, pub use_full_width: Option<bool>, pub item_name_length: Option<usize>, } #[derive(Deserialize, Debug, Clone)] -pub struct Color { +pub struct ConfigColor { pub dir_fg: Colorname, pub file_fg: Colorname, pub symlink_fg: Colorname, diff --git a/src/layout.rs b/src/layout.rs index 22a5478..edf55f4 100644 --- a/src/layout.rs +++ b/src/layout.rs @@ -3,7 +3,7 @@ use super::errors::FxError; use super::functions::*; use super::state::{FileType, ItemInfo, BEGINNING_ROW}; use super::term::*; -use termion::{clear, color, cursor}; +use crossterm::style::Color; /// cf: https://docs.rs/image/latest/src/image/image.rs.html#84-112 pub const MAX_SIZE_TO_PREVIEW: u64 = 1_000_000_000; @@ -27,7 +27,7 @@ pub struct Layout { pub time_start_pos: u16, pub use_full: Option<bool>, pub option_name_len: Option<usize>, - pub colors: Color, + pub colors: ConfigColor, pub preview: bool, pub preview_start_column: u16, pub preview_width: u16, @@ -121,12 +121,9 @@ impl Layout { //Print preview (wrapping) for (i, line) in content.iter().enumerate() { move_to(self.preview_start_column, BEGINNING_ROW + i as u16); - print!( - "{}{}{}", - color::Fg(color::LightBlack), - line, - color::Fg(color::Reset) - ); + set_color(Some(Color::DarkGrey), None); + print!("{}", line); + reset_color(); if BEGINNING_ROW + i as u16 == self.terminal_row - 1 { break; } @@ -155,7 +152,7 @@ impl Layout { for (i, line) in output.lines().enumerate() { let next_line: u16 = BEGINNING_ROW + (i as u16) + 1; print!("{}", line); - print!("{}", cursor::Goto(self.preview_start_column, next_line)); + move_to(self.preview_start_column, next_line); } Ok(()) } @@ -163,13 +160,10 @@ impl Layout { /// Clear the preview space. fn clear_preview(&self, preview_start_column: u16) { for i in 0..self.terminal_row { - print!( - "{}", - cursor::Goto(preview_start_column, BEGINNING_ROW + i as u16) - ); - print!("{}", clear::UntilNewline); + move_to(preview_start_column, BEGINNING_ROW + i as u16); + clear_until_newline(); } - print!("{}", cursor::Goto(self.preview_start_column, BEGINNING_ROW)); + move_to(self.preview_start_column, BEGINNING_ROW); } } diff --git a/src/state.rs b/src/state.rs index 6ca2f94..3b57de8 100644 --- a/src/state.rs +++ b/src/state.rs @@ -147,7 +147,7 @@ impl State { time_start_pos: time_start, use_full: config.use_full_width, option_name_len: config.item_name_length, - colors: Color { + colors: ConfigColor { dir_fg: config.color.dir_fg, file_fg: config.color.file_fg, symlink_fg: config.color.symlink_fg, |