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 <CE.Mohammad.AlSaleh@gmail.com>
This commit is contained in:
Mohammad AlSaleh 2024-01-12 01:58:57 +03:00 committed by Jeremy Soller
parent f34116f3f7
commit e56e582f90
4 changed files with 45 additions and 0 deletions

View file

@ -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

View file

@ -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,

View file

@ -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;

View file

@ -138,6 +138,7 @@ pub struct Terminal {
size: Size,
pub term: Arc<FairMutex<Term<EventProxy>>>,
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