Respect use_color conf value as well as NO_COLOR

memfd
Manos Pitsidianakis 2020-02-09 20:47:36 +02:00
parent a496de2794
commit 14b0ef8f37
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
9 changed files with 26 additions and 50 deletions

View File

@ -1041,10 +1041,7 @@ impl Listing {
crate::conf::value(context, "mail.sidebar_highlighted_unread_count"), crate::conf::value(context, "mail.sidebar_highlighted_unread_count"),
); );
if std::env::var("NO_COLOR").is_ok() if !context.settings.terminal.use_color() {
&& (context.settings.terminal.use_color.is_false()
|| context.settings.terminal.use_color.is_internal())
{
ret.0.attrs |= Attr::Reverse; ret.0.attrs |= Attr::Reverse;
ret.1.attrs |= Attr::Reverse; ret.1.attrs |= Attr::Reverse;
ret.2.attrs |= Attr::Reverse; ret.2.attrs |= Attr::Reverse;

View File

@ -125,10 +125,7 @@ impl MailListingTrait for CompactListing {
theme_default: crate::conf::value(context, "theme_default"), theme_default: crate::conf::value(context, "theme_default"),
..self.color_cache ..self.color_cache
}; };
if std::env::var("NO_COLOR").is_ok() if !context.settings.terminal.use_color() {
&& (context.settings.terminal.use_color.is_false()
|| context.settings.terminal.use_color.is_internal())
{
self.color_cache.highlighted.attrs |= Attr::Reverse; self.color_cache.highlighted.attrs |= Attr::Reverse;
} }

View File

@ -111,10 +111,7 @@ impl MailListingTrait for ConversationsListing {
..self.color_cache ..self.color_cache
}; };
if std::env::var("NO_COLOR").is_ok() if !context.settings.terminal.use_color() {
&& (context.settings.terminal.use_color.is_false()
|| context.settings.terminal.use_color.is_internal())
{
self.color_cache.highlighted.attrs |= Attr::Reverse; self.color_cache.highlighted.attrs |= Attr::Reverse;
} }
// Get mailbox as a reference. // Get mailbox as a reference.

View File

@ -125,10 +125,7 @@ impl MailListingTrait for PlainListing {
thread_snooze_flag: crate::conf::value(context, "mail.listing.thread_snooze_flag"), thread_snooze_flag: crate::conf::value(context, "mail.listing.thread_snooze_flag"),
..self.color_cache ..self.color_cache
}; };
if std::env::var("NO_COLOR").is_ok() if !context.settings.terminal.use_color() {
&& (context.settings.terminal.use_color.is_false()
|| context.settings.terminal.use_color.is_internal())
{
self.color_cache.highlighted.attrs |= Attr::Reverse; self.color_cache.highlighted.attrs |= Attr::Reverse;
} }

View File

@ -82,10 +82,7 @@ impl MailListingTrait for ThreadListing {
thread_snooze_flag: crate::conf::value(context, "mail.listing.thread_snooze_flag"), thread_snooze_flag: crate::conf::value(context, "mail.listing.thread_snooze_flag"),
..self.color_cache ..self.color_cache
}; };
if std::env::var("NO_COLOR").is_ok() if !context.settings.terminal.use_color() {
&& (context.settings.terminal.use_color.is_false()
|| context.settings.terminal.use_color.is_internal())
{
self.color_cache.highlighted.attrs |= Attr::Reverse; self.color_cache.highlighted.attrs |= Attr::Reverse;
} }

View File

@ -769,10 +769,7 @@ impl StatusBar {
} }
fn draw_status_bar(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) { fn draw_status_bar(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) {
let mut attribute = crate::conf::value(context, "status.bar"); let mut attribute = crate::conf::value(context, "status.bar");
if std::env::var("NO_COLOR").is_ok() if !context.settings.terminal.use_color() {
&& (context.settings.terminal.use_color.is_false()
|| context.settings.terminal.use_color.is_internal())
{
attribute.attrs |= Attr::Reverse; attribute.attrs |= Attr::Reverse;
} }
let (x, y) = write_string_to_grid( let (x, y) = write_string_to_grid(
@ -1347,10 +1344,7 @@ impl Tabbed {
} }
let tab_unfocused_attribute = crate::conf::value(context, "tab.unfocused"); let tab_unfocused_attribute = crate::conf::value(context, "tab.unfocused");
let mut tab_focused_attribute = crate::conf::value(context, "tab.focused"); let mut tab_focused_attribute = crate::conf::value(context, "tab.focused");
if std::env::var("NO_COLOR").is_ok() if !context.settings.terminal.use_color() {
&& (context.settings.terminal.use_color.is_false()
|| context.settings.terminal.use_color.is_internal())
{
tab_focused_attribute.attrs |= Attr::Reverse; tab_focused_attribute.attrs |= Attr::Reverse;
} }
@ -1836,10 +1830,7 @@ impl<T: PartialEq + Debug + Clone + Sync + Send> Component for Selector<T> {
let (width, height) = self.content.size(); let (width, height) = self.content.size();
let shortcuts = self.get_shortcuts(context); let shortcuts = self.get_shortcuts(context);
let mut highlighted_attrs = crate::conf::value(context, "widgets.options.highlighted"); let mut highlighted_attrs = crate::conf::value(context, "widgets.options.highlighted");
if std::env::var("NO_COLOR").is_ok() if !context.settings.terminal.use_color() {
&& (context.settings.terminal.use_color.is_false()
|| context.settings.terminal.use_color.is_internal())
{
highlighted_attrs.attrs |= Attr::Reverse; highlighted_attrs.attrs |= Attr::Reverse;
} }
match (event, self.cursor) { match (event, self.cursor) {
@ -1947,10 +1938,7 @@ impl<T: PartialEq + Debug + Clone + Sync + Send> Component for Selector<T> {
self.cursor = SelectorCursor::Entry(c); self.cursor = SelectorCursor::Entry(c);
let mut highlighted_attrs = let mut highlighted_attrs =
crate::conf::value(context, "widgets.options.highlighted"); crate::conf::value(context, "widgets.options.highlighted");
if std::env::var("NO_COLOR").is_ok() if !context.settings.terminal.use_color() {
&& (context.settings.terminal.use_color.is_false()
|| context.settings.terminal.use_color.is_internal())
{
highlighted_attrs.attrs |= Attr::Reverse; highlighted_attrs.attrs |= Attr::Reverse;
} }
for c in self.content.row_iter(2..4, c + 2) { for c in self.content.row_iter(2..4, c + 2) {
@ -2227,10 +2215,7 @@ impl<T: PartialEq + Debug + Clone + Sync + Send> Selector<T> {
); );
} }
let mut highlighted_attrs = crate::conf::value(context, "widgets.options.highlighted"); let mut highlighted_attrs = crate::conf::value(context, "widgets.options.highlighted");
if std::env::var("NO_COLOR").is_ok() if !context.settings.terminal.use_color() {
&& (context.settings.terminal.use_color.is_false()
|| context.settings.terminal.use_color.is_internal())
{
highlighted_attrs.attrs |= Attr::Reverse; highlighted_attrs.attrs |= Attr::Reverse;
} }
if single_only { if single_only {

View File

@ -430,10 +430,7 @@ impl Component for FormWidget {
if self.focus == FormFocus::Fields { if self.focus == FormFocus::Fields {
let mut field_attrs = let mut field_attrs =
crate::conf::value(context, "widgets.form.highlighted"); crate::conf::value(context, "widgets.form.highlighted");
if std::env::var("NO_COLOR").is_ok() if !context.settings.terminal.use_color() {
&& (context.settings.terminal.use_color.is_false()
|| context.settings.terminal.use_color.is_internal())
{
field_attrs.attrs |= Attr::Reverse; field_attrs.attrs |= Attr::Reverse;
} }
for row in grid.bounds_iter(( for row in grid.bounds_iter((

View File

@ -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()))
}
}

View File

@ -296,13 +296,10 @@ impl State {
components: Vec::with_capacity(1), components: Vec::with_capacity(1),
timer, timer,
draw_rate_limit: RateLimit::new(1, 3), draw_rate_limit: RateLimit::new(1, 3),
draw_horizontal_segment_fn: if env::var("NO_COLOR").is_ok() draw_horizontal_segment_fn: if settings.terminal.use_color() {
&& (settings.terminal.use_color.is_false()
|| settings.terminal.use_color.is_internal())
{
State::draw_horizontal_segment_no_color
} else {
State::draw_horizontal_segment State::draw_horizontal_segment
} else {
State::draw_horizontal_segment_no_color
}, },
display_messages: SmallVec::new(), display_messages: SmallVec::new(),
display_messages_expiration_start: None, display_messages_expiration_start: None,