aboutsummaryrefslogtreecommitdiff
path: root/alacritty_terminal/src/config/scrolling.rs
diff options
context:
space:
mode:
Diffstat (limited to 'alacritty_terminal/src/config/scrolling.rs')
-rw-r--r--alacritty_terminal/src/config/scrolling.rs78
1 files changed, 23 insertions, 55 deletions
diff --git a/alacritty_terminal/src/config/scrolling.rs b/alacritty_terminal/src/config/scrolling.rs
index 136e9389..159b0f44 100644
--- a/alacritty_terminal/src/config/scrolling.rs
+++ b/alacritty_terminal/src/config/scrolling.rs
@@ -1,24 +1,23 @@
-use log::error;
+use serde::de::Error as SerdeError;
use serde::{Deserialize, Deserializer};
-use crate::config::{failure_default, LOG_TARGET_CONFIG, MAX_SCROLLBACK_LINES};
+use alacritty_config_derive::ConfigDeserialize;
+
+/// Maximum scrollback amount configurable.
+const MAX_SCROLLBACK_LINES: u32 = 100_000;
/// Struct for scrolling related settings.
-#[serde(default)]
-#[derive(Deserialize, Copy, Clone, Default, Debug, PartialEq, Eq)]
+#[derive(ConfigDeserialize, Copy, Clone, Debug, PartialEq, Eq)]
pub struct Scrolling {
- #[serde(deserialize_with = "failure_default")]
- history: ScrollingHistory,
- #[serde(deserialize_with = "failure_default")]
- multiplier: ScrollingMultiplier,
+ pub multiplier: u8,
- // TODO: REMOVED
- #[serde(deserialize_with = "failure_default")]
- pub auto_scroll: Option<bool>,
+ history: ScrollingHistory,
+}
- // TODO: DEPRECATED
- #[serde(deserialize_with = "failure_default")]
- faux_multiplier: Option<ScrollingMultiplier>,
+impl Default for Scrolling {
+ fn default() -> Self {
+ Self { multiplier: 3, history: Default::default() }
+ }
}
impl Scrolling {
@@ -26,29 +25,12 @@ impl Scrolling {
self.history.0
}
- pub fn multiplier(self) -> u8 {
- self.multiplier.0
- }
-
- pub fn faux_multiplier(self) -> Option<u8> {
- self.faux_multiplier.map(|sm| sm.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 {
- Self(3)
- }
-}
-
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
struct ScrollingHistory(u32);
@@ -59,33 +41,19 @@ impl Default for ScrollingHistory {
}
impl<'de> Deserialize<'de> for ScrollingHistory {
- fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
+ fn deserialize<D>(deserializer: D) -> 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!(
- target: LOG_TARGET_CONFIG,
- "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!(
- target: LOG_TARGET_CONFIG,
- "Problem with config: {}; using default value", err
- );
- Ok(Default::default())
- },
+ let lines = u32::deserialize(deserializer)?;
+
+ if lines > MAX_SCROLLBACK_LINES {
+ Err(SerdeError::custom(format!(
+ "exceeded maximum scrolling history ({}/{})",
+ lines, MAX_SCROLLBACK_LINES
+ )))
+ } else {
+ Ok(Self(lines))
}
}
}