1
0
Fork 0
mirror of https://github.com/alacritty/alacritty.git synced 2024-11-25 14:05:41 -05:00

Add support for alternate scroll escape

Fixes #2727.
This commit is contained in:
Aleksey Kuznetsov 2019-10-16 00:13:58 +05:00 committed by Christian Duerr
parent 124e98e94e
commit 49380bffd2
8 changed files with 54 additions and 38 deletions

View file

@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Live reload font size from config - Live reload font size from config
- New CLI flag `--hold` for keeping Alacritty opened after its child process exits - New CLI flag `--hold` for keeping Alacritty opened after its child process exits
- Escape sequence to save and restore window title from stack - Escape sequence to save and restore window title from stack
- Alternate scroll escape sequence (`CSI ? 1007 h` / `CSI ? 1007 l`)
### Changed ### Changed
@ -76,6 +77,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Bindings for Super/Command + F1-F12 - Bindings for Super/Command + F1-F12
- Automatic config generation - Automatic config generation
- Deprecated `scrolling.faux_multiplier`, the alternate scroll escape can now be used to disable it
and `scrolling.multiplier` controls the number of scrolled lines
## 0.3.3 ## 0.3.3

View file

@ -87,15 +87,6 @@
# scrollback is enabled (history > 0). # scrollback is enabled (history > 0).
#multiplier: 3 #multiplier: 3
# Faux Scrolling
#
# The `faux_multiplier` 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`.
#
# Specifying `0` will disable faux scrolling.
#faux_multiplier: 3
# Scroll to the bottom when new text is written to the terminal. # Scroll to the bottom when new text is written to the terminal.
#auto_scroll: false #auto_scroll: false

View file

@ -202,6 +202,15 @@ fn print_deprecation_warnings(config: &Config) {
"Config persistent_logging is deprecated; please use debug.persistent_logging instead" "Config persistent_logging is deprecated; please use debug.persistent_logging instead"
); );
} }
if config.scrolling.faux_multiplier().is_some() {
warn!(
target: LOG_TARGET_CONFIG,
"Config scrolling.faux_multiplier is deprecated; the alternate scroll escape can now \
be used to disable it and `scrolling.multiplier` controls the number of scrolled \
lines"
);
}
} }
#[cfg(test)] #[cfg(test)]

View file

@ -551,11 +551,9 @@ impl<'a, T: EventListener, A: ActionContext<T> + 'a> Processor<'a, T, A> {
fn scroll_terminal(&mut self, modifiers: ModifiersState, new_scroll_px: i32) { fn scroll_terminal(&mut self, modifiers: ModifiersState, new_scroll_px: i32) {
let mouse_modes = let mouse_modes =
TermMode::MOUSE_REPORT_CLICK | TermMode::MOUSE_DRAG | TermMode::MOUSE_MOTION; TermMode::MOUSE_REPORT_CLICK | TermMode::MOUSE_DRAG | TermMode::MOUSE_MOTION;
let alt_scroll_modes = TermMode::ALT_SCREEN | TermMode::ALTERNATE_SCROLL;
let height = self.ctx.size_info().cell_height as i32; let height = self.ctx.size_info().cell_height as i32;
// Make sure the new and deprecated setting are both allowed
let faux_multiplier = self.config.scrolling.faux_multiplier() as usize;
if self.ctx.terminal().mode().intersects(mouse_modes) { if self.ctx.terminal().mode().intersects(mouse_modes) {
self.ctx.mouse_mut().scroll_px += new_scroll_px; self.ctx.mouse_mut().scroll_px += new_scroll_px;
@ -565,11 +563,14 @@ impl<'a, T: EventListener, A: ActionContext<T> + 'a> Processor<'a, T, A> {
for _ in 0..lines { for _ in 0..lines {
self.mouse_report(code, ElementState::Pressed, modifiers); self.mouse_report(code, ElementState::Pressed, modifiers);
} }
} else if self.ctx.terminal().mode().contains(TermMode::ALT_SCREEN) } else if self.ctx.terminal().mode().contains(alt_scroll_modes) && !modifiers.shift {
&& faux_multiplier > 0 let multiplier = i32::from(
&& !modifiers.shift self.config
{ .scrolling
self.ctx.mouse_mut().scroll_px += new_scroll_px * faux_multiplier as i32; .faux_multiplier()
.unwrap_or_else(|| self.config.scrolling.multiplier()),
);
self.ctx.mouse_mut().scroll_px += new_scroll_px * multiplier;
let cmd = if new_scroll_px > 0 { b'A' } else { b'B' }; let cmd = if new_scroll_px > 0 { b'A' } else { b'B' };
let lines = (self.ctx.mouse().scroll_px / height).abs(); let lines = (self.ctx.mouse().scroll_px / height).abs();

View file

@ -172,7 +172,8 @@ impl OnDemandLogFile {
Ok(file) => { Ok(file) => {
self.file = Some(io::LineWriter::new(file)); self.file = Some(io::LineWriter::new(file));
self.created.store(true, Ordering::Relaxed); self.created.store(true, Ordering::Relaxed);
let _ = writeln!(io::stdout(), "Created log file at \"{}\"", self.path.display()); let _ =
writeln!(io::stdout(), "Created log file at \"{}\"", self.path.display());
}, },
Err(e) => { Err(e) => {
let _ = writeln!(io::stdout(), "Unable to create log file: {}", e); let _ = writeln!(io::stdout(), "Unable to create log file: {}", e);

View file

@ -408,6 +408,8 @@ pub enum Mode {
ReportFocusInOut = 1004, ReportFocusInOut = 1004,
/// ?1006 /// ?1006
SgrMouse = 1006, SgrMouse = 1006,
/// ?1007
AlternateScroll = 1007,
/// ?1049 /// ?1049
SwapScreenAndSetRestoreCursor = 1049, SwapScreenAndSetRestoreCursor = 1049,
/// ?2004 /// ?2004
@ -438,6 +440,7 @@ impl Mode {
1003 => Mode::ReportAllMouseMotion, 1003 => Mode::ReportAllMouseMotion,
1004 => Mode::ReportFocusInOut, 1004 => Mode::ReportFocusInOut,
1006 => Mode::SgrMouse, 1006 => Mode::SgrMouse,
1007 => Mode::AlternateScroll,
1049 => Mode::SwapScreenAndSetRestoreCursor, 1049 => Mode::SwapScreenAndSetRestoreCursor,
2004 => Mode::BracketedPaste, 2004 => Mode::BracketedPaste,
_ => { _ => {

View file

@ -12,9 +12,11 @@ pub struct Scrolling {
#[serde(deserialize_with = "failure_default")] #[serde(deserialize_with = "failure_default")]
multiplier: ScrollingMultiplier, multiplier: ScrollingMultiplier,
#[serde(deserialize_with = "failure_default")] #[serde(deserialize_with = "failure_default")]
faux_multiplier: ScrollingMultiplier,
#[serde(deserialize_with = "failure_default")]
pub auto_scroll: bool, pub auto_scroll: bool,
// TODO: DEPRECATED
#[serde(deserialize_with = "failure_default")]
faux_multiplier: Option<ScrollingMultiplier>,
} }
impl Scrolling { impl Scrolling {
@ -26,8 +28,8 @@ impl Scrolling {
self.multiplier.0 self.multiplier.0
} }
pub fn faux_multiplier(self) -> u8 { pub fn faux_multiplier(self) -> Option<u8> {
self.faux_multiplier.0 self.faux_multiplier.map(|sm| sm.0)
} }
// Update the history size, used in ref tests // Update the history size, used in ref tests

View file

@ -457,28 +457,29 @@ pub mod mode {
bitflags! { bitflags! {
pub struct TermMode: u16 { pub struct TermMode: u16 {
const SHOW_CURSOR = 0b00_0000_0000_0001; const SHOW_CURSOR = 0b000_0000_0000_0001;
const APP_CURSOR = 0b00_0000_0000_0010; const APP_CURSOR = 0b000_0000_0000_0010;
const APP_KEYPAD = 0b00_0000_0000_0100; const APP_KEYPAD = 0b000_0000_0000_0100;
const MOUSE_REPORT_CLICK = 0b00_0000_0000_1000; const MOUSE_REPORT_CLICK = 0b000_0000_0000_1000;
const BRACKETED_PASTE = 0b00_0000_0001_0000; const BRACKETED_PASTE = 0b000_0000_0001_0000;
const SGR_MOUSE = 0b00_0000_0010_0000; const SGR_MOUSE = 0b000_0000_0010_0000;
const MOUSE_MOTION = 0b00_0000_0100_0000; const MOUSE_MOTION = 0b000_0000_0100_0000;
const LINE_WRAP = 0b00_0000_1000_0000; const LINE_WRAP = 0b000_0000_1000_0000;
const LINE_FEED_NEW_LINE = 0b00_0001_0000_0000; const LINE_FEED_NEW_LINE = 0b000_0001_0000_0000;
const ORIGIN = 0b00_0010_0000_0000; const ORIGIN = 0b000_0010_0000_0000;
const INSERT = 0b00_0100_0000_0000; const INSERT = 0b000_0100_0000_0000;
const FOCUS_IN_OUT = 0b00_1000_0000_0000; const FOCUS_IN_OUT = 0b000_1000_0000_0000;
const ALT_SCREEN = 0b01_0000_0000_0000; const ALT_SCREEN = 0b001_0000_0000_0000;
const MOUSE_DRAG = 0b10_0000_0000_0000; const MOUSE_DRAG = 0b010_0000_0000_0000;
const ANY = 0b11_1111_1111_1111; const ALTERNATE_SCROLL = 0b100_0000_0000_0000;
const ANY = 0b111_1111_1111_1111;
const NONE = 0; const NONE = 0;
} }
} }
impl Default for TermMode { impl Default for TermMode {
fn default() -> TermMode { fn default() -> TermMode {
TermMode::SHOW_CURSOR | TermMode::LINE_WRAP TermMode::SHOW_CURSOR | TermMode::LINE_WRAP | TermMode::ALTERNATE_SCROLL
} }
} }
} }
@ -913,6 +914,9 @@ impl<T> Term<T> {
} }
} }
self.visual_bell.update_config(config); self.visual_bell.update_config(config);
if let Some(0) = config.scrolling.faux_multiplier() {
self.mode.remove(TermMode::ALTERNATE_SCROLL);
}
self.default_cursor_style = config.cursor.style; self.default_cursor_style = config.cursor.style;
self.dynamic_title = config.dynamic_title(); self.dynamic_title = config.dynamic_title();
self.auto_scroll = config.scrolling.auto_scroll; self.auto_scroll = config.scrolling.auto_scroll;
@ -2008,6 +2012,7 @@ impl<T: EventListener> ansi::Handler for Term<T> {
ansi::Mode::ReportFocusInOut => self.mode.insert(TermMode::FOCUS_IN_OUT), ansi::Mode::ReportFocusInOut => self.mode.insert(TermMode::FOCUS_IN_OUT),
ansi::Mode::BracketedPaste => self.mode.insert(TermMode::BRACKETED_PASTE), ansi::Mode::BracketedPaste => self.mode.insert(TermMode::BRACKETED_PASTE),
ansi::Mode::SgrMouse => self.mode.insert(TermMode::SGR_MOUSE), ansi::Mode::SgrMouse => self.mode.insert(TermMode::SGR_MOUSE),
ansi::Mode::AlternateScroll => self.mode.insert(TermMode::ALTERNATE_SCROLL),
ansi::Mode::LineWrap => self.mode.insert(TermMode::LINE_WRAP), ansi::Mode::LineWrap => self.mode.insert(TermMode::LINE_WRAP),
ansi::Mode::LineFeedNewLine => self.mode.insert(TermMode::LINE_FEED_NEW_LINE), ansi::Mode::LineFeedNewLine => self.mode.insert(TermMode::LINE_FEED_NEW_LINE),
ansi::Mode::Origin => self.mode.insert(TermMode::ORIGIN), ansi::Mode::Origin => self.mode.insert(TermMode::ORIGIN),
@ -2048,6 +2053,7 @@ impl<T: EventListener> ansi::Handler for Term<T> {
ansi::Mode::ReportFocusInOut => self.mode.remove(TermMode::FOCUS_IN_OUT), ansi::Mode::ReportFocusInOut => self.mode.remove(TermMode::FOCUS_IN_OUT),
ansi::Mode::BracketedPaste => self.mode.remove(TermMode::BRACKETED_PASTE), ansi::Mode::BracketedPaste => self.mode.remove(TermMode::BRACKETED_PASTE),
ansi::Mode::SgrMouse => self.mode.remove(TermMode::SGR_MOUSE), ansi::Mode::SgrMouse => self.mode.remove(TermMode::SGR_MOUSE),
ansi::Mode::AlternateScroll => self.mode.remove(TermMode::ALTERNATE_SCROLL),
ansi::Mode::LineWrap => self.mode.remove(TermMode::LINE_WRAP), ansi::Mode::LineWrap => self.mode.remove(TermMode::LINE_WRAP),
ansi::Mode::LineFeedNewLine => self.mode.remove(TermMode::LINE_FEED_NEW_LINE), ansi::Mode::LineFeedNewLine => self.mode.remove(TermMode::LINE_FEED_NEW_LINE),
ansi::Mode::Origin => self.mode.remove(TermMode::ORIGIN), ansi::Mode::Origin => self.mode.remove(TermMode::ORIGIN),