From e008a1506069aa6ec947f817f2624f34057e6ebb Mon Sep 17 00:00:00 2001 From: Paul Julius Martinez Date: Mon, 30 Aug 2021 12:26:13 -0700 Subject: [PATCH] Add '<' and '>' to decrease and increase indentation level respectively. --- src/jless.rs | 11 ++++++++++- src/screenwriter.rs | 11 ++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/jless.rs b/src/jless.rs index ba4b25a..d54cbc3 100644 --- a/src/jless.rs +++ b/src/jless.rs @@ -46,6 +46,7 @@ pub fn new( tty_writer, command_editor: Editor::<()>::new(), dimensions: TTYDimensions::default(), + indentation_reduction: 0, }; Ok(JLess { @@ -146,6 +147,14 @@ impl JLess { Key::Char('G') | Key::End => Some(Action::FocusBottom), Key::Char('%') => Some(Action::FocusMatchingPair), Key::Char('m') => Some(Action::ToggleMode), + Key::Char('<') => { + self.screen_writer.decrease_indentation_level(); + None + } + Key::Char('>') => { + self.screen_writer.increase_indentation_level(); + None + } Key::Char(':') => { let _readline = self.screen_writer.get_command(); // Something like this? @@ -188,8 +197,8 @@ impl JLess { if let Some(action) = action { self.viewer.perform_action(action); - self.screen_writer.print_viewer(&self.viewer); } + self.screen_writer.print_viewer(&self.viewer); self.screen_writer.print_status_bar( &self.viewer, &self.input_buffer, diff --git a/src/screenwriter.rs b/src/screenwriter.rs index d9d9432..8487ff1 100644 --- a/src/screenwriter.rs +++ b/src/screenwriter.rs @@ -38,6 +38,7 @@ pub struct ScreenWriter { pub tty_writer: AnsiTTYWriter, pub command_editor: Editor<()>, pub dimensions: TTYDimensions, + pub indentation_reduction: u16, } const FOCUSED_LINE: &'static str = "▶ "; @@ -152,7 +153,7 @@ impl ScreenWriter { row: &Row, is_focused: bool, ) -> std::io::Result<()> { - let col = 2 * (row.depth + 1) as u16; + let col = 2 * ((row.depth as u16).saturating_sub(self.indentation_reduction) + 1); if viewer.mode == Mode::Line && is_focused { self.tty_writer.position_cursor(1, row_index + 1)?; write!(self.tty_writer, "{}", FOCUSED_LINE)?; @@ -576,6 +577,14 @@ impl ScreenWriter { } } } + + pub fn decrease_indentation_level(&mut self) { + self.indentation_reduction = self.indentation_reduction.saturating_add(1) + } + + pub fn increase_indentation_level(&mut self) { + self.indentation_reduction = self.indentation_reduction.saturating_sub(1) + } } pub trait TTYWriter {