Browse Source

Respect use_color conf value as well as NO_COLOR

async
Manos Pitsidianakis 3 years ago
parent
commit
14b0ef8f37
Signed by untrusted user: epilys GPG Key ID: 73627C2F690DF710
  1. 5
      src/components/mail/listing.rs
  2. 5
      src/components/mail/listing/compact.rs
  3. 5
      src/components/mail/listing/conversations.rs
  4. 5
      src/components/mail/listing/plain.rs
  5. 5
      src/components/mail/listing/thread.rs
  6. 25
      src/components/utilities.rs
  7. 5
      src/components/utilities/widgets.rs
  8. 12
      src/conf/terminal.rs
  9. 9
      src/state.rs

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

5
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;
}

5
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.

5
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;
}

5
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;
}

25
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<T: PartialEq + Debug + Clone + Sync + Send> Component for Selector<T> {
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<T: PartialEq + Debug + Clone + Sync + Send> Component for Selector<T> {
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<T: PartialEq + Debug + Clone + Sync + Send> Selector<T> {
);
}
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 {

5
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((

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

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

Loading…
Cancel
Save