summaryrefslogtreecommitdiffstats
path: root/alacritty_terminal/src/config/mod.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/mod.rs
parent7738c52ed4eb177ead9f43d14207ecb129cfe617 (diff)
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/mod.rs')
-rw-r--r--alacritty_terminal/src/config/mod.rs2786
1 files changed, 235 insertions, 2551 deletions
diff --git a/alacritty_terminal/src/config/mod.rs b/alacritty_terminal/src/config/mod.rs
index 6eebbdfc..0af7e819 100644
--- a/alacritty_terminal/src/config/mod.rs
+++ b/alacritty_terminal/src/config/mod.rs
@@ -1,542 +1,73 @@
-//! Configuration definitions and file loading
-//!
-//! Alacritty reads from a config file at startup to determine various runtime
-//! parameters including font family and style, font size, etc. In the future,
-//! the config file will also hold user and platform specific keybindings.
+// Copyright 2016 Joe Wilm, The Alacritty Project Contributors
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
use std::borrow::Cow;
use std::collections::HashMap;
-use std::fs::File;
-use std::io::{self, Read, Write};
-use std::path::{Path, PathBuf};
-use std::str::FromStr;
-use std::sync::mpsc;
-use std::time::Duration;
-use std::{env, fmt};
-
-use font::Size;
-use glutin::ModifiersState;
-use notify::{watcher, DebouncedEvent, RecursiveMode, Watcher};
-use serde::de::Error as SerdeError;
-use serde::de::{MapAccess, Unexpected, Visitor};
-use serde::{self, de, Deserialize};
-use serde_yaml;
+use std::path::PathBuf;
-use crate::ansi::CursorStyle;
-use crate::index::{Column, Line};
-use crate::input::{Action, Binding, KeyBinding, MouseBinding};
-use crate::term::color::Rgb;
+use serde::{Deserialize, Deserializer};
-pub use self::options::Options;
-mod options;
mod bindings;
+mod colors;
+mod debug;
+mod font;
+mod monitor;
+mod mouse;
+mod scrolling;
+#[cfg(test)]
+mod test;
+mod visual_bell;
+mod window;
-pub const SOURCE_FILE_PATH: &str = file!();
-const MAX_SCROLLBACK_LINES: u32 = 100_000;
-static DEFAULT_ALACRITTY_CONFIG: &'static str =
+use crate::ansi::CursorStyle;
+use crate::input::{Binding, KeyBinding, MouseBinding};
+
+pub use crate::config::bindings::Key;
+pub use crate::config::colors::Colors;
+pub use crate::config::debug::Debug;
+pub use crate::config::font::{Font, FontDescription};
+pub use crate::config::monitor::Monitor;
+pub use crate::config::mouse::{ClickHandler, Mouse};
+pub use crate::config::scrolling::Scrolling;
+pub use crate::config::visual_bell::{VisualBellAnimation, VisualBellConfig};
+pub use crate::config::window::{Decorations, Dimensions, StartupMode, WindowConfig};
+
+pub static DEFAULT_ALACRITTY_CONFIG: &'static str =
include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/../alacritty.yml"));
-
-#[serde(default)]
-#[derive(Clone, Debug, Deserialize, PartialEq, Eq)]
-pub struct Selection {
- #[serde(deserialize_with = "deserialize_escape_chars")]
- pub semantic_escape_chars: String,
- #[serde(deserialize_with = "failure_default")]
- pub save_to_clipboard: bool,
-}
-
-impl Default for Selection {
- fn default() -> Selection {
- Selection {
- semantic_escape_chars: default_escape_chars(),
- save_to_clipboard: Default::default(),
- }
- }
-}
-
-fn deserialize_escape_chars<'a, D>(deserializer: D) -> ::std::result::Result<String, D::Error>
-where
- D: de::Deserializer<'a>,
-{
- match String::deserialize(deserializer) {
- Ok(escape_chars) => Ok(escape_chars),
- Err(err) => {
- error!("Problem with config: {}; using default value", err);
- Ok(default_escape_chars())
- },
- }
-}
-
-fn default_escape_chars() -> String {
- String::from(",│`|:\"' ()[]{}<>")
-}
-
-#[serde(default)]
-#[derive(Clone, Debug, Deserialize, PartialEq, Eq)]
-pub struct ClickHandler {
- #[serde(deserialize_with = "deserialize_duration_ms")]
- pub threshold: Duration,
-}
-
-impl Default for ClickHandler {
- fn default() -> Self {
- ClickHandler { threshold: default_threshold_ms() }
- }
-}
-
-fn default_threshold_ms() -> Duration {
- Duration::from_millis(300)
-}
-
-fn deserialize_duration_ms<'a, D>(deserializer: D) -> ::std::result::Result<Duration, D::Error>
-where
- D: de::Deserializer<'a>,
-{
- match u64::deserialize(deserializer) {
- Ok(threshold_ms) => Ok(Duration::from_millis(threshold_ms)),
- Err(err) => {
- error!("Problem with config: {}; using default value", err);
- Ok(default_threshold_ms())
- },
- }
-}
-
-#[serde(default)]
-#[derive(Default, Clone, Debug, Deserialize, PartialEq, Eq)]
-pub struct Mouse {
- #[serde(deserialize_with = "failure_default")]
- pub double_click: ClickHandler,
- #[serde(deserialize_with = "failure_default")]
- pub triple_click: ClickHandler,
- #[serde(deserialize_with = "failure_default")]
- pub hide_when_typing: bool,
- #[serde(deserialize_with = "failure_default")]
- pub url: Url,
-
- // TODO: DEPRECATED
- pub faux_scrollback_lines: Option<usize>,
-}
-
-#[serde(default)]
-#[derive(Clone, Debug, Deserialize, PartialEq, Eq)]
-pub struct Url {
- // Program for opening links
- #[serde(deserialize_with = "deserialize_launcher")]
- pub launcher: Option<CommandWrapper>,
-
- // Modifier used to open links
- #[serde(deserialize_with = "deserialize_modifiers")]
- pub modifiers: ModifiersState,
-}
-
-fn deserialize_launcher<'a, D>(
- deserializer: D,
-) -> ::std::result::Result<Option<CommandWrapper>, D::Error>
-where
- D: de::Deserializer<'a>,
-{
- let default = Url::default().launcher;
-
- // Deserialize to generic value
- let val = match serde_yaml::Value::deserialize(deserializer) {
- Ok(val) => val,
- Err(err) => {
- error!("Problem with config: {}; using {}", err, default.clone().unwrap().program());
- return Ok(default);
- },
- };
-
- // Accept `None` to disable the launcher
- if val.as_str().filter(|v| v.to_lowercase() == "none").is_some() {
- return Ok(None);
- }
-
- match <Option<CommandWrapper>>::deserialize(val) {
- Ok(launcher) => Ok(launcher),
- Err(err) => {
- error!("Problem with config: {}; using {}", err, default.clone().unwrap().program());
- Ok(default)
- },
- }
-}
-
-impl Default for Url {
- fn default() -> Url {
- Url {
- #[cfg(not(any(target_os = "macos", windows)))]
- launcher: Some(CommandWrapper::Just(String::from("xdg-open"))),
- #[cfg(target_os = "macos")]
- launcher: Some(CommandWrapper::Just(String::from("open"))),
- #[cfg(windows)]
- launcher: Some(CommandWrapper::Just(String::from("explorer"))),
- modifiers: Default::default(),
- }
- }
-}
-
-fn deserialize_modifiers<'a, D>(deserializer: D) -> ::std::result::Result<ModifiersState, D::Error>
-where
- D: de::Deserializer<'a>,
-{
- ModsWrapper::deserialize(deserializer).map(ModsWrapper::into_inner)
-}
-
-/// `VisualBellAnimations` are modeled after a subset of CSS transitions and Robert
-/// Penner's Easing Functions.
-#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Eq)]
-pub enum VisualBellAnimation {
- Ease, // CSS
- EaseOut, // CSS
- EaseOutSine, // Penner
- EaseOutQuad, // Penner
- EaseOutCubic, // Penner
- EaseOutQuart, // Penner
- EaseOutQuint, // Penner
- EaseOutExpo, // Penner
- EaseOutCirc, // Penner
- Linear,
-}
-
-impl Default for VisualBellAnimation {
- fn default() -> Self {
- VisualBellAnimation::EaseOutExpo
- }
-}
-
-#[serde(default)]
-#[derive(Debug, Deserialize, PartialEq, Eq)]
-pub struct VisualBellConfig {
- /// Visual bell animation function
- #[serde(deserialize_with = "failure_default")]
- animation: VisualBellAnimation,
-
- /// Visual bell duration in milliseconds
- #[serde(deserialize_with = "failure_default")]
- duration: u16,
-
- /// Visual bell flash color
- #[serde(deserialize_with = "rgb_from_hex")]
- color: Rgb,
-}
-
-impl Default for VisualBellConfig {
- fn default() -> VisualBellConfig {
- VisualBellConfig {
- animation: Default::default(),
- duration: Default::default(),
- color: default_visual_bell_color(),
- }
- }
-}
-
-fn default_visual_bell_color() -> Rgb {
- Rgb { r: 255, g: 255, b: 255 }
-}
-
-impl VisualBellConfig {
- /// Visual bell animation
- #[inline]
- pub fn animation(&self) -> VisualBellAnimation {
- self.animation
- }
-
- /// Visual bell duration in milliseconds
- #[inline]
- pub fn duration(&self) -> Duration {
- Duration::from_millis(u64::from(self.duration))
- }
-
- /// Visual bell flash color
- #[inline]
- pub fn color(&self) -> Rgb {
- self.color
- }
-}
-
-#[derive(Debug, Deserialize, PartialEq, Eq)]
-pub struct Shell<'a> {
- program: Cow<'a, str>,
-
- #[serde(default, deserialize_with = "failure_default")]
- args: Vec<String>,
-}
-
-impl<'a> Shell<'a> {
- pub fn new<S>(program: S) -> Shell<'a>
- where
- S: Into<Cow<'a, str>>,
- {
- Shell { program: program.into(), args: Vec::new() }
- }
-
- pub fn new_with_args<S>(program: S, args: Vec<String>) -> Shell<'a>
- where
- S: Into<Cow<'a, str>>,
- {
- Shell { program: program.into(), args }
- }
-
- pub fn program(&self) -> &str {
- &*self.program
- }
-
- pub fn args(&self) -> &[String] {
- self.args.as_slice()
- }
-}
-
-/// Wrapper around f32 that represents an alpha value between 0.0 and 1.0
-#[derive(Clone, Copy, Debug, PartialEq)]
-pub struct Alpha(f32);
-
-impl Alpha {
- pub fn new(value: f32) -> Self {
- Alpha(Self::clamp_to_valid_range(value))
- }
-
- pub fn set(&mut self, value: f32) {
- self.0 = Self::clamp_to_valid_range(value);
- }
-
- #[inline]
- pub fn get(self) -> f32 {
- self.0
- }
-
- fn clamp_to_valid_range(value: f32) -> f32 {
- if value < 0.0 {
- 0.0
- } else if value > 1.0 {
- 1.0
- } else {
- value
- }
- }
-}
-
-impl Default for Alpha {
- fn default() -> Self {
- Alpha(1.0)
- }
-}
-
-#[derive(Debug, Deserialize, Copy, Clone, PartialEq, Eq)]
-pub enum StartupMode {
- Windowed,
- Maximized,
- Fullscreen,
- #[cfg(target_os = "macos")]
- SimpleFullscreen,
-}
-
-impl Default for StartupMode {
- fn default() -> StartupMode {
- StartupMode::Windowed
- }
-}
-
-#[derive(Debug, Copy, Clone, PartialEq, Eq)]
-pub enum Decorations {
- Full,
- Transparent,
- Buttonless,
- None,
-}
-
-impl Default for Decorations {
- fn default() -> Decorations {
- Decorations::Full
- }
-}
-
-impl<'de> Deserialize<'de> for Decorations {
- fn deserialize<D>(deserializer: D) -> ::std::result::Result<Decorations, D::Error>
- where
- D: de::Deserializer<'de>,
- {
- struct DecorationsVisitor;
-
- impl<'de> Visitor<'de> for DecorationsVisitor {
- type Value = Decorations;
-
- fn expecting(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- f.write_str("Some subset of full|transparent|buttonless|none")
- }
-
- #[cfg(target_os = "macos")]
- fn visit_str<E>(self, value: &str) -> ::std::result::Result<Decorations, E>
- where
- E: de::Error,
- {
- match value.to_lowercase().as_str() {
- "transparent" => Ok(Decorations::Transparent),
- "buttonless" => Ok(Decorations::Buttonless),
- "none" => Ok(Decorations::None),
- "full" => Ok(Decorations::Full),
- "true" => {
- error!(
- "Deprecated decorations boolean value, use one of \
- transparent|buttonless|none|full instead; falling back to \"full\""
- );
- Ok(Decorations::Full)
- },
- "false" => {
- error!(
- "Deprecated decorations boolean value, use one of \
- transparent|buttonless|none|full instead; falling back to \"none\""
- );
- Ok(Decorations::None)
- },
- _ => {
- error!("Invalid decorations value: {}; using default value", value);
- Ok(Decorations::Full)
- },
- }
- }
-
- #[cfg(not(target_os = "macos"))]
- fn visit_str<E>(self, value: &str) -> ::std::result::Result<Decorations, E>
- where
- E: de::Error,
- {
- match value.to_lowercase().as_str() {
- "none" => Ok(Decorations::None),
- "full" => Ok(Decorations::Full),
- "true" => {
- error!(
- "Deprecated decorations boolean value, use one of none|full instead; \
- falling back to \"full\""
- );
- Ok(Decorations::Full)
- },
- "false" => {
- error!(
- "Deprecated decorations boolean value, use one of none|full instead; \
- falling back to \"none\""
- );
- Ok(Decorations::None)
- },
- "transparent" | "buttonless" => {
- error!("macOS-only decorations value: {}; using default value", value);
- Ok(Decorations::Full)
- },
- _ => {
- error!("Invalid decorations value: {}; using default value", value);
- Ok(Decorations::Full)
- },
- }
- }
- }
-
- deserializer.deserialize_str(DecorationsVisitor)
- }
-}
-
-#[serde(default)]
-#[derive(Debug, Copy, Clone, Deserialize, PartialEq, Eq)]
-pub struct WindowConfig {
- /// Initial dimensions
- #[serde(default, deserialize_with = "failure_default")]
- dimensions: Dimensions,
-
- /// Initial position
- #[serde(default, deserialize_with = "failure_default")]
- position: Option<Delta<i32>>,
-
- /// Pixel padding
- #[serde(deserialize_with = "deserialize_padding")]
- padding: Delta<u8>,
-
- /// Draw the window with title bar / borders
- #[serde(deserialize_with = "failure_default")]
- decorations: Decorations,
-
- /// Spread out additional padding evenly
- #[serde(deserialize_with = "failure_default")]
- dynamic_padding: bool,
-
- /// Startup mode
- #[serde(deserialize_with = "failure_default")]
- startup_mode: StartupMode,
-
- /// TODO: DEPRECATED
- #[serde(deserialize_with = "failure_default")]
- start_maximized: Option<bool>,
-}
-
-impl Default for WindowConfig {
- fn default() -> Self {
- WindowConfig {
- dimensions: Default::default(),
- position: Default::default(),
- padding: default_padding(),
- decorations: Default::default(),
- dynamic_padding: Default::default(),
- start_maximized: Default::default(),
- startup_mode: Default::default(),
- }
- }
-}
-
-fn default_padding() -> Delta<u8> {
- Delta { x: 2, y: 2 }
-}
-
-fn deserialize_padding<'a, D>(deserializer: D) -> ::std::result::Result<Delta<u8>, D::Error>
-where
- D: de::Deserializer<'a>,
-{
- match Delta::deserialize(deserializer) {
- Ok(delta) => Ok(delta),
- Err(err) => {
- error!("Problem with config: {}; using default value", err);
- Ok(default_padding())
- },
- }
-}
-
-impl WindowConfig {
- pub fn decorations(&self) -> Decorations {
- self.decorations
- }
-
- pub fn dynamic_padding(&self) -> bool {
- self.dynamic_padding
- }
-
- pub fn startup_mode(&self) -> StartupMode {
- self.startup_mode
- }
-
- pub fn position(&self) -> Option<Delta<i32>> {
- self.position
- }
-}
+const MAX_SCROLLBACK_LINES: u32 = 100_000;
/// Top-level config type
#[derive(Debug, PartialEq, Deserialize)]
pub struct Config {
/// Pixel padding
#[serde(default, deserialize_with = "failure_default")]
- padding: Option<Delta<u8>>,
+ pub padding: Option<Delta<u8>>,
/// TERM env variable
#[serde(default, deserialize_with = "failure_default")]
- env: HashMap<String, String>,
+ pub env: HashMap<String, String>,
/// Font configuration
#[serde(default, deserialize_with = "failure_default")]
- font: Font,
-
- /// Should show render timer
- #[serde(default, deserialize_with = "failure_default")]
- render_timer: bool,
+ pub font: Font,
/// Should draw bold text with brighter colors instead of bold font
- #[serde(default = "default_true_bool", deserialize_with = "deserialize_true_bool")]
- draw_bold_text_with_bright_colors: bool,
+ #[serde(default, deserialize_with = "failure_default")]
+ draw_bold_text_with_bright_colors: DefaultTrueBool,
#[serde(default, deserialize_with = "failure_default")]
- colors: Colors,
+ pub colors: Colors,
/// Background opacity from 0.0 to 1.0
#[serde(default, deserialize_with = "failure_default")]
@@ -544,82 +75,79 @@ pub struct Config {
/// Window configuration
#[serde(default, deserialize_with = "failure_default")]
- window: WindowConfig,
+ pub window: WindowConfig,
/// Keybindings
#[serde(default = "default_key_bindings", deserialize_with = "deserialize_key_bindings")]
- key_bindings: Vec<KeyBinding>,
+ pub key_bindings: Vec<KeyBinding>,
/// Bindings for the mouse
#[serde(default = "default_mouse_bindings", deserialize_with = "deserialize_mouse_bindings")]
- mouse_bindings: Vec<MouseBinding>,
+ pub mouse_bindings: Vec<MouseBinding>,
#[serde(default, deserialize_with = "failure_default")]
- selection: Selection,
+ pub selection: Selection,
#[serde(default, deserialize_with = "failure_default")]
- mouse: Mouse,
+ pub mouse: Mouse,
/// Path to a shell program to run on startup
#[serde(default, deserialize_with = "failure_default")]
- shell: Option<Shell<'static>>,
+ pub shell: Option<Shell<'static>>,
/// Path where config was loaded from
#[serde(default, deserialize_with = "failure_default")]
- config_path: Option<PathBuf>,
+ pub config_path: Option<PathBuf>,
/// Visual bell configuration
#[serde(default, deserialize_with = "failure_default")]
- visual_bell: VisualBellConfig,
+ pub visual_bell: VisualBellConfig,
/// Use dynamic title
- #[serde(default = "default_true_bool", deserialize_with = "deserialize_true_bool")]
- dynamic_title: bool,
+ #[serde(default, deserialize_with = "failure_default")]
+ dynamic_title: DefaultTrueBool,
/// Live config reload
- #[serde(default = "default_true_bool", deserialize_with = "deserialize_true_bool")]
- live_config_reload: bool,
+ #[serde(default, deserialize_with = "failure_default")]
+ live_config_reload: DefaultTrueBool,
/// Number of spaces in one tab
- #[serde(default = "default_tabspaces", deserialize_with = "deserialize_tabspaces")]
- tabspaces: usize,
+ #[serde(default, deserialize_with = "failure_default")]
+ tabspaces: Tabspaces,
/// How much scrolling history to keep
#[serde(default, deserialize_with = "failure_default")]
- scrolling: Scrolling,
+ pub scrolling: Scrolling,
/// Cursor configuration
#[serde(default, deserialize_with = "failure_default")]
- cursor: Cursor,
-
- /// Keep the log file after quitting
- #[serde(default, deserialize_with = "failure_default")]
- persistent_logging: bool,
+ pub cursor: Cursor,
/// Enable experimental conpty backend instead of using winpty.
/// Will only take effect on Windows 10 Oct 2018 and later.
#[cfg(windows)]
#[serde(default, deserialize_with = "failure_default")]
- enable_experimental_conpty_backend: bool,
+ pub enable_experimental_conpty_backend: bool,
/// Send escape sequences using the alt key.
- #[serde(default = "default_true_bool", deserialize_with = "deserialize_true_bool")]
- alt_send_esc: bool,
-
- // TODO: DEPRECATED
- custom_cursor_colors: Option<bool>,
+ #[serde(default, deserialize_with = "failure_default")]
+ alt_send_esc: DefaultTrueBool,
- // TODO: DEPRECATED
- hide_cursor_when_typing: Option<bool>,
+ /// Shell startup directory
+ #[serde(default, deserialize_with = "failure_default")]
+ working_directory: WorkingDirectory,
- // TODO: DEPRECATED
- cursor_style: Option<CursorStyle>,
+ /// Debug options
+ #[serde(default, deserialize_with = "failure_default")]
+ pub debug: Debug,
// TODO: DEPRECATED
- unfocused_hollow_cursor: Option<bool>,
+ #[serde(default, deserialize_with = "failure_default")]
+ pub render_timer: Option<bool>,
// TODO: DEPRECATED
- dimensions: Option<Dimensions>,
+ #[serde(default, deserialize_with = "failure_default")]
+ pub persistent_logging: Option<bool>,
}
impl Default for Config {
@@ -628,818 +156,159 @@ impl Default for Config {
}
}
-fn default_key_bindings() -> Vec<KeyBinding> {
- bindings::default_key_bindings()
-}
-
-fn default_mouse_bindings() -> Vec<MouseBinding> {
- bindings::default_mouse_bindings()
-}
-
-fn deserialize_key_bindings<'a, D>(
- deserializer: D,
-) -> ::std::result::Result<Vec<KeyBinding>, D::Error>
-where
- D: de::Deserializer<'a>,
-{
- deserialize_bindings(deserializer, bindings::default_key_bindings())
-}
-
-fn deserialize_mouse_bindings<'a, D>(
- deserializer: D,
-) -> ::std::result::Result<Vec<MouseBinding>, D::Error>
-where
- D: de::Deserializer<'a>,
-{
- deserialize_bindings(deserializer, bindings::default_mouse_bindings())
-}
-
-fn deserialize_bindings<'a, D, T>(
- deserializer: D,
- mut default: Vec<Binding<T>>,
-) -> ::std::result::Result<Vec<Binding<T>>, D::Error>
-where
- D: de::Deserializer<'a>,
- T: Copy + Eq + std::hash::Hash + std::fmt::Debug,
- Binding<T>: de::Deserialize<'a>,
-{
- let mut bindings: Vec<Binding<T>> = failure_default_vec(deserializer)?;
-
- for binding in bindings.iter() {
- default.retain(|b| !b.triggers_match(binding));
- }
-
- bindings.extend(default);
-
- Ok(bindings)
-}
-
-fn failure_default_vec<'a, D, T>(deserializer: D) -> ::std::result::Result<Vec<T>, D::Error>
-where
- D: de::Deserializer<'a>,
- T: Deserialize<'a>,
-{
- // Deserialize as generic vector
- let vec = match Vec::<serde_yaml::Value>::deserialize(deserializer) {
- Ok(vec) => vec,
- Err(err) => {
- error!("Problem with config: {}; using empty vector", err);
- return Ok(Vec::new());
- },
- };
-
- // Move to lossy vector
- let mut bindings: Vec<T> = Vec::new();
- for value in vec {
- match T::deserialize(value) {
- Ok(binding) => bindings.push(binding),
- Err(err) => {
- error!("Problem with config: {}; skipping value", err);
- },
- }
- }
-
- Ok(bindings)
-}
-
-fn default_tabspaces() -> usize {
- 8
-}
-
-fn deserialize_tabspaces<'a, D>(deserializer: D) -> ::std::result::Result<usize, D::Error>
-where
- D: de::Deserializer<'a>,
-{
- match usize::deserialize(deserializer) {
- Ok(value) => Ok(value),
- Err(err) => {
- error!("Problem with config: {}; using 8", err);
- Ok(default_tabspaces())
- },
+impl Config {
+ pub fn tabspaces(&self) -> usize {
+ self.tabspaces.0
}
-}
-fn deserialize_true_bool<'a, D>(deserializer: D) -> ::std::result::Result<bool, D::Error>
-where
- D: de::Deserializer<'a>,
-{
- match bool::deserialize(deserializer) {
- Ok(value) => Ok(value),
- Err(err) => {
- error!("Problem with config: {}; using true", err);
- Ok(true)
- },
+ #[inline]
+ pub fn draw_bold_text_with_bright_colors(&self) -> bool {
+ self.draw_bold_text_with_bright_colors.0
}
-}
-
-fn default_true_bool() -> bool {
- true
-}
-fn failure_default<'a, D, T>(deserializer: D) -> ::std::result::Result<T, D::Error>
-where
- D: de::Deserializer<'a>,
- T: Deserialize<'a> + Default,
-{
- match T::deserialize(deserializer) {
- Ok(value) => Ok(value),
- Err(err) => {
- error!("Problem with config: {}; using default value", err);
- Ok(T::default())
- },
+ /// Should show render timer
+ #[inline]
+ pub fn render_timer(&self) -> bool {
+ self.render_timer.unwrap_or(self.debug.render_timer)
}
-}
-/// Struct for scrolling related settings
-#[serde(default)]
-#[derive(Copy, Clone, Debug, PartialEq, Eq, Deserialize)]
-pub struct Scrolling {
- #[serde(deserialize_with = "deserialize_scrolling_history")]
- pub history: u32,
- #[serde(deserialize_with = "deserialize_scrolling_multiplier")]
- pub multiplier: u8,
- #[serde(deserialize_with = "deserialize_scrolling_multiplier")]
- pub faux_multiplier: u8,
- #[serde(deserialize_with = "failure_default")]
- pub auto_scroll: bool,
-}
-
-impl Default for Scrolling {
- fn default() -> Self {
- Self {
- history: default_scrolling_history(),
- multiplier: default_scrolling_multiplier(),
- faux_multiplier: default_scrolling_multiplier(),
- auto_scroll: Default::default(),
- }
+ /// Live config reload
+ #[inline]
+ pub fn live_config_reload(&self) -> bool {
+ self.live_config_reload.0
}
-}
-
-fn default_scrolling_history() -> u32 {
- 10_000
-}
-
-// Default for normal and faux scrolling
-fn default_scrolling_multiplier() -> u8 {
- 3
-}
-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) => {
- 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(MAX_SCROLLBACK_LINES)
- } else {
- Ok(lines)
- }
- },
- Err(err) => {
- error!("Problem with config: {}; using default value", err);
- Ok(default_scrolling_history())
- },
+ #[inline]
+ pub fn set_live_config_reload(&mut self, live_config_reload: bool) {
+ self.live_config_reload.0 = live_config_reload;
}
-}
-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) => {
- error!("Problem with config: {}; using default value", err);
- Ok(default_scrolling_multiplier())
- },
+ #[inline]
+ pub fn dynamic_title(&self) -> bool {
+ self.dynamic_title.0
}
-}
-
-/// Newtype for implementing deserialize on glutin Mods
-///
-/// Our deserialize impl wouldn't be covered by a derive(Deserialize); see the
-/// impl below.
-#[derive(Debug, Copy, Clone, Hash, Default, Eq, PartialEq)]
-struct ModsWrapper(ModifiersState);
-impl ModsWrapper {
- fn into_inner(self) -> ModifiersState {
- self.0
+ #[inline]
+ pub fn set_dynamic_title(&mut self, dynamic_title: bool) {
+ self.dynamic_title.0 = dynamic_title;
}
-}
-
-impl<'a> de::Deserialize<'a> for ModsWrapper {
- fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
- where
- D: de::Deserializer<'a>,
- {
- struct ModsVisitor;
-
- impl<'a> Visitor<'a> for ModsVisitor {
- type Value = ModsWrapper;
-
- fn expecting(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- f.write_str("Some subset of Command|Shift|Super|Alt|Option|Control")
- }
-
- fn visit_str<E>(self, value: &str) -> ::std::result::Result<ModsWrapper, E>
- where
- E: de::Error,
- {
- let mut res = ModifiersState::default();
- for modifier in value.split('|') {
- match modifier.trim() {
- "Command" | "Super" => res.logo = true,
- "Shift" => res.shift = true,
- "Alt" | "Option" => res.alt = true,
- "Control" => res.ctrl = true,
- "None" => (),
- _ => error!("Unknown modifier {:?}", modifier),
- }
- }
-
- Ok(ModsWrapper(res))
- }
- }
- deserializer.deserialize_str(ModsVisitor)
+ /// Send escape sequences using the alt key
+ #[inline]
+ pub fn alt_send_esc(&self) -> bool {
+ self.alt_send_esc.0
}
-}
-struct ActionWrapper(crate::input::Action);
-
-impl ActionWrapper {
- fn into_inner(self) -> crate::input::Action {
- self.0
+ /// Keep the log file after quitting Alacritty
+ #[inline]
+ pub fn persistent_logging(&self) -> bool {
+ self.persistent_logging.unwrap_or(self.debug.persistent_logging)
}
-}
-impl<'a> de::Deserialize<'a> for ActionWrapper {
- fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
- where
- D: de::Deserializer<'a>,
- {
- struct ActionVisitor;
-
- impl<'a> Visitor<'a> for ActionVisitor {
- type Value = ActionWrapper;
-
- fn expecting(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- f.write_str(
- "Paste, Copy, PasteSelection, IncreaseFontSize, DecreaseFontSize, \
- ResetFontSize, ScrollPageUp, ScrollPageDown, ScrollLineUp, ScrollLineDown, \
- ScrollToTop, ScrollToBottom, ClearHistory, Hide, ClearLogNotice, \
- SpawnNewInstance, ToggleFullscreen, ToggleSimpleFullscreen, None or Quit",
- )
- }
-
- fn visit_str<E>(self, value: &str) -> ::std::result::Result<ActionWrapper, E>
- where
- E: de::Error,
- {
- Ok(ActionWrapper(match value {
- "Paste" => Action::Paste,
- "Copy" => Action::C