diff --git a/alacritty.yml b/alacritty.yml index 4dcdbb2b..d11e8a19 100644 --- a/alacritty.yml +++ b/alacritty.yml @@ -33,8 +33,24 @@ window: # Setting this to false will result in window without borders and title bar. decorations: true -# How many lines of scrollback to keep -scroll_history: 10000 +scrolling: + # How many lines of scrollback to keep, + # '0' will disable scrolling. + history: 10000 + + # Number of lines the viewport will move for every line + # scrolled when scrollback is enabled (history > 0). + multiplier: 1 + + # 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`. + # + # To disable this completely, set `faux_multiplier` to 0. + faux_multiplier: 3 # Display tabs using this many cells (changes require restart) tabspaces: 8 @@ -209,22 +225,6 @@ mouse: double_click: { threshold: 300 } triple_click: { threshold: 300 } - # Faux Scrollback - # - # 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. - faux_scrollback_lines: 1 - - # Normal Scrolling - # - # Number of lines the viewport will move when scrolling in - # the terminal with scrollback enabled (>0). - normal_scrolling_lines: 3 - selection: semantic_escape_chars: ",│`|:\"' ()[]{}<>" diff --git a/alacritty_macos.yml b/alacritty_macos.yml index 08287c87..de8316af 100644 --- a/alacritty_macos.yml +++ b/alacritty_macos.yml @@ -31,8 +31,24 @@ window: # Setting this to false will result in window without borders and title bar. decorations: true -# How many lines of scrollback to keep -scroll_history: 10000 +scrolling: + # How many lines of scrollback to keep, + # '0' will disable scrolling. + history: 10000 + + # Number of lines the viewport will move for every line + # scrolled when scrollback is enabled (history > 0). + 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`. + # + # To disable this completely, set `faux_multiplier` to 0. + faux_multiplier: 3 # Display tabs using this many cells (changes require restart) tabspaces: 8 @@ -190,22 +206,6 @@ mouse: double_click: { threshold: 300 } triple_click: { threshold: 300 } - # Faux Scrollback - # - # 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. - faux_scrollback_lines: 1 - - # Normal Scrolling - # - # Number of lines the viewport will move when scrolling in - # the terminal with scrollback enabled (>0). - normal_scrolling_lines: 3 - selection: semantic_escape_chars: ",│`|:\"' ()[]{}<>" diff --git a/src/config.rs b/src/config.rs index d0741d9e..a7f3dbd6 100644 --- a/src/config.rs +++ b/src/config.rs @@ -82,47 +82,9 @@ pub struct Mouse { #[serde(default, deserialize_with = "failure_default")] pub triple_click: ClickHandler, - /// up/down arrows sent when scrolling in alt screen buffer - #[serde(deserialize_with = "deserialize_faux_scrollback_lines")] - #[serde(default="default_faux_scrollback_lines")] - pub faux_scrollback_lines: u8, - - /// Number of lines scrolled in normal buffer with scrollback - #[serde(deserialize_with = "deserialize_normal_scrolling_lines")] - #[serde(default="default_normal_scrolling_lines")] - pub normal_scrolling_lines: u8, -} - -fn default_faux_scrollback_lines() -> u8 { - 1 -} - -fn default_normal_scrolling_lines() -> u8 { - 3 -} - -fn deserialize_faux_scrollback_lines<'a, D>(deserializer: D) -> ::std::result::Result - where D: de::Deserializer<'a> -{ - match u8::deserialize(deserializer) { - Ok(lines) => Ok(lines), - Err(err) => { - eprintln!("problem with config: {}; Using default value", err); - Ok(default_faux_scrollback_lines()) - }, - } -} - -fn deserialize_normal_scrolling_lines<'a, D>(deserializer: D) -> ::std::result::Result - where D: de::Deserializer<'a> -{ - match u8::deserialize(deserializer) { - Ok(lines) => Ok(lines), - Err(err) => { - eprintln!("problem with config: {}; Using default value", err); - Ok(default_normal_scrolling_lines()) - }, - } + // TODO: DEPRECATED + #[serde(default)] + pub faux_scrollback_lines: Option, } impl Default for Mouse { @@ -134,8 +96,7 @@ impl Default for Mouse { triple_click: ClickHandler { threshold: Duration::from_millis(300), }, - faux_scrollback_lines: default_faux_scrollback_lines(), - normal_scrolling_lines: default_normal_scrolling_lines(), + faux_scrollback_lines: None, } } } @@ -420,12 +381,8 @@ pub struct Config { tabspaces: usize, /// How much scrolling history to keep - #[serde(default="default_scroll_history", deserialize_with="deserialize_scroll_history")] - scroll_history: u32, -} - -fn default_scroll_history() -> u32 { - 10_000 + #[serde(default, deserialize_with="failure_default")] + scrolling: Scrolling, } fn deserialize_scroll_history<'a, D>(deserializer: D) -> ::std::result::Result @@ -521,6 +478,63 @@ impl Default for Config { } } +/// Struct for scrolling related settings +#[derive(Copy, Clone, Debug, Deserialize)] +pub struct Scrolling { + #[serde(deserialize_with="deserialize_scrolling_history")] + #[serde(default="default_scrolling_history")] + pub history: u32, + #[serde(deserialize_with="deserialize_scrolling_multiplier")] + #[serde(default="default_scrolling_multiplier")] + pub multiplier: u8, + #[serde(deserialize_with="deserialize_scrolling_multiplier")] + #[serde(default="default_scrolling_multiplier")] + pub faux_multiplier: u8, +} + +fn default_scrolling_history() -> u32 { + 10_000 +} + +// Default for normal and faux scrolling +fn default_scrolling_multiplier() -> u8 { + 3 +} + +impl Default for Scrolling { + fn default() -> Self { + Self { + history: default_scrolling_history(), + multiplier: default_scrolling_multiplier(), + faux_multiplier: default_scrolling_multiplier(), + } + } +} + +fn deserialize_scrolling_history<'a, D>(deserializer: D) -> ::std::result::Result + where D: de::Deserializer<'a> +{ + match u32::deserialize(deserializer) { + Ok(lines) => Ok(lines), + Err(err) => { + eprintln!("problem with config: {}; Using default value", err); + Ok(default_scrolling_history()) + }, + } +} + +fn deserialize_scrolling_multiplier<'a, D>(deserializer: D) -> ::std::result::Result + where D: de::Deserializer<'a> +{ + match u8::deserialize(deserializer) { + Ok(lines) => Ok(lines), + Err(err) => { + eprintln!("problem with config: {}; Using default value", err); + Ok(default_scrolling_multiplier()) + }, + } +} + /// Newtype for implementing deserialize on glutin Mods /// /// Our deserialize impl wouldn't be covered by a derive(Deserialize); see the @@ -1286,10 +1300,6 @@ impl Config { .map(|path| path.into()) } - pub fn scroll_history(&self) -> usize { - self.scroll_history as _ - } - pub fn write_defaults() -> io::Result> { let path = ::xdg::BaseDirectories::with_prefix("alacritty") .map_err(|err| io::Error::new(io::ErrorKind::NotFound, ::std::error::Error::description(&err))) @@ -1419,6 +1429,12 @@ impl Config { self.dynamic_title } + /// Scrolling settings + #[inline] + pub fn scrolling(&self) -> Scrolling { + self.scrolling + } + pub fn load_from>(path: P) -> Result { let path = path.into(); let raw = Config::read_file(path.as_path())?; @@ -1451,6 +1467,11 @@ impl Config { eprintln!("{}", fmt::Yellow("Config `padding` is deprecated. \ Please use `window.padding` instead.")); } + + if self.mouse.faux_scrollback_lines.is_some() { + println!("{}", fmt::Yellow("Config `mouse.faux_scrollback_lines` is deprecated. \ + Please use `mouse.faux_scrolling_lines` instead.")); + } } } diff --git a/src/event.rs b/src/event.rs index 04176963..af5053f4 100644 --- a/src/event.rs +++ b/src/event.rs @@ -191,6 +191,7 @@ pub struct Processor { key_bindings: Vec, mouse_bindings: Vec, mouse_config: config::Mouse, + scrolling_config: config::Scrolling, print_events: bool, wait_for_event: bool, notifier: N, @@ -232,6 +233,7 @@ impl Processor { key_bindings: config.key_bindings().to_vec(), mouse_bindings: config.mouse_bindings().to_vec(), mouse_config: config.mouse().to_owned(), + scrolling_config: config.scrolling(), print_events: options.print_events, wait_for_event: true, notifier, @@ -395,6 +397,7 @@ impl Processor { processor = input::Processor { ctx: context, + scrolling_config: &self.scrolling_config, mouse_config: &self.mouse_config, key_bindings: &self.key_bindings[..], mouse_bindings: &self.mouse_bindings[..], diff --git a/src/input.rs b/src/input.rs index fabb3485..9b9aedc3 100644 --- a/src/input.rs +++ b/src/input.rs @@ -44,6 +44,7 @@ pub struct Processor<'a, A: 'a> { pub key_bindings: &'a [KeyBinding], pub mouse_bindings: &'a [MouseBinding], pub mouse_config: &'a config::Mouse, + pub scrolling_config: &'a config::Scrolling, pub ctx: A, } @@ -711,8 +712,9 @@ mod tests { triple_click: ClickHandler { threshold: Duration::from_millis(1000), }, - faux_scrollback_lines: 1, + faux_scrollback_lines: None, }, + scrolling_config: &config::Scrolling::default(), key_bindings: &config.key_bindings()[..], mouse_bindings: &config.mouse_bindings()[..], }; diff --git a/src/term/mod.rs b/src/term/mod.rs index 53bb3420..52d56ec8 100644 --- a/src/term/mod.rs +++ b/src/term/mod.rs @@ -847,7 +847,8 @@ impl Term { let num_cols = size.cols(); let num_lines = size.lines(); - let grid = Grid::new(num_lines, num_cols, config.scroll_history(), template); + let history_size = config.scrolling().history as usize; + let grid = Grid::new(num_lines, num_cols, history_size, template); let tabspaces = config.tabspaces(); let tabs = IndexRange::from(Column(0)..grid.num_cols())