Skip to content

Commit

Permalink
Show focus indicator next to top level primitives in data mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulJuliusMartinez committed Feb 4, 2022
1 parent bc26351 commit f5d8d65
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/lineprinter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ pub struct LinePrinter<'a, 'b, 'c> {
pub mode: Mode,
pub terminal: &'c mut dyn Terminal,

// Do I need these?
pub node_depth: usize,
pub depth: usize,
pub width: usize,

Expand Down Expand Up @@ -271,7 +271,14 @@ impl<'a, 'b, 'c> LinePrinter<'a, 'b, 'c> {
debug_assert!(row.is_opening_of_container());
row.is_collapsed()
}
_ => return Ok(()),
_ => {
// Print a focused indicator for top-level primitives.
if self.focused && self.node_depth == 0 {
self.terminal.position_cursor_col(0)?;
write!(self.terminal, "{}", FOCUSED_COLLAPSED_CONTAINER)?;
}
return Ok(());
}
};

// Make sure there's enough room for the indicator
Expand Down Expand Up @@ -1044,6 +1051,7 @@ mod tests {
LinePrinter {
mode: Mode::Data,
terminal,
node_depth: 0,
depth: 0,
width: 100,
tab_size: 2,
Expand Down
1 change: 1 addition & 0 deletions src/screenwriter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ impl ScreenWriter {
mode: viewer.mode,
terminal: &mut terminal,

node_depth: row.depth,
depth,
width: self.dimensions.width as usize,
tab_size: 2,
Expand Down

0 comments on commit f5d8d65

Please sign in to comment.