mirror of
https://github.com/alacritty/alacritty.git
synced 2025-02-10 15:46:10 -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_bindings:
|
||||||
- { mouse: Middle, action: PasteSelection }
|
- { 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:
|
mouse:
|
||||||
double_click: { threshold: 300 }
|
double_click: { threshold: 300 }
|
||||||
triple_click: { threshold: 300 }
|
triple_click: { threshold: 300 }
|
||||||
|
faux_scrollback_lines: 1
|
||||||
|
|
||||||
selection:
|
selection:
|
||||||
semantic_escape_chars: ",│`|:\"' ()[]{}<>"
|
semantic_escape_chars: ",│`|:\"' ()[]{}<>"
|
||||||
|
|
|
@ -178,9 +178,21 @@ background_opacity: 1.0
|
||||||
mouse_bindings:
|
mouse_bindings:
|
||||||
- { mouse: Middle, action: PasteSelection }
|
- { 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:
|
mouse:
|
||||||
double_click: { threshold: 300 }
|
double_click: { threshold: 300 }
|
||||||
triple_click: { threshold: 300 }
|
triple_click: { threshold: 300 }
|
||||||
|
faux_scrollback_lines: 1
|
||||||
|
|
||||||
selection:
|
selection:
|
||||||
semantic_escape_chars: ",│`|:\"' ()[]{}<>"
|
semantic_escape_chars: ",│`|:\"' ()[]{}<>"
|
||||||
|
|
|
@ -66,9 +66,13 @@ pub struct Mouse {
|
||||||
pub double_click: ClickHandler,
|
pub double_click: ClickHandler,
|
||||||
pub triple_click: ClickHandler,
|
pub triple_click: ClickHandler,
|
||||||
|
|
||||||
/// Send up/down arrow when scrolling in alt screen buffer
|
/// up/down arrows sent when scrolling in alt screen buffer
|
||||||
#[serde(default="true_bool")]
|
#[serde(default="default_faux_scrollback_lines")]
|
||||||
pub faux_scrollback: bool,
|
pub faux_scrollback_lines: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn default_faux_scrollback_lines() -> usize {
|
||||||
|
1
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Mouse {
|
impl Default for Mouse {
|
||||||
|
@ -80,7 +84,7 @@ impl Default for Mouse {
|
||||||
triple_click: ClickHandler {
|
triple_click: ClickHandler {
|
||||||
threshold: Duration::from_millis(300),
|
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) {
|
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 |
|
let mouse_modes = mode::TermMode::MOUSE_REPORT_CLICK | mode::TermMode::MOUSE_MOTION | mode::TermMode::SGR_MOUSE;
|
||||||
mode::TermMode::ALT_SCREEN;
|
if !self.ctx.terminal_mode().intersects(mouse_modes | mode::TermMode::ALT_SCREEN) {
|
||||||
if !self.ctx.terminal_mode().intersects(modes) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -391,20 +390,7 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> {
|
||||||
};
|
};
|
||||||
|
|
||||||
for _ in 0..(to_scroll.abs() as usize) {
|
for _ in 0..(to_scroll.abs() as usize) {
|
||||||
if self.mouse_config.faux_scrollback &&
|
self.scroll_terminal(mouse_modes, code)
|
||||||
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.ctx.mouse_mut().lines_scrolled = to_scroll % 1.0;
|
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;
|
let height = self.ctx.size_info().cell_height as i32;
|
||||||
|
|
||||||
while self.ctx.mouse_mut().scroll_px.abs() >= height {
|
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;
|
self.ctx.mouse_mut().scroll_px -= height;
|
||||||
64
|
64
|
||||||
} else {
|
} else {
|
||||||
|
@ -428,20 +414,7 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> {
|
||||||
65
|
65
|
||||||
};
|
};
|
||||||
|
|
||||||
if self.mouse_config.faux_scrollback &&
|
self.scroll_terminal(mouse_modes, code)
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
_ => (),
|
_ => (),
|
||||||
|
@ -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) {
|
pub fn on_focus_change(&mut self, is_focused: bool) {
|
||||||
if self.ctx.terminal_mode().contains(mode::TermMode::FOCUS_IN_OUT) {
|
if self.ctx.terminal_mode().contains(mode::TermMode::FOCUS_IN_OUT) {
|
||||||
let chr = if is_focused {
|
let chr = if is_focused {
|
||||||
|
@ -702,7 +699,8 @@ mod tests {
|
||||||
},
|
},
|
||||||
triple_click: ClickHandler {
|
triple_click: ClickHandler {
|
||||||
threshold: Duration::from_millis(1000),
|
threshold: Duration::from_millis(1000),
|
||||||
}
|
},
|
||||||
|
faux_scrollback_lines: 1,
|
||||||
},
|
},
|
||||||
key_bindings: &config.key_bindings()[..],
|
key_bindings: &config.key_bindings()[..],
|
||||||
mouse_bindings: &config.mouse_bindings()[..],
|
mouse_bindings: &config.mouse_bindings()[..],
|
||||||
|
|
Loading…
Add table
Reference in a new issue