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 | |
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.
-rw-r--r-- | alacritty.yml | 12 | ||||
-rw-r--r-- | alacritty_macos.yml | 12 | ||||
-rw-r--r-- | src/config.rs | 12 | ||||
-rw-r--r-- | src/input.rs | 64 |
4 files changed, 63 insertions, 37 deletions
diff --git a/alacritty.yml b/alacritty.yml index bf9451c7..0901b7fe 100644 --- a/alacritty.yml +++ b/alacritty.yml @@ -197,9 +197,21 @@ background_opacity: 1.0 mouse_bindings: - { mouse: Middle, action: PasteSelection } +# Mouse settings +# +# The `faux_scrollback_lines` setting controls the number +# of lines the terminal should scroll when the alternate +# screen buffer is active. This is used to allow mouse +# scrolling for applications like `man`. +# To disable this completely, set `faux_scrollback_lines` to 0. +# +# The `double_click` and `triple_click` settings control the time +# alacritty should wait for accepting multiple clicks as one double +# or triple click. mouse: double_click: { threshold: 300 } triple_click: { threshold: 300 } + faux_scrollback_lines: 1 selection: semantic_escape_chars: ",│`|:\"' ()[]{}<>" diff --git a/alacritty_macos.yml b/alacritty_macos.yml index b2b76781..4b44b3f4 100644 --- a/alacritty_macos.yml +++ b/alacritty_macos.yml @@ -178,9 +178,21 @@ background_opacity: 1.0 mouse_bindings: - { mouse: Middle, action: PasteSelection } +# Mouse settings +# +# The `faux_scrollback_lines` setting controls the number +# of lines the terminal should scroll when the alternate +# screen buffer is active. This is used to allow mouse +# scrolling for applications like `man`. +# To disable this completely, set `faux_scrollback_lines` to 0. +# +# The `double_click` and `triple_click` settings control the time +# alacritty should wait for accepting multiple clicks as one double +# or triple click. mouse: double_click: { threshold: 300 } triple_click: { threshold: 300 } + faux_scrollback_lines: 1 selection: semantic_escape_chars: ",│`|:\"' ()[]{}<>" diff --git a/src/config.rs b/src/config.rs index aace4254..e7ab3403 100644 --- a/src/config.rs +++ b/src/config.rs @@ -66,9 +66,13 @@ pub struct Mouse { pub double_click: ClickHandler, pub triple_click: ClickHandler, - /// Send up/down arrow when scrolling in alt screen buffer - #[serde(default="true_bool")] - pub faux_scrollback: bool, + /// up/down arrows sent when scrolling in alt screen buffer + #[serde(default="default_faux_scrollback_lines")] + pub faux_scrollback_lines: usize, +} + +fn default_faux_scrollback_lines() -> usize { + 1 } impl Default for Mouse { @@ -80,7 +84,7 @@ impl Default for Mouse { triple_click: ClickHandler { threshold: Duration::from_millis(300), }, - faux_scrollback: true, + faux_scrollback_lines: 1, } } } 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()[..], |