From e56e582f908fa7519d42a729e8f72f116cb81b68 Mon Sep 17 00:00:00 2001 From: Mohammad AlSaleh Date: Fri, 12 Jan 2024 01:58:57 +0300 Subject: [PATCH] Add option for setting dim font weight Allows users to set this to a value lower than default font weight. Signed-off-by: Mohammad AlSaleh --- i18n/en/cosmic_term.ftl | 1 + src/config.rs | 2 ++ src/main.rs | 31 +++++++++++++++++++++++++++++++ src/terminal.rs | 11 +++++++++++ 4 files changed, 45 insertions(+) diff --git a/i18n/en/cosmic_term.ftl b/i18n/en/cosmic_term.ftl index 6ca2614..395f650 100644 --- a/i18n/en/cosmic_term.ftl +++ b/i18n/en/cosmic_term.ftl @@ -15,6 +15,7 @@ advanced-font-settings = Advanced Font Settings default-font = Default font default-font-stretch = Default font stretch default-font-weight = Default font weight +default-dim-font-weight = Default dim 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 diff --git a/src/config.rs b/src/config.rs index 9033f19..ed855b5 100644 --- a/src/config.rs +++ b/src/config.rs @@ -35,6 +35,7 @@ pub struct Config { pub font_name: String, pub font_size: u16, pub font_weight: u16, + pub dim_font_weight: u16, pub bold_font_weight: u16, pub font_stretch: u16, pub font_size_zoom_step_mul_100: u16, @@ -51,6 +52,7 @@ impl Default for Config { font_name: "Fira Mono".to_string(), font_size: 14, font_weight: Weight::NORMAL.0, + dim_font_weight: Weight::NORMAL.0, bold_font_weight: Weight::BOLD.0, font_stretch: Stretch::Normal.to_number(), font_size_zoom_step_mul_100: 100, diff --git a/src/main.rs b/src/main.rs index d68b2dc..62e05a6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -160,6 +160,7 @@ pub enum Message { DefaultFontSize(usize), DefaultFontStretch(usize), DefaultFontWeight(usize), + DefaultDimFontWeight(usize), DefaultBoldFontWeight(usize), DefaultZoomStep(usize), Find(bool), @@ -350,6 +351,14 @@ impl App { self.config.font_weight = Weight::NORMAL.0; } + if !self + .curr_font_weights + .contains(&self.config.dim_font_weight) + { + self.config.dim_font_weight = Weight::NORMAL.0; + } + + if !self .curr_font_weights .contains(&self.config.bold_font_weight) @@ -391,6 +400,10 @@ impl App { .curr_font_weights .iter() .position(|font_weight| font_weight == &self.config.font_weight); + let dim_font_weight_selected = self + .curr_font_weights + .iter() + .position(|font_weight| font_weight == &self.config.dim_font_weight); let bold_font_weight_selected = self .curr_font_weights .iter() @@ -420,6 +433,15 @@ impl App { ), ), ) + .add( + widget::settings::item::builder(fl!("default-dim-font-weight")).control( + widget::dropdown( + &self.curr_font_weight_names, + dim_font_weight_selected, + |index| Message::DefaultDimFontWeight(index), + ), + ), + ) .add( widget::settings::item::builder(fl!("default-bold-font-weight")).control( widget::dropdown( @@ -778,6 +800,15 @@ impl Application for App { log::warn!("failed to find font weight with index {}", index); } }, + Message::DefaultDimFontWeight(index) => match self.curr_font_weights.get(index) { + Some(font_weight) => { + self.config.dim_font_weight = *font_weight; + return self.save_config(); + } + None => { + log::warn!("failed to find dim font weight with index {}", index); + } + }, Message::DefaultBoldFontWeight(index) => match self.curr_font_weights.get(index) { Some(font_weight) => { self.config.bold_font_weight = *font_weight; diff --git a/src/terminal.rs b/src/terminal.rs index 4512abc..617633d 100644 --- a/src/terminal.rs +++ b/src/terminal.rs @@ -138,6 +138,7 @@ pub struct Terminal { size: Size, pub term: Arc>>, colors: Colors, + dim_font_weight: Weight, bold_font_weight: Weight, use_bright_bold: bool, notifier: Notifier, @@ -158,6 +159,7 @@ impl Terminal { ) -> Self { let font_stretch = app_config.typed_font_stretch(); let font_weight = app_config.font_weight; + let dim_font_weight = app_config.dim_font_weight; let bold_font_weight = app_config.bold_font_weight; let use_bright_bold = app_config.use_bright_bold; @@ -206,6 +208,7 @@ impl Terminal { Self { colors, + dim_font_weight: Weight(dim_font_weight), bold_font_weight: Weight(bold_font_weight), use_bright_bold, default_attrs, @@ -455,6 +458,11 @@ impl Terminal { update_cell_size = true; } + if self.dim_font_weight.0 != config.dim_font_weight { + self.dim_font_weight = Weight(config.dim_font_weight); + update_cell_size = true; + } + if self.bold_font_weight.0 != config.font_weight { self.bold_font_weight = Weight(config.bold_font_weight); update_cell_size = true; @@ -639,6 +647,9 @@ impl Terminal { //TODO: more flags if indexed.cell.flags.contains(Flags::BOLD) { attrs = attrs.weight(self.bold_font_weight); + } else if indexed.cell.flags.contains(Flags::DIM) { + // if DIM and !BOLD + attrs = attrs.weight(self.dim_font_weight); } if indexed.cell.flags.contains(Flags::ITALIC) { //TODO: automatically use fake italic