diff options
author | Canop <cano.petrole@gmail.com> | 2020-12-13 16:41:35 +0100 |
---|---|---|
committer | Canop <cano.petrole@gmail.com> | 2020-12-13 17:22:07 +0100 |
commit | 2c06c7ca0a580618d932325e15d8d40e7640f24d (patch) | |
tree | 5764d009d564a514a285426be6ce497cc65660c9 /src/display | |
parent | ee4f93f4919be4e716bb9b73476473bbc8bd7159 (diff) |
keep selection visible on unfiltering
The selection was sometimes scrolled away on unfiltering.
Also change some formatting.
Diffstat (limited to 'src/display')
-rw-r--r-- | src/display/areas.rs | 6 | ||||
-rw-r--r-- | src/display/cell_size.rs | 17 | ||||
-rw-r--r-- | src/display/crop_writer.rs | 16 | ||||
-rw-r--r-- | src/display/displayable_tree.rs | 21 | ||||
-rw-r--r-- | src/display/filling.rs | 6 | ||||
-rw-r--r-- | src/display/matched_string.rs | 10 | ||||
-rw-r--r-- | src/display/permissions.rs | 6 | ||||
-rw-r--r-- | src/display/screen.rs | 6 |
8 files changed, 48 insertions, 40 deletions
diff --git a/src/display/areas.rs b/src/display/areas.rs index bba65f4..b974184 100644 --- a/src/display/areas.rs +++ b/src/display/areas.rs @@ -20,7 +20,7 @@ pub struct Areas { pub input: Area, pub purpose: Option<Area>, pub pos_idx: usize, // from left to right - pub nb_pos: usize, // number of displayed panels + pub nb_pos: usize, // number of displayed panels } const MINIMAL_PANEL_HEIGHT: u16 = 10; @@ -97,7 +97,7 @@ impl Areas { let nb_pos = slots.len(); #[allow(clippy::needless_range_loop)] for slot_idx in 0..nb_pos { - if slot_idx==nb_pos-1 { + if slot_idx == nb_pos - 1 { panel_width = screen.width - x; } let areas: &mut Areas = match &mut slots[slot_idx] { @@ -113,7 +113,7 @@ impl Areas { }; let y = y + 1; areas.input = Area::new(x, y, panel_width, 1); - if slot_idx==nb_pos-1 { + if slot_idx == nb_pos - 1 { // the char at the bottom right of the terminal should not be touched // (it makes some terminals flicker) so the input area is one char shorter areas.input.width -= 1; diff --git a/src/display/cell_size.rs b/src/display/cell_size.rs index 01f1fc3..b9e002b 100644 --- a/src/display/cell_size.rs +++ b/src/display/cell_size.rs @@ -18,15 +18,18 @@ pub fn cell_size_in_pixels() -> std::io::Result<(u32, u32)> { // see http://www.delorie.com/djgpp/doc/libc/libc_495.html #[repr(C)] struct winsize { - ws_row: c_ushort, /* rows, in characters */ - ws_col: c_ushort, /* columns, in characters */ - ws_xpixel: c_ushort, /* horizontal size, pixels */ - ws_ypixel: c_ushort /* vertical size, pixels */ + ws_row: c_ushort, /* rows, in characters */ + ws_col: c_ushort, /* columns, in characters */ + ws_xpixel: c_ushort, /* horizontal size, pixels */ + ws_ypixel: c_ushort, /* vertical size, pixels */ }; - let w = winsize { ws_row: 0, ws_col: 0, ws_xpixel: 0, ws_ypixel: 0 }; - let r = unsafe { - ioctl(STDOUT_FILENO, TIOCGWINSZ, &w) + let w = winsize { + ws_row: 0, + ws_col: 0, + ws_xpixel: 0, + ws_ypixel: 0, }; + let r = unsafe { ioctl(STDOUT_FILENO, TIOCGWINSZ, &w) }; if r == 0 && w.ws_xpixel > w.ws_col && w.ws_ypixel > w.ws_row { Ok(( (w.ws_xpixel / w.ws_col) as u32, diff --git a/src/display/crop_writer.rs b/src/display/crop_writer.rs index 9042043..8295c50 100644 --- a/src/display/crop_writer.rs +++ b/src/display/crop_writer.rs @@ -1,9 +1,6 @@ use { - super::{TAB_REPLACEMENT, Filling}, - crossterm::{ - QueueableCommand, - style::Print, - }, + super::{Filling, TAB_REPLACEMENT}, + crossterm::{style::Print, QueueableCommand}, std::borrow::Cow, termimad::{ CompoundStyle, @@ -107,7 +104,7 @@ where if len > self.allowed { s.truncate(idx); self.allowed = 0; - return cs.queue(self.w, s) + return cs.queue(self.w, s); } } self.allowed -= len; @@ -125,7 +122,12 @@ where pub fn fill_unstyled(&mut self, filling: &'static Filling) -> Result<()> { self.repeat_unstyled(filling, self.allowed) } - pub fn repeat(&mut self, cs: &CompoundStyle, filling: &'static Filling, mut len: usize) -> Result<()> { + pub fn repeat( + &mut self, + cs: &CompoundStyle, + filling: &'static Filling, + mut len: usize, + ) -> Result<()> { len = len.min(self.allowed); self.allowed -= len; filling.queue_styled(self.w, cs, len) diff --git a/src/display/displayable_tree.rs b/src/display/displayable_tree.rs index 0d519e6..fcb1a3e 100644 --- a/src/display/displayable_tree.rs +++ b/src/display/displayable_tree.rs @@ -16,7 +16,7 @@ use { task_sync::ComputationResult, tree::{Tree, TreeLine, TreeLineType}, }, - chrono::{Local, DateTime, TimeZone}, + chrono::{DateTime, Local, TimeZone}, crossterm::{ cursor, style::{Color, SetBackgroundColor}, @@ -180,8 +180,7 @@ impl<'s, 't> DisplayableTree<'s, 't> { line: &TreeLine, selected: bool, ) -> Result<usize, termimad::Error> { - let (style, char) = - if !line.is_selectable() { + let (style, char) = if !line.is_selectable() { (&self.skin.tree, ' ') } else { match line.git_status.map(|s| s.status) { @@ -207,7 +206,12 @@ impl<'s, 't> DisplayableTree<'s, 't> { ) -> Result<usize, termimad::Error> { let date_time: DateTime<Local> = Local.timestamp(seconds, 0); cond_bg!(date_style, self, selected, self.skin.dates); - cw.queue_g_string(date_style, date_time.format(self.tree.options.date_time_format).to_string())?; + cw.queue_g_string( + date_style, + date_time + .format(self.tree.options.date_time_format) + .to_string(), + )?; Ok(1) } @@ -309,7 +313,10 @@ impl<'s, 't> DisplayableTree<'s, 't> { if extract.needle_start > 0 { cw.queue_str(&extract_style, &extract.extract[0..extract.needle_start])?; } - cw.queue_str(&match_style, &extract.extract[extract.needle_start..extract.needle_end])?; + cw.queue_str( + &match_style, + &extract.extract[extract.needle_start..extract.needle_end], + )?; if extract.needle_end < extract.extract.len() { cw.queue_str(&extract_style, &extract.extract[extract.needle_end..])?; } @@ -377,7 +384,7 @@ impl<'s, 't> DisplayableTree<'s, 't> { /// write the whole tree on the given `W` pub fn write_on<W: Write>(&self, f: &mut W) -> Result<(), ProgramError> { - #[cfg(not(any(target_family="windows",target_os="android")))] + #[cfg(not(any(target_family = "windows", target_os = "android")))] let perm_writer = super::PermWriter::for_tree(&self.skin, &self.tree); let tree = self.tree; @@ -446,7 +453,7 @@ impl<'s, 't> DisplayableTree<'s, 't> { self.write_branch(cw, line_index, line, selected)? } - #[cfg(not(any(target_family="windows",target_os="android")))] + #[cfg(not(any(target_family = "windows", target_os = "android")))] Col::Permission if tree.options.show_permissions => { perm_writer.write_permissions(cw, line, selected)? } diff --git a/src/display/filling.rs b/src/display/filling.rs index 705977b..4939879 100644 --- a/src/display/filling.rs +++ b/src/display/filling.rs @@ -22,7 +22,7 @@ impl Filling { // to allow normal static fillings pub fn from_char(filling_char: char) -> Self { let char_size = String::from(filling_char).len(); - let mut filling_string = String::with_capacity(char_size*FILLING_STRING_CHAR_LEN); + let mut filling_string = String::with_capacity(char_size * FILLING_STRING_CHAR_LEN); for _ in 0..FILLING_STRING_CHAR_LEN { filling_string.push(filling_char); } @@ -40,7 +40,7 @@ impl Filling { { while len > 0 { let sl = len.min(FILLING_STRING_CHAR_LEN); - w.queue(Print(&self.filling_string[0..sl*self.char_size]))?; + w.queue(Print(&self.filling_string[0..sl * self.char_size]))?; len -= sl; } Ok(()) @@ -55,7 +55,7 @@ impl Filling { { while len > 0 { let sl = len.min(FILLING_STRING_CHAR_LEN); - cs.queue_str(w, &self.filling_string[0..sl*self.char_size])?; + cs.queue_str(w, &self.filling_string[0..sl * self.char_size])?; len -= sl; } Ok(()) diff --git a/src/display/matched_string.rs b/src/display/matched_string.rs index 6c940b1..99456b4 100644 --- a/src/display/matched_string.rs +++ b/src/display/matched_string.rs @@ -1,8 +1,6 @@ use { super::{CropWriter, SPACE_FILLING}, - crate::{ - pattern::NameMatch, - }, + crate::pattern::NameMatch, minimad::Alignment, termimad::{CompoundStyle, StrFit}, }; @@ -82,13 +80,13 @@ impl<'a, 'w> MatchedString<'a> { } else if let Some(w) = self.display_width { match self.align { Alignment::Center => { - cw.queue_str(&self.base_style, &format!("{:^w$}", self.string, w=w))?; + cw.queue_str(&self.base_style, &format!("{:^w$}", self.string, w = w))?; } Alignment::Right => { - cw.queue_str(&self.base_style, &format!("{:>w$}", self.string, w=w))?; + cw.queue_str(&self.base_style, &format!("{:>w$}", self.string, w = w))?; } _ => { - cw.queue_str(&self.base_style, &format!("{:<w$}", self.string, w=w))?; + cw.queue_str(&self.base_style, &format!("{:<w$}", self.string, w = w))?; } } } else { diff --git a/src/display/permissions.rs b/src/display/permissions.rs index ed33cc8..9c7f0ae 100644 --- a/src/display/permissions.rs +++ b/src/display/permissions.rs @@ -1,7 +1,5 @@ use { - super::{ - CropWriter, - }, + super::CropWriter, crate::{ errors::ProgramError, permissions, @@ -102,7 +100,7 @@ impl<'s> PermWriter<'s> { Ok(()) } - #[cfg(not(any(target_family="windows",target_os="android")))] + #[cfg(not(any(target_family = "windows", target_os = "android")))] pub fn write_permissions<'w, W: Write>( &self, cw: &mut CropWriter<'w, W>, diff --git a/src/display/screen.rs b/src/display/screen.rs index cf6c3a3..582ebbf 100644 --- a/src/display/screen.rs +++ b/src/display/screen.rs @@ -1,4 +1,5 @@ use { + super::W, crate::{ app::AppContext, errors::ProgramError, @@ -9,7 +10,6 @@ use { terminal::{Clear, ClearType}, QueueableCommand, }, - super::W, termimad::Area, }; @@ -53,8 +53,8 @@ impl Screen { } /// clear the area and everything to the right. /// Should be used with parcimony as it could lead to flickering. - pub fn clear_area_to_right(self, w: &mut W, area: &Area) -> Result<(), ProgramError> { - for y in area.top..area.top+area.height { + pub fn clear_area_to_right(self, w: &mut W, area: &Area) -> Result<(), ProgramError> { + for y in area.top..area.top + area.height { self.goto(w, area.left, y)?; self.clear_line(w)?; } |