1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
|
use std::cmp::max;
use std::collections::HashMap;
use std::path::PathBuf;
use serde::Deserialize;
use alacritty_config_derive::ConfigDeserialize;
mod bell;
mod colors;
mod scrolling;
use crate::ansi::{CursorShape, CursorStyle};
pub use crate::config::bell::{BellAnimation, BellConfig};
pub use crate::config::colors::Colors;
pub use crate::config::scrolling::Scrolling;
pub const LOG_TARGET_CONFIG: &str = "alacritty_config_derive";
const MIN_BLINK_INTERVAL: u64 = 10;
pub type MockConfig = Config<HashMap<String, serde_yaml::Value>>;
/// Top-level config type.
#[derive(ConfigDeserialize, Debug, PartialEq, Default)]
pub struct Config<T> {
/// TERM env variable.
pub env: HashMap<String, String>,
/// Should draw bold text with brighter colors instead of bold font.
pub draw_bold_text_with_bright_colors: bool,
pub colors: Colors,
pub selection: Selection,
/// Path to a shell program to run on startup.
pub shell: Option<Program>,
/// How much scrolling history to keep.
pub scrolling: Scrolling,
/// Cursor configuration.
pub cursor: Cursor,
/// Shell startup directory.
pub working_directory: Option<PathBuf>,
/// Additional configuration options not directly required by the terminal.
#[config(flatten)]
pub ui_config: T,
/// Remain open after child process exits.
#[config(skip)]
pub hold: bool,
/// Bell configuration.
bell: BellConfig,
#[config(deprecated = "use `bell` instead")]
pub visual_bell: Option<BellConfig>,
}
impl<T> Config<T> {
#[inline]
pub fn bell(&self) -> &BellConfig {
self.visual_bell.as_ref().unwrap_or(&self.bell)
}
}
#[derive(ConfigDeserialize, Clone, Debug, PartialEq, Eq)]
pub struct Selection {
pub semantic_escape_chars: String,
pub save_to_clipboard: bool,
}
impl Default for Selection {
fn default() -> Self {
Self {
semantic_escape_chars: String::from(",│`|:\"' ()[]{}<>\t"),
save_to_clipboard: Default::default(),
}
}
}
#[derive(ConfigDeserialize, Copy, Clone, Debug, PartialEq)]
pub struct Cursor {
pub style: ConfigCursorStyle,
pub vi_mode_style: Option<ConfigCursorStyle>,
pub unfocused_hollow: bool,
thickness: Percentage,
blink_interval: u64,
}
impl Default for Cursor {
fn default() -> Self {
Self {
thickness: Percentage(0.15),
unfocused_hollow: true,
blink_interval: 750,
style: Default::default(),
vi_mode_style: Default::default(),
}
}
}
impl Cursor {
#[inline]
pub fn thickness(self) -> f32 {
self.thickness.as_f32()
}
#[inline]
pub fn style(self) -> CursorStyle {
self.style.into()
}
#[inline]
pub fn vi_mode_style(self) -> Option<CursorStyle> {
self.vi_mode_style.map(From::from)
}
#[inline]
pub fn blink_interval(self) -> u64 {
max(self.blink_interval, MIN_BLINK_INTERVAL)
}
}
#[serde(untagged)]
#[derive(Deserialize, Debug, Copy, Clone, PartialEq, Eq)]
pub enum ConfigCursorStyle {
Shape(CursorShape),
WithBlinking { shape: CursorShape, blinking: CursorBlinking },
}
impl Default for ConfigCursorStyle {
fn default() -> Self {
Self::Shape(CursorShape::default())
}
}
impl ConfigCursorStyle {
/// Check if blinking is force enabled/disabled.
pub fn blinking_override(&self) -> Option<bool> {
match self {
Self::Shape(_) => None,
Self::WithBlinking { blinking, .. } => blinking.blinking_override(),
}
}
}
impl From<ConfigCursorStyle> for CursorStyle {
fn from(config_style: ConfigCursorStyle) -> Self {
match config_style {
ConfigCursorStyle::Shape(shape) => Self { shape, blinking: false },
ConfigCursorStyle::WithBlinking { shape, blinking } => {
Self { shape, blinking: blinking.into() }
},
}
}
}
#[derive(ConfigDeserialize, Debug, Copy, Clone, PartialEq, Eq)]
pub enum CursorBlinking {
Never,
Off,
On,
Always,
}
impl Default for CursorBlinking {
fn default() -> Self {
CursorBlinking::Off
}
}
impl CursorBlinking {
fn blinking_override(&self) -> Option<bool> {
match self {
Self::Never => Some(false),
Self::Off | Self::On => None,
Self::Always => Some(true),
}
}
}
impl Into<bool> for CursorBlinking {
fn into(self) -> bool {
self == Self::On || self == Self::Always
}
}
#[serde(untagged)]
#[derive(Deserialize, Debug, Clone, PartialEq, Eq)]
pub enum Program {
Just(String),
WithArgs { program: String, args: Vec<String> },
}
impl Program {
pub fn program(&self) -> &str {
match self {
Program::Just(program) => program,
Program::WithArgs { program, .. } => program,
}
}
pub fn args(&self) -> &[String] {
match self {
Program::Just(_) => &[],
Program::WithArgs { args, .. } => args,
}
}
}
/// Wrapper around f32 that represents a percentage value between 0.0 and 1.0.
#[derive(Deserialize, Clone, Copy, Debug, PartialEq)]
pub struct Percentage(f32);
impl Default for Percentage {
fn default() -> Self {
Percentage(1.0)
}
}
impl Percentage {
pub fn new(value: f32) -> Self {
Percentage(if value < 0.0 {
0.0
} else if value > 1.0 {
1.0
} else {
value
})
}
pub fn as_f32(self) -> f32 {
self.0
}
}
|