Make normal scrolling line amount configurable
It is now possible to configure the amount of lines the viewport should scroll when using the normal scrolling mode. This fixes #1160.
This commit is contained in:
parent
231ef51365
commit
dab0eca4a7
|
@ -219,6 +219,12 @@ mouse:
|
|||
# To disable this completely, set `faux_scrollback_lines` to 0.
|
||||
faux_scrollback_lines: 1
|
||||
|
||||
# Normal Scrolling
|
||||
#
|
||||
# Number of lines the viewport will move when scrolling in
|
||||
# the terminal with scrollback enabled (>0).
|
||||
normal_scrolling_lines: 300
|
||||
|
||||
selection:
|
||||
semantic_escape_chars: ",│`|:\"' ()[]{}<>"
|
||||
|
||||
|
|
|
@ -200,6 +200,12 @@ mouse:
|
|||
# To disable this completely, set `faux_scrollback_lines` to 0.
|
||||
faux_scrollback_lines: 1
|
||||
|
||||
# Normal Scrolling
|
||||
#
|
||||
# Number of lines the viewport will move when scrolling in
|
||||
# the terminal with scrollback enabled (>0).
|
||||
normal_scrolling_lines: 3
|
||||
|
||||
selection:
|
||||
semantic_escape_chars: ",│`|:\"' ()[]{}<>"
|
||||
|
||||
|
|
|
@ -85,17 +85,26 @@ pub struct Mouse {
|
|||
/// up/down arrows sent when scrolling in alt screen buffer
|
||||
#[serde(deserialize_with = "deserialize_faux_scrollback_lines")]
|
||||
#[serde(default="default_faux_scrollback_lines")]
|
||||
pub faux_scrollback_lines: usize,
|
||||
pub faux_scrollback_lines: u8,
|
||||
|
||||
/// Number of lines scrolled in normal buffer with scrollback
|
||||
#[serde(deserialize_with = "deserialize_normal_scrolling_lines")]
|
||||
#[serde(default="default_normal_scrolling_lines")]
|
||||
pub normal_scrolling_lines: u8,
|
||||
}
|
||||
|
||||
fn default_faux_scrollback_lines() -> usize {
|
||||
fn default_faux_scrollback_lines() -> u8 {
|
||||
1
|
||||
}
|
||||
|
||||
fn deserialize_faux_scrollback_lines<'a, D>(deserializer: D) -> ::std::result::Result<usize, D::Error>
|
||||
fn default_normal_scrolling_lines() -> u8 {
|
||||
3
|
||||
}
|
||||
|
||||
fn deserialize_faux_scrollback_lines<'a, D>(deserializer: D) -> ::std::result::Result<u8, D::Error>
|
||||
where D: de::Deserializer<'a>
|
||||
{
|
||||
match usize::deserialize(deserializer) {
|
||||
match u8::deserialize(deserializer) {
|
||||
Ok(lines) => Ok(lines),
|
||||
Err(err) => {
|
||||
eprintln!("problem with config: {}; Using default value", err);
|
||||
|
@ -104,6 +113,18 @@ fn deserialize_faux_scrollback_lines<'a, D>(deserializer: D) -> ::std::result::R
|
|||
}
|
||||
}
|
||||
|
||||
fn deserialize_normal_scrolling_lines<'a, D>(deserializer: D) -> ::std::result::Result<u8, D::Error>
|
||||
where D: de::Deserializer<'a>
|
||||
{
|
||||
match u8::deserialize(deserializer) {
|
||||
Ok(lines) => Ok(lines),
|
||||
Err(err) => {
|
||||
eprintln!("problem with config: {}; Using default value", err);
|
||||
Ok(default_normal_scrolling_lines())
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Mouse {
|
||||
fn default() -> Mouse {
|
||||
Mouse {
|
||||
|
@ -113,7 +134,8 @@ impl Default for Mouse {
|
|||
triple_click: ClickHandler {
|
||||
threshold: Duration::from_millis(300),
|
||||
},
|
||||
faux_scrollback_lines: 1,
|
||||
faux_scrollback_lines: default_faux_scrollback_lines(),
|
||||
normal_scrolling_lines: default_normal_scrolling_lines(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
10
src/input.rs
10
src/input.rs
|
@ -34,8 +34,6 @@ use term::SizeInfo;
|
|||
use term::mode::TermMode;
|
||||
use util::fmt::Red;
|
||||
|
||||
const SCROLL_MULTIPLIER: usize = 3;
|
||||
|
||||
/// Processes input from glutin.
|
||||
///
|
||||
/// An escape sequence may be emitted in case specific keys or key combinations
|
||||
|
@ -431,7 +429,6 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> {
|
|||
}
|
||||
|
||||
pub fn on_mouse_wheel(&mut self, delta: MouseScrollDelta, phase: TouchPhase, modifiers: ModifiersState) {
|
||||
let mouse_modes = TermMode::MOUSE_REPORT_CLICK | TermMode::MOUSE_DRAG | TermMode::MOUSE_MOTION;
|
||||
match delta {
|
||||
MouseScrollDelta::LineDelta(_columns, lines) => {
|
||||
let to_scroll = self.ctx.mouse_mut().lines_scrolled + lines;
|
||||
|
@ -441,8 +438,9 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> {
|
|||
65
|
||||
};
|
||||
|
||||
let scrolling_multiplier = self.mouse_config.normal_scrolling_lines;
|
||||
for _ in 0..(to_scroll.abs() as usize) {
|
||||
self.scroll_terminal(code, modifiers, SCROLL_MULTIPLIER)
|
||||
self.scroll_terminal(code, modifiers, scrolling_multiplier)
|
||||
}
|
||||
|
||||
self.ctx.mouse_mut().lines_scrolled = to_scroll % 1.0;
|
||||
|
@ -475,7 +473,7 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> {
|
|||
}
|
||||
}
|
||||
|
||||
fn scroll_terminal(&mut self, code: u8, modifiers: ModifiersState, scroll_multiplier: usize) {
|
||||
fn scroll_terminal(&mut self, code: u8, modifiers: ModifiersState, scroll_multiplier: u8) {
|
||||
debug_assert!(code == 64 || code == 65);
|
||||
|
||||
let faux_scrollback_lines = self.mouse_config.faux_scrollback_lines;
|
||||
|
@ -487,7 +485,7 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> {
|
|||
{
|
||||
// Faux scrolling
|
||||
let cmd = code + 1; // 64 + 1 = A, 65 + 1 = B
|
||||
let mut content = Vec::with_capacity(faux_scrollback_lines * 3);
|
||||
let mut content = Vec::with_capacity(faux_scrollback_lines as usize * 3);
|
||||
for _ in 0..faux_scrollback_lines {
|
||||
content.push(0x1b);
|
||||
content.push(b'O');
|
||||
|
|
Loading…
Reference in New Issue