From b161db94d1974c3eccd9611c9d62431c48e7c018 Mon Sep 17 00:00:00 2001 From: Mohammad AlSaleh Date: Thu, 11 Jan 2024 17:47:24 +0300 Subject: [PATCH] Add a disabled-by-default toggle for using bright colors for bold text Signed-off-by: Mohammad AlSaleh --- i18n/en/cosmic_term.ftl | 1 + src/config.rs | 2 ++ src/main.rs | 15 ++++++++++++--- src/terminal.rs | 22 +++++++++++++++++----- 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/i18n/en/cosmic_term.ftl b/i18n/en/cosmic_term.ftl index ceefd25..11e9031 100644 --- a/i18n/en/cosmic_term.ftl +++ b/i18n/en/cosmic_term.ftl @@ -16,6 +16,7 @@ default-font = Default font default-font-stretch = Default font stretch default-font-weight = Default font weight default-bold-font-weight = Default bold font weight +use-bright-bold = Use bright colors with bold text default-font-size = Default font size default-zoom-step = Default zoom step diff --git a/src/config.rs b/src/config.rs index 802485a..77b17ce 100644 --- a/src/config.rs +++ b/src/config.rs @@ -39,6 +39,7 @@ pub struct Config { pub font_stretch: u16, pub font_size_zoom_step_mul_100: u16, pub show_headerbar: bool, + pub use_bright_bold: bool, pub syntax_theme_dark: String, pub syntax_theme_light: String, } @@ -54,6 +55,7 @@ impl Default for Config { font_stretch: Stretch::Normal.to_number(), font_size_zoom_step_mul_100: 100, show_headerbar: true, + use_bright_bold: false, syntax_theme_dark: "COSMIC Dark".to_string(), syntax_theme_light: "COSMIC Light".to_string(), } diff --git a/src/main.rs b/src/main.rs index 4aed03f..14d4b11 100644 --- a/src/main.rs +++ b/src/main.rs @@ -147,6 +147,7 @@ pub enum Message { Paste(Option), PasteValue(Option, String), SelectAll(Option), + UseBrightBold(bool), ShowHeaderBar(bool), SyntaxTheme(usize, bool), SystemThemeModeChange(cosmic_theme::ThemeMode), @@ -426,6 +427,10 @@ impl App { } let settings_view = settings_view + .add( + widget::settings::item::builder(fl!("use-bright-bold")) + .toggler(self.config.use_bright_bold, Message::UseBrightBold), + ) .add( widget::settings::item::builder(fl!("default-font-size")).control( widget::dropdown(&self.font_size_names, font_size_selected, |index| { @@ -734,6 +739,12 @@ impl Application for App { return self.save_config(); } } + Message::UseBrightBold(use_bright_bold) => { + if use_bright_bold != self.config.use_bright_bold { + self.config.use_bright_bold = use_bright_bold; + return self.save_config(); + } + } Message::SystemThemeModeChange(_theme_mode) => { return self.update_config(); } @@ -814,9 +825,7 @@ impl Application for App { entity, term_event_tx.clone(), self.term_config.clone(), - self.config.typed_font_stretch(), - self.config.font_weight, - self.config.bold_font_weight, + &self.config, colors.clone(), ); terminal.set_config(&self.config, &self.themes, self.zoom_adj); diff --git a/src/terminal.rs b/src/terminal.rs index 4f118c4..cbb628a 100644 --- a/src/terminal.rs +++ b/src/terminal.rs @@ -29,6 +29,8 @@ use tokio::sync::mpsc; pub use alacritty_terminal::grid::Scroll as TerminalScroll; +use crate::config::Config as AppConfig; + #[derive(Clone, Copy, Debug)] pub struct Size { pub width: u32, @@ -129,6 +131,7 @@ pub struct Terminal { pub term: Arc>>, colors: Colors, bold_font_weight: Weight, + use_bright_bold: bool, notifier: Notifier, pub context_menu: Option, pub needs_update: bool, @@ -140,11 +143,14 @@ impl Terminal { entity: segmented_button::Entity, event_tx: mpsc::Sender<(segmented_button::Entity, Event)>, config: Config, - font_stretch: Stretch, - font_weight: u16, - bold_font_weight: u16, + app_config: &AppConfig, colors: Colors, ) -> Self { + let font_stretch = app_config.typed_font_stretch(); + let font_weight = app_config.font_weight; + let bold_font_weight = app_config.bold_font_weight; + let use_bright_bold = app_config.use_bright_bold; + let metrics = Metrics::new(14.0, 20.0); //TODO: set color to default fg let default_attrs = Attrs::new() @@ -191,6 +197,7 @@ impl Terminal { Self { colors, bold_font_weight: Weight(bold_font_weight), + use_bright_bold, default_attrs, buffer: Arc::new(buffer), size, @@ -334,7 +341,7 @@ impl Terminal { pub fn set_config( &mut self, - config: &crate::Config, + config: &AppConfig, themes: &HashMap, zoom_adj: i8, ) { @@ -357,6 +364,11 @@ impl Terminal { update_cell_size = true; } + if self.use_bright_bold != config.use_bright_bold { + self.use_bright_bold = config.use_bright_bold; + update_cell_size = true; + } + let metrics = config.metrics(zoom_adj); if metrics != self.buffer.metrics() { { @@ -473,7 +485,7 @@ impl Terminal { let mut attrs = self.default_attrs; - let cell_fg = if indexed.cell.flags.contains(Flags::BOLD) { + let cell_fg = if self.use_bright_bold && indexed.cell.flags.contains(Flags::BOLD) { as_bright(indexed.cell.fg) } else { indexed.cell.fg