Skip to content

Commit cb7ad5b

Browse files
Switch to VTE's built-in ansi feature
Co-authored-by: Christian Duerr <[email protected]>
1 parent f0379f2 commit cb7ad5b

File tree

17 files changed

+208
-2038
lines changed

17 files changed

+208
-2038
lines changed

Cargo.lock

+8-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

alacritty/src/config/bell.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub struct BellConfig {
2323
impl Default for BellConfig {
2424
fn default() -> Self {
2525
Self {
26-
color: Rgb { r: 255, g: 255, b: 255 },
26+
color: Rgb::new(255, 255, 255),
2727
animation: Default::default(),
2828
command: Default::default(),
2929
duration: Default::default(),
@@ -39,7 +39,7 @@ impl BellConfig {
3939

4040
/// `VisualBellAnimations` are modeled after a subset of CSS transitions and Robert
4141
/// Penner's Easing Functions.
42-
#[derive(ConfigDeserialize, Clone, Copy, Debug, PartialEq, Eq)]
42+
#[derive(ConfigDeserialize, Default, Clone, Copy, Debug, PartialEq, Eq)]
4343
pub enum BellAnimation {
4444
// CSS animation.
4545
Ease,
@@ -56,15 +56,10 @@ pub enum BellAnimation {
5656
// Penner animation.
5757
EaseOutQuint,
5858
// Penner animation.
59+
#[default]
5960
EaseOutExpo,
6061
// Penner animation.
6162
EaseOutCirc,
6263
// Penner animation.
6364
Linear,
6465
}
65-
66-
impl Default for BellAnimation {
67-
fn default() -> Self {
68-
BellAnimation::EaseOutExpo
69-
}
70-
}

alacritty/src/config/color.rs

+34-34
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ pub struct HintStartColors {
5252
impl Default for HintStartColors {
5353
fn default() -> Self {
5454
Self {
55-
foreground: CellRgb::Rgb(Rgb { r: 0x1d, g: 0x1f, b: 0x21 }),
56-
background: CellRgb::Rgb(Rgb { r: 0xe9, g: 0xff, b: 0x5e }),
55+
foreground: CellRgb::Rgb(Rgb::new(0x1d, 0x1f, 0x21)),
56+
background: CellRgb::Rgb(Rgb::new(0xe9, 0xff, 0x5e)),
5757
}
5858
}
5959
}
@@ -67,8 +67,8 @@ pub struct HintEndColors {
6767
impl Default for HintEndColors {
6868
fn default() -> Self {
6969
Self {
70-
foreground: CellRgb::Rgb(Rgb { r: 0xe9, g: 0xff, b: 0x5e }),
71-
background: CellRgb::Rgb(Rgb { r: 0x1d, g: 0x1f, b: 0x21 }),
70+
foreground: CellRgb::Rgb(Rgb::new(0xe9, 0xff, 0x5e)),
71+
background: CellRgb::Rgb(Rgb::new(0x1d, 0x1f, 0x21)),
7272
}
7373
}
7474
}
@@ -139,8 +139,8 @@ pub struct FocusedMatchColors {
139139
impl Default for FocusedMatchColors {
140140
fn default() -> Self {
141141
Self {
142-
background: CellRgb::Rgb(Rgb { r: 0x00, g: 0x00, b: 0x00 }),
143-
foreground: CellRgb::Rgb(Rgb { r: 0xff, g: 0xff, b: 0xff }),
142+
background: CellRgb::Rgb(Rgb::new(0x00, 0x00, 0x00)),
143+
foreground: CellRgb::Rgb(Rgb::new(0xff, 0xff, 0xff)),
144144
}
145145
}
146146
}
@@ -154,8 +154,8 @@ pub struct MatchColors {
154154
impl Default for MatchColors {
155155
fn default() -> Self {
156156
Self {
157-
background: CellRgb::Rgb(Rgb { r: 0xff, g: 0xff, b: 0xff }),
158-
foreground: CellRgb::Rgb(Rgb { r: 0x00, g: 0x00, b: 0x00 }),
157+
background: CellRgb::Rgb(Rgb::new(0xff, 0xff, 0xff)),
158+
foreground: CellRgb::Rgb(Rgb::new(0x00, 0x00, 0x00)),
159159
}
160160
}
161161
}
@@ -177,8 +177,8 @@ pub struct PrimaryColors {
177177
impl Default for PrimaryColors {
178178
fn default() -> Self {
179179
PrimaryColors {
180-
background: Rgb { r: 0x1d, g: 0x1f, b: 0x21 },
181-
foreground: Rgb { r: 0xc5, g: 0xc8, b: 0xc6 },
180+
background: Rgb::new(0x1d, 0x1f, 0x21),
181+
foreground: Rgb::new(0xc5, 0xc8, 0xc6),
182182
bright_foreground: Default::default(),
183183
dim_foreground: Default::default(),
184184
}
@@ -200,14 +200,14 @@ pub struct NormalColors {
200200
impl Default for NormalColors {
201201
fn default() -> Self {
202202
NormalColors {
203-
black: Rgb { r: 0x1d, g: 0x1f, b: 0x21 },
204-
red: Rgb { r: 0xcc, g: 0x66, b: 0x66 },
205-
green: Rgb { r: 0xb5, g: 0xbd, b: 0x68 },
206-
yellow: Rgb { r: 0xf0, g: 0xc6, b: 0x74 },
207-
blue: Rgb { r: 0x81, g: 0xa2, b: 0xbe },
208-
magenta: Rgb { r: 0xb2, g: 0x94, b: 0xbb },
209-
cyan: Rgb { r: 0x8a, g: 0xbe, b: 0xb7 },
210-
white: Rgb { r: 0xc5, g: 0xc8, b: 0xc6 },
203+
black: Rgb::new(0x1d, 0x1f, 0x21),
204+
red: Rgb::new(0xcc, 0x66, 0x66),
205+
green: Rgb::new(0xb5, 0xbd, 0x68),
206+
yellow: Rgb::new(0xf0, 0xc6, 0x74),
207+
blue: Rgb::new(0x81, 0xa2, 0xbe),
208+
magenta: Rgb::new(0xb2, 0x94, 0xbb),
209+
cyan: Rgb::new(0x8a, 0xbe, 0xb7),
210+
white: Rgb::new(0xc5, 0xc8, 0xc6),
211211
}
212212
}
213213
}
@@ -227,14 +227,14 @@ pub struct BrightColors {
227227
impl Default for BrightColors {
228228
fn default() -> Self {
229229
BrightColors {
230-
black: Rgb { r: 0x66, g: 0x66, b: 0x66 },
231-
red: Rgb { r: 0xd5, g: 0x4e, b: 0x53 },
232-
green: Rgb { r: 0xb9, g: 0xca, b: 0x4a },
233-
yellow: Rgb { r: 0xe7, g: 0xc5, b: 0x47 },
234-
blue: Rgb { r: 0x7a, g: 0xa6, b: 0xda },
235-
magenta: Rgb { r: 0xc3, g: 0x97, b: 0xd8 },
236-
cyan: Rgb { r: 0x70, g: 0xc0, b: 0xb1 },
237-
white: Rgb { r: 0xea, g: 0xea, b: 0xea },
230+
black: Rgb::new(0x66, 0x66, 0x66),
231+
red: Rgb::new(0xd5, 0x4e, 0x53),
232+
green: Rgb::new(0xb9, 0xca, 0x4a),
233+
yellow: Rgb::new(0xe7, 0xc5, 0x47),
234+
blue: Rgb::new(0x7a, 0xa6, 0xda),
235+
magenta: Rgb::new(0xc3, 0x97, 0xd8),
236+
cyan: Rgb::new(0x70, 0xc0, 0xb1),
237+
white: Rgb::new(0xea, 0xea, 0xea),
238238
}
239239
}
240240
}
@@ -254,14 +254,14 @@ pub struct DimColors {
254254
impl Default for DimColors {
255255
fn default() -> Self {
256256
DimColors {
257-
black: Rgb { r: 0x13, g: 0x14, b: 0x15 },
258-
red: Rgb { r: 0x86, g: 0x43, b: 0x43 },
259-
green: Rgb { r: 0x77, g: 0x7c, b: 0x44 },
260-
yellow: Rgb { r: 0x9e, g: 0x82, b: 0x4c },
261-
blue: Rgb { r: 0x55, g: 0x6a, b: 0x7d },
262-
magenta: Rgb { r: 0x75, g: 0x61, b: 0x7b },
263-
cyan: Rgb { r: 0x5b, g: 0x7d, b: 0x78 },
264-
white: Rgb { r: 0x82, g: 0x84, b: 0x82 },
257+
black: Rgb::new(0x13, 0x14, 0x15),
258+
red: Rgb::new(0x86, 0x43, 0x43),
259+
green: Rgb::new(0x77, 0x7c, 0x44),
260+
yellow: Rgb::new(0x9e, 0x82, 0x4c),
261+
blue: Rgb::new(0x55, 0x6a, 0x7d),
262+
magenta: Rgb::new(0x75, 0x61, 0x7b),
263+
cyan: Rgb::new(0x5b, 0x7d, 0x78),
264+
white: Rgb::new(0x82, 0x84, 0x82),
265265
}
266266
}
267267
}

alacritty/src/config/window.rs

+4-14
Original file line numberDiff line numberDiff line change
@@ -154,23 +154,19 @@ impl Default for Identity {
154154
}
155155
}
156156

157-
#[derive(ConfigDeserialize, Debug, Copy, Clone, PartialEq, Eq)]
157+
#[derive(ConfigDeserialize, Default, Debug, Copy, Clone, PartialEq, Eq)]
158158
pub enum StartupMode {
159+
#[default]
159160
Windowed,
160161
Maximized,
161162
Fullscreen,
162163
#[cfg(target_os = "macos")]
163164
SimpleFullscreen,
164165
}
165166

166-
impl Default for StartupMode {
167-
fn default() -> StartupMode {
168-
StartupMode::Windowed
169-
}
170-
}
171-
172-
#[derive(ConfigDeserialize, Debug, Copy, Clone, PartialEq, Eq)]
167+
#[derive(ConfigDeserialize, Default, Debug, Copy, Clone, PartialEq, Eq)]
173168
pub enum Decorations {
169+
#[default]
174170
Full,
175171
#[cfg(target_os = "macos")]
176172
Transparent,
@@ -179,12 +175,6 @@ pub enum Decorations {
179175
None,
180176
}
181177

182-
impl Default for Decorations {
183-
fn default() -> Decorations {
184-
Decorations::Full
185-
}
186-
}
187-
188178
/// Window Dimensions.
189179
///
190180
/// Newtype to avoid passing values incorrectly.

alacritty/src/display/color.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,11 @@ impl List {
9595
{
9696
self[index] = indexed_color.color;
9797
} else {
98-
self[index] = Rgb {
99-
r: if r == 0 { 0 } else { r * 40 + 55 },
100-
b: if b == 0 { 0 } else { b * 40 + 55 },
101-
g: if g == 0 { 0 } else { g * 40 + 55 },
102-
};
98+
self[index] = Rgb::new(
99+
if r == 0 { 0 } else { r * 40 + 55 },
100+
if b == 0 { 0 } else { b * 40 + 55 },
101+
if g == 0 { 0 } else { g * 40 + 55 },
102+
);
103103
}
104104
index += 1;
105105
}
@@ -126,7 +126,7 @@ impl List {
126126
}
127127

128128
let value = i * 10 + 8;
129-
self[index] = Rgb { r: value, g: value, b: value };
129+
self[index] = Rgb::new(value, value, value);
130130
index += 1;
131131
}
132132

alacritty/src/display/content.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl<'a> RenderableContent<'a> {
121121

122122
let insufficient_contrast = (!matches!(cursor_color, CellRgb::Rgb(_))
123123
|| !matches!(text_color, CellRgb::Rgb(_)))
124-
&& cell.fg.contrast(cell.bg) < MIN_CURSOR_CONTRAST;
124+
&& cell.fg.contrast(*cell.bg) < MIN_CURSOR_CONTRAST;
125125

126126
// Convert from cell colors to RGB.
127127
let mut text_color = text_color.color(cell.fg, cell.bg);
@@ -307,8 +307,11 @@ impl RenderableCell {
307307
let config = &content.config;
308308
match fg {
309309
Color::Spec(rgb) => match flags & Flags::DIM {
310-
Flags::DIM => rgb * DIM_FACTOR,
311-
_ => rgb,
310+
Flags::DIM => {
311+
let rgb: Rgb = rgb.into();
312+
rgb * DIM_FACTOR
313+
},
314+
_ => rgb.into(),
312315
},
313316
Color::Named(ansi) => {
314317
match (config.draw_bold_text_with_bright_colors, flags & Flags::DIM_BOLD) {
@@ -350,7 +353,7 @@ impl RenderableCell {
350353
#[inline]
351354
fn compute_bg_rgb(content: &mut RenderableContent<'_>, bg: Color) -> Rgb {
352355
match bg {
353-
Color::Spec(rgb) => rgb,
356+
Color::Spec(rgb) => rgb.into(),
354357
Color::Named(ansi) => content.color(ansi as usize),
355358
Color::Indexed(idx) => content.color(idx as usize),
356359
}

alacritty/src/display/hint.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -647,25 +647,25 @@ mod tests {
647647
#[test]
648648
fn collect_unique_hyperlinks() {
649649
let mut term = mock_term("000\r\n111");
650-
term.goto(Line(0), Column(0));
650+
term.goto(0, 0);
651651

652652
let hyperlink_foo = Hyperlink::new(Some("1"), String::from("foo"));
653653
let hyperlink_bar = Hyperlink::new(Some("2"), String::from("bar"));
654654

655655
// Create 2 hyperlinks on the first line.
656-
term.set_hyperlink(Some(hyperlink_foo.clone()));
656+
term.set_hyperlink(Some(hyperlink_foo.clone().into()));
657657
term.input('b');
658658
term.input('a');
659-
term.set_hyperlink(Some(hyperlink_bar.clone()));
659+
term.set_hyperlink(Some(hyperlink_bar.clone().into()));
660660
term.input('r');
661-
term.set_hyperlink(Some(hyperlink_foo.clone()));
662-
term.goto(Line(1), Column(0));
661+
term.set_hyperlink(Some(hyperlink_foo.clone().into()));
662+
term.goto(1, 0);
663663

664664
// Ditto for the second line.
665-
term.set_hyperlink(Some(hyperlink_foo));
665+
term.set_hyperlink(Some(hyperlink_foo.into()));
666666
term.input('b');
667667
term.input('a');
668-
term.set_hyperlink(Some(hyperlink_bar));
668+
term.set_hyperlink(Some(hyperlink_bar.into()));
669669
term.input('r');
670670
term.set_hyperlink(None);
671671

alacritty/src/display/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ const BACKWARD_SEARCH_LABEL: &str = "Backward Search: ";
7373
const SHORTENER: char = '…';
7474

7575
/// Color which is used to highlight damaged rects when debugging.
76-
const DAMAGE_RECT_COLOR: Rgb = Rgb { r: 255, g: 0, b: 255 };
76+
const DAMAGE_RECT_COLOR: Rgb = Rgb::new(255, 0, 255);
7777

7878
#[derive(Debug)]
7979
pub enum Error {

alacritty/src/renderer/rects.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ impl RectRenderer {
366366
let y = -rect.y / half_height + 1.0;
367367
let width = rect.width / half_width;
368368
let height = rect.height / half_height;
369-
let Rgb { r, g, b } = rect.color;
369+
let (r, g, b) = rect.color.as_tuple();
370370
let a = (rect.alpha * 255.) as u8;
371371

372372
// Make quad vertices.

alacritty_terminal/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ regex-automata = "0.1.9"
3030
serde = { version = "1", features = ["derive", "rc"] }
3131
serde_yaml = "0.8"
3232
unicode-width = "0.1"
33-
vte = { version = "0.10.0", default-features = false }
33+
vte = { version = "0.11.1", default-features = false, features = ["ansi", "serde"] }
3434

3535
[target.'cfg(unix)'.dependencies]
3636
nix = { version = "0.26.2", default-features = false, features = ["term"] }

0 commit comments

Comments
 (0)