Add a disabled-by-default toggle for using bright colors for bold text

Signed-off-by: Mohammad AlSaleh <CE.Mohammad.AlSaleh@gmail.com>
This commit is contained in:
Mohammad AlSaleh 2024-01-11 17:47:24 +03:00 • committed by Jeremy Soller
parent fc6e2de78b
commit b161db94d1
4 changed files with 32 additions and 8 deletions

View file

@ -16,6 +16,7 @@ default-font = Default font
default-font-stretch = Default font stretch default-font-stretch = Default font stretch
default-font-weight = Default font weight default-font-weight = Default font weight
default-bold-font-weight = Default bold 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-font-size = Default font size
default-zoom-step = Default zoom step default-zoom-step = Default zoom step

View file

@ -39,6 +39,7 @@ pub struct Config {
pub font_stretch: u16, pub font_stretch: u16,
pub font_size_zoom_step_mul_100: u16, pub font_size_zoom_step_mul_100: u16,
pub show_headerbar: bool, pub show_headerbar: bool,
pub use_bright_bold: bool,
pub syntax_theme_dark: String, pub syntax_theme_dark: String,
pub syntax_theme_light: String, pub syntax_theme_light: String,
} }
@ -54,6 +55,7 @@ impl Default for Config {
font_stretch: Stretch::Normal.to_number(), font_stretch: Stretch::Normal.to_number(),
font_size_zoom_step_mul_100: 100, font_size_zoom_step_mul_100: 100,
show_headerbar: true, show_headerbar: true,
use_bright_bold: false,
syntax_theme_dark: "COSMIC Dark".to_string(), syntax_theme_dark: "COSMIC Dark".to_string(),
syntax_theme_light: "COSMIC Light".to_string(), syntax_theme_light: "COSMIC Light".to_string(),
} }

View file

@ -147,6 +147,7 @@ pub enum Message {
Paste(Option<segmented_button::Entity>), Paste(Option<segmented_button::Entity>),
PasteValue(Option<segmented_button::Entity>, String), PasteValue(Option<segmented_button::Entity>, String),
SelectAll(Option<segmented_button::Entity>), SelectAll(Option<segmented_button::Entity>),
UseBrightBold(bool),
ShowHeaderBar(bool), ShowHeaderBar(bool),
SyntaxTheme(usize, bool), SyntaxTheme(usize, bool),
SystemThemeModeChange(cosmic_theme::ThemeMode), SystemThemeModeChange(cosmic_theme::ThemeMode),
@ -426,6 +427,10 @@ impl App {
} }
let settings_view = settings_view let settings_view = settings_view
.add(
widget::settings::item::builder(fl!("use-bright-bold"))
.toggler(self.config.use_bright_bold, Message::UseBrightBold),
)
.add( .add(
widget::settings::item::builder(fl!("default-font-size")).control( widget::settings::item::builder(fl!("default-font-size")).control(
widget::dropdown(&self.font_size_names, font_size_selected, |index| { widget::dropdown(&self.font_size_names, font_size_selected, |index| {
@ -734,6 +739,12 @@ impl Application for App {
return self.save_config(); 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) => { Message::SystemThemeModeChange(_theme_mode) => {
return self.update_config(); return self.update_config();
} }
@ -814,9 +825,7 @@ impl Application for App {
entity, entity,
term_event_tx.clone(), term_event_tx.clone(),
self.term_config.clone(), self.term_config.clone(),
self.config.typed_font_stretch(), &self.config,
self.config.font_weight,
self.config.bold_font_weight,
colors.clone(), colors.clone(),
); );
terminal.set_config(&self.config, &self.themes, self.zoom_adj); terminal.set_config(&self.config, &self.themes, self.zoom_adj);

View file

@ -29,6 +29,8 @@ use tokio::sync::mpsc;
pub use alacritty_terminal::grid::Scroll as TerminalScroll; pub use alacritty_terminal::grid::Scroll as TerminalScroll;
use crate::config::Config as AppConfig;
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
pub struct Size { pub struct Size {
pub width: u32, pub width: u32,
@ -129,6 +131,7 @@ pub struct Terminal {
pub term: Arc<FairMutex<Term<EventProxy>>>, pub term: Arc<FairMutex<Term<EventProxy>>>,
colors: Colors, colors: Colors,
bold_font_weight: Weight, bold_font_weight: Weight,
use_bright_bold: bool,
notifier: Notifier, notifier: Notifier,
pub context_menu: Option<cosmic::iced::Point>, pub context_menu: Option<cosmic::iced::Point>,
pub needs_update: bool, pub needs_update: bool,
@ -140,11 +143,14 @@ impl Terminal {
entity: segmented_button::Entity, entity: segmented_button::Entity,
event_tx: mpsc::Sender<(segmented_button::Entity, Event)>, event_tx: mpsc::Sender<(segmented_button::Entity, Event)>,
config: Config, config: Config,
font_stretch: Stretch, app_config: &AppConfig,
font_weight: u16,
bold_font_weight: u16,
colors: Colors, colors: Colors,
) -> Self { ) -> 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); let metrics = Metrics::new(14.0, 20.0);
//TODO: set color to default fg //TODO: set color to default fg
let default_attrs = Attrs::new() let default_attrs = Attrs::new()
@ -191,6 +197,7 @@ impl Terminal {
Self { Self {
colors, colors,
bold_font_weight: Weight(bold_font_weight), bold_font_weight: Weight(bold_font_weight),
use_bright_bold,
default_attrs, default_attrs,
buffer: Arc::new(buffer), buffer: Arc::new(buffer),
size, size,
@ -334,7 +341,7 @@ impl Terminal {
pub fn set_config( pub fn set_config(
&mut self, &mut self,
config: &crate::Config, config: &AppConfig,
themes: &HashMap<String, Colors>, themes: &HashMap<String, Colors>,
zoom_adj: i8, zoom_adj: i8,
) { ) {
@ -357,6 +364,11 @@ impl Terminal {
update_cell_size = true; 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); let metrics = config.metrics(zoom_adj);
if metrics != self.buffer.metrics() { if metrics != self.buffer.metrics() {
{ {
@ -473,7 +485,7 @@ impl Terminal {
let mut attrs = self.default_attrs; 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) as_bright(indexed.cell.fg)
} else { } else {
indexed.cell.fg indexed.cell.fg