summaryrefslogtreecommitdiff
path: root/alacritty_terminal/src/config/scrolling.rs
diff options
context:
space:
mode:
authorChristian Duerr <chrisduerr@users.noreply.github.com>2019-05-10 11:36:16 +0000
committerGitHub <noreply@github.com>2019-05-10 11:36:16 +0000
commit5d173f6df3b20308eb318cef4b58147b2197d5f9 (patch)
tree05638837bef25d65a818253814331a4f429f57ac /alacritty_terminal/src/config/scrolling.rs
parent7738c52ed4eb177ead9f43d14207ecb129cfe617 (diff)
downloadalacritty-5d173f6df3b20308eb318cef4b58147b2197d5f9.tar.gz
alacritty-5d173f6df3b20308eb318cef4b58147b2197d5f9.zip
Refactor config parsing files
This is a large refactor of the config parsing structure, attempting to reduce the size of the file a bit by splitting it up into different modules with more specific purposes. This also fixes #2279.
Diffstat (limited to 'alacritty_terminal/src/config/scrolling.rs')
-rw-r--r--alacritty_terminal/src/config/scrolling.rs81
1 files changed, 81 insertions, 0 deletions
diff --git a/alacritty_terminal/src/config/scrolling.rs b/alacritty_terminal/src/config/scrolling.rs
new file mode 100644
index 00000000..d62b102f
--- /dev/null
+++ b/alacritty_terminal/src/config/scrolling.rs
@@ -0,0 +1,81 @@
+use serde::{Deserialize, Deserializer};
+
+use crate::config::{failure_default, MAX_SCROLLBACK_LINES};
+
+/// Struct for scrolling related settings
+#[serde(default)]
+#[derive(Deserialize, Copy, Clone, Default, Debug, PartialEq, Eq)]
+pub struct Scrolling {
+ #[serde(deserialize_with = "failure_default")]
+ history: ScrollingHistory,
+ #[serde(deserialize_with = "failure_default")]
+ multiplier: ScrollingMultiplier,
+ #[serde(deserialize_with = "failure_default")]
+ faux_multiplier: ScrollingMultiplier,
+ #[serde(deserialize_with = "failure_default")]
+ pub auto_scroll: bool,
+}
+
+impl Scrolling {
+ pub fn history(self) -> u32 {
+ self.history.0
+ }
+
+ pub fn multiplier(self) -> u8 {
+ self.multiplier.0
+ }
+
+ pub fn faux_multiplier(self) -> u8 {
+ self.faux_multiplier.0
+ }
+
+ // Update the history size, used in ref tests
+ pub fn set_history(&mut self, history: u32) {
+ self.history = ScrollingHistory(history);
+ }
+}
+
+#[derive(Copy, Clone, Debug, PartialEq, Eq, Deserialize)]
+struct ScrollingMultiplier(u8);
+
+impl Default for ScrollingMultiplier {
+ fn default() -> Self {
+ ScrollingMultiplier(3)
+ }
+}
+
+#[derive(Copy, Clone, Debug, PartialEq, Eq)]
+struct ScrollingHistory(u32);
+
+impl Default for ScrollingHistory {
+ fn default() -> Self {
+ ScrollingHistory(10_000)
+ }
+}
+
+impl<'de> Deserialize<'de> for ScrollingHistory {
+ fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
+ where
+ D: Deserializer<'de>,
+ {
+ let value = serde_yaml::Value::deserialize(deserializer)?;
+ match u32::deserialize(value) {
+ Ok(lines) => {
+ if lines > MAX_SCROLLBACK_LINES {
+ error!(
+ "Problem with config: scrollback size is {}, but expected a maximum of \
+ {}; using {1} instead",
+ lines, MAX_SCROLLBACK_LINES,
+ );
+ Ok(ScrollingHistory(MAX_SCROLLBACK_LINES))
+ } else {
+ Ok(ScrollingHistory(lines))
+ }
+ },
+ Err(err) => {
+ error!("Problem with config: {}; using default value", err);
+ Ok(Default::default())
+ },
+ }
+ }
+}