diff --git a/src/components/mail/listing.rs b/src/components/mail/listing.rs index 8f7f40a68..1b3410ee6 100644 --- a/src/components/mail/listing.rs +++ b/src/components/mail/listing.rs @@ -1041,10 +1041,7 @@ impl Listing { crate::conf::value(context, "mail.sidebar_highlighted_unread_count"), ); - if std::env::var("NO_COLOR").is_ok() - && (context.settings.terminal.use_color.is_false() - || context.settings.terminal.use_color.is_internal()) - { + if !context.settings.terminal.use_color() { ret.0.attrs |= Attr::Reverse; ret.1.attrs |= Attr::Reverse; ret.2.attrs |= Attr::Reverse; diff --git a/src/components/mail/listing/compact.rs b/src/components/mail/listing/compact.rs index b2beb2a30..67a2da085 100644 --- a/src/components/mail/listing/compact.rs +++ b/src/components/mail/listing/compact.rs @@ -125,10 +125,7 @@ impl MailListingTrait for CompactListing { theme_default: crate::conf::value(context, "theme_default"), ..self.color_cache }; - if std::env::var("NO_COLOR").is_ok() - && (context.settings.terminal.use_color.is_false() - || context.settings.terminal.use_color.is_internal()) - { + if !context.settings.terminal.use_color() { self.color_cache.highlighted.attrs |= Attr::Reverse; } diff --git a/src/components/mail/listing/conversations.rs b/src/components/mail/listing/conversations.rs index fded17821..d6b7cda6b 100644 --- a/src/components/mail/listing/conversations.rs +++ b/src/components/mail/listing/conversations.rs @@ -111,10 +111,7 @@ impl MailListingTrait for ConversationsListing { ..self.color_cache }; - if std::env::var("NO_COLOR").is_ok() - && (context.settings.terminal.use_color.is_false() - || context.settings.terminal.use_color.is_internal()) - { + if !context.settings.terminal.use_color() { self.color_cache.highlighted.attrs |= Attr::Reverse; } // Get mailbox as a reference. diff --git a/src/components/mail/listing/plain.rs b/src/components/mail/listing/plain.rs index 2b88b026e..1156d8e4a 100644 --- a/src/components/mail/listing/plain.rs +++ b/src/components/mail/listing/plain.rs @@ -125,10 +125,7 @@ impl MailListingTrait for PlainListing { thread_snooze_flag: crate::conf::value(context, "mail.listing.thread_snooze_flag"), ..self.color_cache }; - if std::env::var("NO_COLOR").is_ok() - && (context.settings.terminal.use_color.is_false() - || context.settings.terminal.use_color.is_internal()) - { + if !context.settings.terminal.use_color() { self.color_cache.highlighted.attrs |= Attr::Reverse; } diff --git a/src/components/mail/listing/thread.rs b/src/components/mail/listing/thread.rs index da085f9e9..6cad1054e 100644 --- a/src/components/mail/listing/thread.rs +++ b/src/components/mail/listing/thread.rs @@ -82,10 +82,7 @@ impl MailListingTrait for ThreadListing { thread_snooze_flag: crate::conf::value(context, "mail.listing.thread_snooze_flag"), ..self.color_cache }; - if std::env::var("NO_COLOR").is_ok() - && (context.settings.terminal.use_color.is_false() - || context.settings.terminal.use_color.is_internal()) - { + if !context.settings.terminal.use_color() { self.color_cache.highlighted.attrs |= Attr::Reverse; } diff --git a/src/components/utilities.rs b/src/components/utilities.rs index 5837303e5..933fc7952 100644 --- a/src/components/utilities.rs +++ b/src/components/utilities.rs @@ -769,10 +769,7 @@ impl StatusBar { } fn draw_status_bar(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) { let mut attribute = crate::conf::value(context, "status.bar"); - if std::env::var("NO_COLOR").is_ok() - && (context.settings.terminal.use_color.is_false() - || context.settings.terminal.use_color.is_internal()) - { + if !context.settings.terminal.use_color() { attribute.attrs |= Attr::Reverse; } let (x, y) = write_string_to_grid( @@ -1347,10 +1344,7 @@ impl Tabbed { } let tab_unfocused_attribute = crate::conf::value(context, "tab.unfocused"); let mut tab_focused_attribute = crate::conf::value(context, "tab.focused"); - if std::env::var("NO_COLOR").is_ok() - && (context.settings.terminal.use_color.is_false() - || context.settings.terminal.use_color.is_internal()) - { + if !context.settings.terminal.use_color() { tab_focused_attribute.attrs |= Attr::Reverse; } @@ -1836,10 +1830,7 @@ impl Component for Selector { let (width, height) = self.content.size(); let shortcuts = self.get_shortcuts(context); let mut highlighted_attrs = crate::conf::value(context, "widgets.options.highlighted"); - if std::env::var("NO_COLOR").is_ok() - && (context.settings.terminal.use_color.is_false() - || context.settings.terminal.use_color.is_internal()) - { + if !context.settings.terminal.use_color() { highlighted_attrs.attrs |= Attr::Reverse; } match (event, self.cursor) { @@ -1947,10 +1938,7 @@ impl Component for Selector { self.cursor = SelectorCursor::Entry(c); let mut highlighted_attrs = crate::conf::value(context, "widgets.options.highlighted"); - if std::env::var("NO_COLOR").is_ok() - && (context.settings.terminal.use_color.is_false() - || context.settings.terminal.use_color.is_internal()) - { + if !context.settings.terminal.use_color() { highlighted_attrs.attrs |= Attr::Reverse; } for c in self.content.row_iter(2..4, c + 2) { @@ -2227,10 +2215,7 @@ impl Selector { ); } let mut highlighted_attrs = crate::conf::value(context, "widgets.options.highlighted"); - if std::env::var("NO_COLOR").is_ok() - && (context.settings.terminal.use_color.is_false() - || context.settings.terminal.use_color.is_internal()) - { + if !context.settings.terminal.use_color() { highlighted_attrs.attrs |= Attr::Reverse; } if single_only { diff --git a/src/components/utilities/widgets.rs b/src/components/utilities/widgets.rs index c5faf3fcc..778646b52 100644 --- a/src/components/utilities/widgets.rs +++ b/src/components/utilities/widgets.rs @@ -430,10 +430,7 @@ impl Component for FormWidget { if self.focus == FormFocus::Fields { let mut field_attrs = crate::conf::value(context, "widgets.form.highlighted"); - if std::env::var("NO_COLOR").is_ok() - && (context.settings.terminal.use_color.is_false() - || context.settings.terminal.use_color.is_internal()) - { + if !context.settings.terminal.use_color() { field_attrs.attrs |= Attr::Reverse; } for row in grid.bounds_iter(( diff --git a/src/conf/terminal.rs b/src/conf/terminal.rs index 2f5f7d7dd..e7c916b41 100644 --- a/src/conf/terminal.rs +++ b/src/conf/terminal.rs @@ -49,3 +49,15 @@ impl Default for TerminalSettings { } } } + +impl TerminalSettings { + pub fn use_color(&self) -> bool { + /* Don't use color if + * - Either NO_COLOR is set and user hasn't explicitly set use_colors or + * - User has explicitly set use_colors to false + */ + !((std::env::var("NO_COLOR").is_ok() + && (self.use_color.is_false() || self.use_color.is_internal())) + || (self.use_color.is_false() && !self.use_color.is_internal())) + } +} diff --git a/src/state.rs b/src/state.rs index 61779cc88..656ef13fb 100644 --- a/src/state.rs +++ b/src/state.rs @@ -296,13 +296,10 @@ impl State { components: Vec::with_capacity(1), timer, draw_rate_limit: RateLimit::new(1, 3), - draw_horizontal_segment_fn: if env::var("NO_COLOR").is_ok() - && (settings.terminal.use_color.is_false() - || settings.terminal.use_color.is_internal()) - { - State::draw_horizontal_segment_no_color - } else { + draw_horizontal_segment_fn: if settings.terminal.use_color() { State::draw_horizontal_segment + } else { + State::draw_horizontal_segment_no_color }, display_messages: SmallVec::new(), display_messages_expiration_start: None,