1
0
Fork 0
mirror of https://github.com/alacritty/alacritty.git synced 2024-11-18 13:55:23 -05:00

Merge branch #1095

Because there was some overlap with branch #1095, these two PRs have
been added together and the config has been restructured to make use of
a `scrolling` section.

The default faux scrolling amount has also been changed to `3` because
this simplifies the code and falls in line with what most other terminal
emulators do.

There should be no additional test failures due to this.
This commit is contained in:
Christian Duerr 2018-03-09 19:45:40 +01:00 committed by Joe Wilm
parent 290e2cfb17
commit c1e831dab0
6 changed files with 118 additions and 91 deletions

View file

@ -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: ",│`|:\"' ()[]{}<>"

View file

@ -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: ",│`|:\"' ()[]{}<>"

View file

@ -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<u8, D::Error>
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<u8, D::Error>
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<usize>,
}
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<u32, D::Error>
@ -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<u32, D::Error>
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<u8, D::Error>
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<Cow<'static, Path>> {
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<P: Into<PathBuf>>(path: P) -> Result<Config> {
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."));
}
}
}

View file

@ -191,6 +191,7 @@ pub struct Processor<N> {
key_bindings: Vec<KeyBinding>,
mouse_bindings: Vec<MouseBinding>,
mouse_config: config::Mouse,
scrolling_config: config::Scrolling,
print_events: bool,
wait_for_event: bool,
notifier: N,
@ -232,6 +233,7 @@ impl<N: Notify> Processor<N> {
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<N: Notify> Processor<N> {
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[..],

View file

@ -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()[..],
};

View file

@ -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())