Skip to content

Commit

Permalink
Some boilerplate preparation for horizontal scorlling.
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulJuliusMartinez committed Jan 17, 2022
1 parent 2c0adf9 commit 553cd38
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 14 deletions.
27 changes: 19 additions & 8 deletions src/jless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,8 @@ pub fn new(
stdout,
color: true,
};
let screen_writer = ScreenWriter {
tty_writer,
command_editor: Editor::<()>::new(),
dimensions: TTYDimensions::default(),
indentation_reduction: 0,
};
let screen_writer =
ScreenWriter::init(tty_writer, Editor::<()>::new(), TTYDimensions::default());

Ok(JLess {
viewer,
Expand Down Expand Up @@ -154,6 +150,18 @@ impl JLess {
jumped_to_search_match = true;
Some(self.jump_to_prev_search_match(count))
}
Key::Char('.') => {
let count = self.parse_input_buffer_as_number();
self.screen_writer
.scroll_focused_line_right(&self.viewer, count);
None
}
Key::Char(',') => {
let count = self.parse_input_buffer_as_number();
self.screen_writer
.scroll_focused_line_left(&self.viewer, count);
None
}
// These may interpret the input buffer some other way
Key::Char('t') => {
if self.input_buffer == "z".as_bytes() {
Expand Down Expand Up @@ -192,6 +200,10 @@ impl JLess {
self.screen_writer.increase_indentation_level();
None
}
Key::Char(';') => {
self.screen_writer.scroll_focused_line_to_an_end(&self.viewer);
None
}
Key::Char(':') => {
let _readline = self.screen_writer.get_command(":");
// Something like this?
Expand Down Expand Up @@ -264,7 +276,6 @@ impl JLess {
|| focused_row_collapsed_state_before
!= self.viewer.flatjson[focused_row_before].is_collapsed())
{
eprintln!("No longer actively searching");
self.search_state.set_no_longer_actively_searching();
}

Expand Down Expand Up @@ -318,7 +329,7 @@ impl JLess {
// Note key_range already includes quotes around key.
let needle = format!("{}: ", &self.viewer.flatjson.1[key_range.clone()]);
self.search_state =
SearchState::initialize_search(dbg!(needle), &self.viewer.flatjson.1, direction);
SearchState::initialize_search(needle, &self.viewer.flatjson.1, direction);
} else {
panic!("Handle object key search initialized not on object key");
}
Expand Down
37 changes: 31 additions & 6 deletions src/screenwriter.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::collections::HashMap;
use std::fmt::Write;

use rustyline::Editor;
Expand All @@ -12,6 +13,7 @@ use crate::lineprinter::JS_IDENTIFIER;
use crate::search::SearchState;
use crate::truncate::TruncationResult::{DoesntFit, NoTruncation, Truncated};
use crate::truncate::{truncate_left_to_fit, truncate_right_to_fit};
use crate::truncatedstrview::TruncatedStrView;
use crate::tuicontrol::{Color as TUIColor, ColorControl};
use crate::types::TTYDimensions;
use crate::viewer::{JsonViewer, Mode};
Expand Down Expand Up @@ -43,13 +45,29 @@ pub struct ScreenWriter {
pub tty_writer: AnsiTTYWriter,
pub command_editor: Editor<()>,
pub dimensions: TTYDimensions,
pub indentation_reduction: u16,

indentation_reduction: u16,
truncated_row_value_views: HashMap<Index, TruncatedStrView>,
}

const PATH_BASE: &'static str = "input";
const SPACE_BETWEEN_PATH_AND_FILENAME: isize = 3;

impl ScreenWriter {
pub fn init(
tty_writer: AnsiTTYWriter,
command_editor: Editor<()>,
dimensions: TTYDimensions,
) -> Self {
ScreenWriter {
tty_writer,
command_editor,
dimensions,
indentation_reduction: 0,
truncated_row_value_views: HashMap::new(),
}
}

pub fn print(
&mut self,
viewer: &JsonViewer,
Expand Down Expand Up @@ -159,7 +177,6 @@ impl ScreenWriter {

let mut label = None;
let index_label: String;
let number_value: String;

// Set up key label.
if let Some(key_range) = &row.key_range {
Expand All @@ -177,10 +194,6 @@ impl ScreenWriter {
}
}

// TODO: It would be great if I could move this match out of here,
// but I need a reference to the string representation of the Value::Number
// value that lives long enough. The Container LineValue also uses some
// local variables.
let value = match &row.value {
Value::OpenContainer { .. } | Value::CloseContainer { .. } => {
lp::LineValue::Container {
Expand Down Expand Up @@ -473,6 +486,18 @@ impl ScreenWriter {
pub fn increase_indentation_level(&mut self) {
self.indentation_reduction = self.indentation_reduction.saturating_sub(1)
}

pub fn scroll_focused_line_right(&mut self, viewer: &JsonViewer, count: usize) {
unimplemented!();
}

pub fn scroll_focused_line_left(&mut self, viewer: &JsonViewer, count: usize) {
unimplemented!();
}

pub fn scroll_focused_line_to_an_end(&mut self, viewer: &JsonViewer) {
unimplemented!();
}
}

pub trait TTYWriter {
Expand Down

0 comments on commit 553cd38

Please sign in to comment.