aboutsummaryrefslogtreecommitdiff
path: root/src/config.rs
diff options
context:
space:
mode:
authorChristian Duerr <contact@christianduerr.com>2018-03-09 19:45:40 +0100
committerJoe Wilm <joe@jwilm.com>2018-06-02 09:44:58 -0700
commitd3f64072f3fe4d31f7a60eb0cb17a98096617b4b (patch)
tree3b9e13888df43cff8a976e4edcf1f9be89d82023 /src/config.rs
parenta2f127a5e65c8a6f4e1fc0bf79cc832d161a01b7 (diff)
downloadalacritty-d3f64072f3fe4d31f7a60eb0cb17a98096617b4b.tar.gz
alacritty-d3f64072f3fe4d31f7a60eb0cb17a98096617b4b.zip
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.
Diffstat (limited to 'src/config.rs')
-rw-r--r--src/config.rs127
1 files changed, 74 insertions, 53 deletions
diff --git a/src/config.rs b/src/config.rs
index 6502cf74..8e531a9c 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<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."));
+ }
}
}