mirror of
https://github.com/alacritty/alacritty.git
synced 2024-11-18 13:55:23 -05:00
Allow faux scroll amount configuration
It is now possible to configure the amount of lines scrolled with faux scrollback.
This commit is contained in:
parent
aa1f31785e
commit
9797bd72bc
4 changed files with 63 additions and 37 deletions
|
@ -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: ",│`|:\"' ()[]{}<>"
|
||||
|
|
|
@ -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: ",│`|:\"' ()[]{}<>"
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
64
src/input.rs
64
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()[..],
|
||||
|
|
Loading…
Reference in a new issue