diff options
author | Christian Dürr <contact@christianduerr.com> | 2017-12-25 22:15:41 +0100 |
---|---|---|
committer | Joe Wilm <jwilm@users.noreply.github.com> | 2018-01-02 08:24:03 -0800 |
commit | 9797bd72bca6ee496561714dc1cda4071bebf045 (patch) | |
tree | 8d8dece9b8223120873bceff8380f0dc52653427 /src/input.rs | |
parent | aa1f31785e754107fab154002abf9bc0b129aad1 (diff) | |
download | alacritty-9797bd72bca6ee496561714dc1cda4071bebf045.tar.gz alacritty-9797bd72bca6ee496561714dc1cda4071bebf045.zip |
Allow faux scroll amount configuration
It is now possible to configure the amount of lines
scrolled with faux scrollback.
Diffstat (limited to 'src/input.rs')
-rw-r--r-- | src/input.rs | 64 |
1 files changed, 31 insertions, 33 deletions
diff --git a/src/input.rs b/src/input.rs index ac4078ee..8b66cb61 100644 --- a/src/input.rs +++ b/src/input.rs @@ -375,9 +375,8 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> { } pub fn on_mouse_wheel(&mut self, delta: MouseScrollDelta, phase: TouchPhase) { - let modes = mode::TermMode::MOUSE_REPORT_CLICK | mode::TermMode::MOUSE_MOTION | mode::TermMode::SGR_MOUSE | - mode::TermMode::ALT_SCREEN; - if !self.ctx.terminal_mode().intersects(modes) { + let mouse_modes = mode::TermMode::MOUSE_REPORT_CLICK | mode::TermMode::MOUSE_MOTION | mode::TermMode::SGR_MOUSE; + if !self.ctx.terminal_mode().intersects(mouse_modes | mode::TermMode::ALT_SCREEN) { return; } @@ -391,20 +390,7 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> { }; for _ in 0..(to_scroll.abs() as usize) { - if self.mouse_config.faux_scrollback && - self.ctx.terminal_mode().intersects(mode::TermMode::ALT_SCREEN) - { - // Faux scrolling - if code == 64 { - // Scroll up one line - self.ctx.write_to_pty("\x1bOA".as_bytes()); - } else { - // Scroll down one line - self.ctx.write_to_pty("\x1bOB".as_bytes()); - } - } else { - self.normal_mouse_report(code); - } + self.scroll_terminal(mouse_modes, code) } self.ctx.mouse_mut().lines_scrolled = to_scroll % 1.0; @@ -420,7 +406,7 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> { let height = self.ctx.size_info().cell_height as i32; while self.ctx.mouse_mut().scroll_px.abs() >= height { - let button = if self.ctx.mouse_mut().scroll_px > 0 { + let code = if self.ctx.mouse_mut().scroll_px > 0 { self.ctx.mouse_mut().scroll_px -= height; 64 } else { @@ -428,20 +414,7 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> { 65 }; - if self.mouse_config.faux_scrollback && - self.ctx.terminal_mode().intersects(mode::TermMode::ALT_SCREEN) - { - // Faux scrolling - if button == 64 { - // Scroll up one line - self.ctx.write_to_pty("\x1bOA".as_bytes()); - } else { - // Scroll down one line - self.ctx.write_to_pty("\x1bOB".as_bytes()); - } - } else { - self.normal_mouse_report(button); - } + self.scroll_terminal(mouse_modes, code) } }, _ => (), @@ -450,6 +423,30 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> { } } + fn scroll_terminal(&mut self, mouse_modes: TermMode, code: u8) { + let faux_scrollback_lines = self.mouse_config.faux_scrollback_lines; + if self.ctx.terminal_mode().intersects(mouse_modes) { + self.normal_mouse_report(code); + } else if faux_scrollback_lines > 0 { + // Faux scrolling + if code == 64 { + // Scroll up by `faux_scrollback_lines` + let mut content = String::with_capacity(faux_scrollback_lines * 3); + for _ in 0..faux_scrollback_lines { + content = content + "\x1bOA"; + } + self.ctx.write_to_pty(content.into_bytes()); + } else { + // Scroll down by `faux_scrollback_lines` + let mut content = String::with_capacity(faux_scrollback_lines * 3); + for _ in 0..faux_scrollback_lines { + content = content + "\x1bOB"; + } + self.ctx.write_to_pty(content.into_bytes()); + } + } + } + pub fn on_focus_change(&mut self, is_focused: bool) { if self.ctx.terminal_mode().contains(mode::TermMode::FOCUS_IN_OUT) { let chr = if is_focused { @@ -702,7 +699,8 @@ mod tests { }, triple_click: ClickHandler { threshold: Duration::from_millis(1000), - } + }, + faux_scrollback_lines: 1, }, key_bindings: &config.key_bindings()[..], mouse_bindings: &config.mouse_bindings()[..], |