Skip to content

Commit

Permalink
Change Pager::set_line_wrapping to Pager::horizontal_scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
AMythicDev committed Feb 9, 2024
1 parent c4344bd commit dc9aced
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
19 changes: 19 additions & 0 deletions src/input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
pub(crate) mod definitions;
pub(crate) mod event_wrapper;

pub use crossterm::event as crossterm_event;

#[cfg(feature = "search")]
Expand Down Expand Up @@ -113,6 +114,7 @@ pub enum InputEvent {
Number(char),
/// Restore the original prompt
RestorePrompt,
HorizontalScroll(bool),
/// Tells the event hadler to not do anything for this event
///
/// This is extremely useful when you want to execute arbitrary code on events without
Expand Down Expand Up @@ -260,6 +262,11 @@ where
InputEvent::UpdateUpperMark(ps.upper_mark.saturating_add(5))
});

map.add_key_events(&["c-s-h"], |_, ps| {
InputEvent::HorizontalScroll(!ps.line_wrapping)
});
// TODO: Add keybindings for left right scrolling

map.add_resize_event(|ev, _| {
let Event::Resize(cols, rows) = ev else {
unreachable!();
Expand Down Expand Up @@ -456,21 +463,33 @@ impl InputClassifier for DefaultInputClassifier {
}) => Some(InputEvent::Exit),

// Horizontal scrolling
Event::Key(KeyEvent {
code: KeyCode::Char('h'),
modifiers,
..
}) if modifiers == KeyModifiers::CONTROL.intersection(KeyModifiers::SHIFT) => {
Some(InputEvent::HorizontalScroll(!ps.line_wrapping))
}

Event::Key(KeyEvent {
code: KeyCode::Char('h'),
modifiers: KeyModifiers::NONE,
..
})
| Event::Key(KeyEvent {
code: KeyCode::Left,
modifiers: KeyModifiers::NONE,
..
}) => Some(InputEvent::UpdateLeftMark(ps.left_mark.saturating_sub(1))),
Event::Key(KeyEvent {
code: KeyCode::Char('l'),
modifiers: KeyModifiers::NONE,
..
})
| Event::Key(KeyEvent {
code: KeyCode::Right,
modifiers: KeyModifiers::NONE,
..
}) => Some(InputEvent::UpdateLeftMark(ps.left_mark.saturating_add(1))),

// Search
Expand Down
10 changes: 5 additions & 5 deletions src/pager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,9 @@ impl Pager {
Ok(self.tx.send(Command::SetRunNoOverflow(val))?)
}

/// Control whether to wrap lines or not
/// Whether to allow scrolling horizontally
///
/// Setting this to `false` implicitly turns on horizontal scrolling. By default hhis is set to true.
/// Setting this to `true` implicitly disables line wrapping
///
/// # Error
/// This function will return a [`Err(MinusError::Communication)`](MinusError::Communication) if the data
Expand All @@ -229,10 +229,10 @@ impl Pager {
/// use minus::Pager;
///
/// let pager = Pager::new();
/// pager.set_line_wrapping(false).expect("Failed to communicate with the pager");
/// pager.horizontal_scroll(true).expect("Failed to communicate with the pager");
/// ```
pub fn set_line_wrapping(&self, value: bool) -> Result<(), MinusError> {
Ok(self.tx.send(Command::LineWrapping(value))?)
pub fn horizontal_scroll(&self, value: bool) -> Result<(), MinusError> {
Ok(self.tx.send(Command::LineWrapping(!value))?)
}

/// Set a custom input classifer function.
Expand Down

0 comments on commit dc9aced

Please sign in to comment.