summaryrefslogtreecommitdiff
path: root/alacritty_terminal/src/term/mod.rs
diff options
context:
space:
mode:
authorChristian Duerr <contact@christianduerr.com>2020-12-21 02:44:38 +0000
committerGitHub <noreply@github.com>2020-12-21 02:44:38 +0000
commit6e1b9d8b2502f5b47dc28eb5e0853e46ad8b4e84 (patch)
tree623a6cd8785529b28cc28af201c26b56fb47ac46 /alacritty_terminal/src/term/mod.rs
parent37a3198d8882463c9873011c1d18c325ea46d7c8 (diff)
downloadalacritty-6e1b9d8b2502f5b47dc28eb5e0853e46ad8b4e84.tar.gz
alacritty-6e1b9d8b2502f5b47dc28eb5e0853e46ad8b4e84.zip
Replace serde's derive with custom proc macro
This replaces the existing `Deserialize` derive from serde with a `ConfigDeserialize` derive. The goal of this new proc macro is to allow a more error-friendly deserialization for the Alacritty configuration file without having to manage a lot of boilerplate code inside the configuration modules. The first part of the derive macro is for struct deserialization. This takes structs which have `Default` implemented and will only replace fields which can be successfully deserialized. Otherwise the `log` crate is used for printing errors. Since this deserialization takes the default value from the struct instead of the value, it removes the necessity for creating new types just to implement `Default` on them for deserialization. Additionally, the struct deserialization also checks for `Option` values and makes sure that explicitly specifying `none` as text literal is allowed for all options. The other part of the derive macro is responsible for deserializing enums. While only enums with Unit variants are supported, it will automatically implement a deserializer for these enums which accepts any form of capitalization. Since this custom derive prevents us from using serde's attributes on fields, some of the attributes have been reimplemented for `ConfigDeserialize`. These include `#[config(flatten)]`, `#[config(skip)]` and `#[config(alias = "alias)]`. The flatten attribute is currently limited to at most one per struct. Additionally the `#[config(deprecated = "optional message")]` attribute allows easily defining uniform deprecation messages for fields on structs.
Diffstat (limited to 'alacritty_terminal/src/term/mod.rs')
-rw-r--r--alacritty_terminal/src/term/mod.rs27
1 files changed, 12 insertions, 15 deletions
diff --git a/alacritty_terminal/src/term/mod.rs b/alacritty_terminal/src/term/mod.rs
index 154a24a2..64493bd9 100644
--- a/alacritty_terminal/src/term/mod.rs
+++ b/alacritty_terminal/src/term/mod.rs
@@ -157,7 +157,7 @@ impl<'a, C> Iterator for RenderableCellsIter<'a, C> {
if self.cursor.rendered {
return self.next_cursor_cell();
} else {
- return self.next_cursor();
+ return Some(self.next_cursor());
}
} else {
// Handle non-cursor cells.
@@ -213,7 +213,7 @@ impl<'a, C> RenderableCellsIter<'a, C> {
}
/// Get the next renderable cell as the cursor.
- fn next_cursor(&mut self) -> Option<RenderableCell> {
+ fn next_cursor(&mut self) -> RenderableCell {
// Handle cursor.
self.cursor.rendered = true;
@@ -236,7 +236,7 @@ impl<'a, C> RenderableCellsIter<'a, C> {
cell.fg = self.cursor.cursor_color.color(cell.fg, cell.bg);
}
- Some(cell)
+ cell
}
/// Check selection state of a cell.
@@ -323,8 +323,8 @@ impl RenderableCell {
let mut is_match = false;
if iter.is_selected(point) {
- let config_bg = iter.config.colors.selection.background();
- let selected_fg = iter.config.colors.selection.foreground().color(fg_rgb, bg_rgb);
+ let config_bg = iter.config.colors.selection.background;
+ let selected_fg = iter.config.colors.selection.foreground.color(fg_rgb, bg_rgb);
bg_rgb = config_bg.color(fg_rgb, bg_rgb);
fg_rgb = selected_fg;
@@ -377,7 +377,7 @@ impl RenderableCell {
_ => rgb,
},
Color::Named(ansi) => {
- match (config.draw_bold_text_with_bright_colors(), flags & Flags::DIM_BOLD) {
+ match (config.draw_bold_text_with_bright_colors, flags & Flags::DIM_BOLD) {
// If no bright foreground is set, treat it like the BOLD flag doesn't exist.
(_, Flags::DIM_BOLD)
if ansi == NamedColor::Foreground
@@ -395,7 +395,7 @@ impl RenderableCell {
},
Color::Indexed(idx) => {
let idx = match (
- config.draw_bold_text_with_bright_colors(),
+ config.draw_bold_text_with_bright_colors,
flags & Flags::DIM_BOLD,
idx,
) {
@@ -851,7 +851,7 @@ impl<T> Term<T> {
colors,
color_modified: [false; color::COUNT],
original_colors: colors,
- semantic_escape_chars: config.selection.semantic_escape_chars().to_owned(),
+ semantic_escape_chars: config.selection.semantic_escape_chars.to_owned(),
cursor_style: None,
default_cursor_style: config.cursor.style(),
vi_mode_cursor_style: config.cursor.vi_mode_style(),
@@ -870,7 +870,7 @@ impl<T> Term<T> {
where
T: EventListener,
{
- self.semantic_escape_chars = config.selection.semantic_escape_chars().to_owned();
+ self.semantic_escape_chars = config.selection.semantic_escape_chars.to_owned();
self.original_colors.fill_named(&config.colors);
self.original_colors.fill_cube(&config.colors);
self.original_colors.fill_gray_ramp(&config.colors);
@@ -880,9 +880,6 @@ impl<T> Term<T> {
}
}
self.visual_bell.update_config(config);
- if let Some(0) = config.scrolling.faux_multiplier() {
- self.mode.remove(TermMode::ALTERNATE_SCROLL);
- }
self.default_cursor_style = config.cursor.style();
self.vi_mode_cursor_style = config.cursor.vi_mode_style();
@@ -1418,7 +1415,7 @@ impl<T> Term<T> {
let cursor_shape = if hidden {
point.line = Line(0);
CursorShape::Hidden
- } else if !self.is_focused && config.cursor.unfocused_hollow() {
+ } else if !self.is_focused && config.cursor.unfocused_hollow {
CursorShape::HollowBlock
} else {
let cursor_style = self.cursor_style.unwrap_or(self.default_cursor_style);
@@ -1435,9 +1432,9 @@ impl<T> Term<T> {
let cursor_color = if self.color_modified[NamedColor::Cursor as usize] {
CellRgb::Rgb(self.colors[NamedColor::Cursor])
} else {
- color.cursor()
+ color.background
};
- let text_color = color.text();
+ let text_color = color.foreground;
// Expand across wide cell when inside wide char or spacer.
let buffer_point = self.visible_to_buffer(point);