aboutsummaryrefslogtreecommitdiff
path: root/alacritty/src/config/ui_config.rs
diff options
context:
space:
mode:
Diffstat (limited to 'alacritty/src/config/ui_config.rs')
-rw-r--r--alacritty/src/config/ui_config.rs109
1 files changed, 61 insertions, 48 deletions
diff --git a/alacritty/src/config/ui_config.rs b/alacritty/src/config/ui_config.rs
index 29ff2c4c..0933ea42 100644
--- a/alacritty/src/config/ui_config.rs
+++ b/alacritty/src/config/ui_config.rs
@@ -3,16 +3,14 @@ use std::fmt::{self, Formatter};
use std::path::PathBuf;
use std::rc::Rc;
-use log::error;
+use log::{error, warn};
use serde::de::{Error as SerdeError, MapAccess, Visitor};
use serde::{self, Deserialize, Deserializer};
use unicode_width::UnicodeWidthChar;
use winit::event::{ModifiersState, VirtualKeyCode};
use alacritty_config_derive::{ConfigDeserialize, SerdeReplace};
-use alacritty_terminal::config::{
- Config as TerminalConfig, Percentage, Program, LOG_TARGET_CONFIG,
-};
+use alacritty_terminal::config::{Config as TerminalConfig, Program, LOG_TARGET_CONFIG};
use alacritty_terminal::term::search::RegexSearch;
use crate::config::bell::BellConfig;
@@ -22,7 +20,7 @@ use crate::config::bindings::{
use crate::config::color::Colors;
use crate::config::debug::Debug;
use crate::config::font::Font;
-use crate::config::mouse::Mouse;
+use crate::config::mouse::{Mouse, MouseBindings};
use crate::config::window::WindowConfig;
/// Regex used for the default URL hint.
@@ -38,6 +36,7 @@ pub struct UiConfig {
/// Window configuration.
pub window: WindowConfig,
+ /// Mouse configuration.
pub mouse: Mouse,
/// Debug options.
@@ -57,9 +56,6 @@ pub struct UiConfig {
/// RGB values for colors.
pub colors: Colors,
- /// Should draw bold text with brighter colors instead of bold font.
- pub draw_bold_text_with_bright_colors: bool,
-
/// Path where config was loaded from.
#[config(skip)]
pub config_paths: Vec<PathBuf>,
@@ -75,37 +71,42 @@ pub struct UiConfig {
#[config(flatten)]
pub terminal_config: TerminalConfig,
+ /// Keyboard configuration.
+ keyboard: Keyboard,
+
+ /// Should draw bold text with brighter colors instead of bold font.
+ #[config(deprecated = "use colors.draw_bold_text_with_bright_colors instead")]
+ draw_bold_text_with_bright_colors: bool,
+
/// Keybindings.
+ #[config(deprecated = "use keyboard.bindings instead")]
key_bindings: KeyBindings,
/// Bindings for the mouse.
+ #[config(deprecated = "use mouse.bindings instead")]
mouse_bindings: MouseBindings,
-
- /// Background opacity from 0.0 to 1.0.
- #[config(deprecated = "use window.opacity instead")]
- background_opacity: Option<Percentage>,
}
impl Default for UiConfig {
fn default() -> Self {
Self {
live_config_reload: true,
- alt_send_esc: Default::default(),
#[cfg(unix)]
ipc_socket: true,
- font: Default::default(),
- window: Default::default(),
- mouse: Default::default(),
- debug: Default::default(),
+ draw_bold_text_with_bright_colors: Default::default(),
+ terminal_config: Default::default(),
+ mouse_bindings: Default::default(),
config_paths: Default::default(),
key_bindings: Default::default(),
- mouse_bindings: Default::default(),
- terminal_config: Default::default(),
- background_opacity: Default::default(),
- bell: Default::default(),
+ alt_send_esc: Default::default(),
+ keyboard: Default::default(),
+ window: Default::default(),
colors: Default::default(),
- draw_bold_text_with_bright_colors: Default::default(),
+ mouse: Default::default(),
+ debug: Default::default(),
hints: Default::default(),
+ font: Default::default(),
+ bell: Default::default(),
}
}
}
@@ -113,6 +114,15 @@ impl Default for UiConfig {
impl UiConfig {
/// Generate key bindings for all keyboard hints.
pub fn generate_hint_bindings(&mut self) {
+ // Check which key bindings is most likely to be the user's configuration.
+ //
+ // Both will be non-empty due to the presence of the default keybindings.
+ let key_bindings = if self.keyboard.bindings.0.len() >= self.key_bindings.0.len() {
+ &mut self.keyboard.bindings.0
+ } else {
+ &mut self.key_bindings.0
+ };
+
for hint in &self.hints.enabled {
let binding = match hint.binding {
Some(binding) => binding,
@@ -127,54 +137,56 @@ impl UiConfig {
action: Action::Hint(hint.clone()),
};
- self.key_bindings.0.push(binding);
+ key_bindings.push(binding);
}
}
#[inline]
pub fn window_opacity(&self) -> f32 {
- self.background_opacity.unwrap_or(self.window.opacity).as_f32()
+ self.window.opacity.as_f32()
}
#[inline]
pub fn key_bindings(&self) -> &[KeyBinding] {
- self.key_bindings.0.as_slice()
+ if self.keyboard.bindings.0.len() >= self.key_bindings.0.len() {
+ self.keyboard.bindings.0.as_slice()
+ } else {
+ self.key_bindings.0.as_slice()
+ }
}
#[inline]
pub fn mouse_bindings(&self) -> &[MouseBinding] {
- self.mouse_bindings.0.as_slice()
+ if self.mouse.bindings.0.len() >= self.mouse_bindings.0.len() {
+ self.mouse.bindings.0.as_slice()
+ } else {
+ self.mouse_bindings.0.as_slice()
+ }
}
-}
-
-#[derive(SerdeReplace, Clone, Debug, PartialEq, Eq)]
-struct KeyBindings(Vec<KeyBinding>);
-impl Default for KeyBindings {
- fn default() -> Self {
- Self(bindings::default_key_bindings())
+ #[inline]
+ pub fn draw_bold_text_with_bright_colors(&self) -> bool {
+ self.colors.draw_bold_text_with_bright_colors || self.draw_bold_text_with_bright_colors
}
}
-impl<'de> Deserialize<'de> for KeyBindings {
- fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
- where
- D: Deserializer<'de>,
- {
- Ok(Self(deserialize_bindings(deserializer, Self::default().0)?))
- }
+/// Keyboard configuration.
+#[derive(ConfigDeserialize, Default, Clone, Debug, PartialEq)]
+struct Keyboard {
+ /// Keybindings.
+ bindings: KeyBindings,
}
#[derive(SerdeReplace, Clone, Debug, PartialEq, Eq)]
-struct MouseBindings(Vec<MouseBinding>);
+struct KeyBindings(Vec<KeyBinding>);
-impl Default for MouseBindings {
+impl Default for KeyBindings {
fn default() -> Self {
- Self(bindings::default_mouse_bindings())
+ Self(bindings::default_key_bindings())
}
}
-impl<'de> Deserialize<'de> for MouseBindings {
+impl<'de> Deserialize<'de> for KeyBindings {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
@@ -183,7 +195,7 @@ impl<'de> Deserialize<'de> for MouseBindings {
}
}
-fn deserialize_bindings<'a, D, T>(
+pub fn deserialize_bindings<'a, D, T>(
deserializer: D,
mut default: Vec<Binding<T>>,
) -> Result<Vec<Binding<T>>, D::Error>
@@ -192,7 +204,7 @@ where
T: Copy + Eq,
Binding<T>: Deserialize<'a>,
{
- let values = Vec::<serde_yaml::Value>::deserialize(deserializer)?;
+ let values = Vec::<toml::Value>::deserialize(deserializer)?;
// Skip all invalid values.
let mut bindings = Vec::with_capacity(values.len());
@@ -388,7 +400,7 @@ impl<'de> Deserialize<'de> for HintContent {
{
let mut content = Self::Value::default();
- while let Some((key, value)) = map.next_entry::<String, serde_yaml::Value>()? {
+ while let Some((key, value)) = map.next_entry::<String, toml::Value>()? {
match key.as_str() {
"regex" => match Option::<LazyRegex>::deserialize(value) {
Ok(regex) => content.regex = regex,
@@ -408,7 +420,8 @@ impl<'de> Deserialize<'de> for HintContent {
);
},
},
- _ => (),
+ "command" | "action" => (),
+ key => warn!(target: LOG_TARGET_CONFIG, "Unrecognized hint field: {key}"),
}
}