Skip to content

Commit

Permalink
Add '<' and '>' to decrease and increase indentation level respectively.
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulJuliusMartinez committed Aug 30, 2021
1 parent 60f0f06 commit e008a15
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/jless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub fn new(
tty_writer,
command_editor: Editor::<()>::new(),
dimensions: TTYDimensions::default(),
indentation_reduction: 0,
};

Ok(JLess {
Expand Down Expand Up @@ -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?
Expand Down Expand Up @@ -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,
Expand Down
11 changes: 10 additions & 1 deletion src/screenwriter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "▶ ";
Expand Down Expand Up @@ -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)?;
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit e008a15

Please sign in to comment.