Skip to content
Permalink
Browse files
ui/themes: add NO_COLOR support
  • Loading branch information
epilys committed Jan 27, 2020
1 parent ee65f35 commit 6a7cae09882d43c0de8a84df3d66174949ede0e0
Showing 11 changed files with 494 additions and 242 deletions.
4 meli.1
@@ -402,6 +402,10 @@ catchall for general errors
Specifies the editor to use
.It Ev MELI_CONFIG
Override the configuration file
.It Ev NO_COLOR
When present (regardless of its value), prevents the addition of ANSI color. The configuration value
.Ic use_color
overrides this.
.El
.Sh FILES
.Nm
@@ -1050,49 +1050,38 @@ impl Listing {
if idx == lines_len {
break;
}
let (
fg_color,
bg_color,
index_fg_color,
index_bg_color,
unread_count_fg,
unread_count_bg,
) = if must_highlight_account {
let (att, index_att, unread_count_att) = if must_highlight_account {
if self.cursor_pos.1 == idx {
(
crate::conf::value(context, "mail.sidebar_highlighted").fg,
crate::conf::value(context, "mail.sidebar_highlighted").bg,
crate::conf::value(context, "mail.sidebar_highlighted_index").fg,
crate::conf::value(context, "mail.sidebar_highlighted_index").bg,
crate::conf::value(context, "mail.sidebar_highlighted_unread_count").fg,
crate::conf::value(context, "mail.sidebar_highlighted_unread_count").bg,
)
let mut ret = (
crate::conf::value(context, "mail.sidebar_highlighted"),
crate::conf::value(context, "mail.sidebar_highlighted_index"),
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())
{
ret.0.attrs |= Attr::Reverse;
ret.1.attrs |= Attr::Reverse;
ret.2.attrs |= Attr::Reverse;
}
ret
} else {
(
crate::conf::value(context, "mail.sidebar_highlighted_account").fg,
crate::conf::value(context, "mail.sidebar_highlighted_account").bg,
crate::conf::value(context, "mail.sidebar_highlighted_account_index").fg,
crate::conf::value(context, "mail.sidebar_highlighted_account_index").bg,
crate::conf::value(context, "mail.sidebar_highlighted_account"),
crate::conf::value(context, "mail.sidebar_highlighted_account_index"),
crate::conf::value(
context,
"mail.sidebar_highlighted_account_unread_count",
)
.fg,
crate::conf::value(
context,
"mail.sidebar_highlighted_account_unread_count",
)
.bg,
),
)
}
} else {
(
crate::conf::value(context, "mail.sidebar").fg,
crate::conf::value(context, "mail.sidebar").bg,
crate::conf::value(context, "mail.sidebar_index").fg,
crate::conf::value(context, "mail.sidebar_index").bg,
crate::conf::value(context, "mail.sidebar_unread_count").fg,
crate::conf::value(context, "mail.sidebar_unread_count").bg,
crate::conf::value(context, "mail.sidebar"),
crate::conf::value(context, "mail.sidebar_index"),
crate::conf::value(context, "mail.sidebar_unread_count"),
)
};

@@ -1117,27 +1106,27 @@ impl Listing {
let (x, _) = write_string_to_grid(
&format!("{:>width$}", inc, width = total_folder_no_digits),
grid,
index_fg_color,
index_bg_color,
Attr::Default,
index_att.fg,
index_att.bg,
index_att.attrs,
(set_y(upper_left, y), bottom_right),
None,
);
let (x, _) = write_string_to_grid(
&" ".repeat(depth + 1),
grid,
fg_color,
bg_color,
Attr::Default,
att.fg,
att.bg,
att.attrs,
((x, y), bottom_right),
None,
);
let (x, _) = write_string_to_grid(
entries[&folder_idx].name(),
grid,
fg_color,
bg_color,
Attr::Default,
att.fg,
att.bg,
att.attrs,
((x, y), bottom_right),
None,
);
@@ -1156,13 +1145,14 @@ impl Listing {
let (x, _) = write_string_to_grid(
&count_string,
grid,
unread_count_fg,
unread_count_bg,
if count.unwrap_or(0) > 0 {
Attr::Bold
} else {
Attr::Default
},
unread_count_att.fg,
unread_count_att.bg,
unread_count_att.attrs
| if count.unwrap_or(0) > 0 {
Attr::Bold
} else {
Attr::Default
},
(
(
/* Hide part of folder name if need be to fit the message count */
@@ -1173,7 +1163,9 @@ impl Listing {
),
None,
);
change_colors(grid, ((x, y), set_y(bottom_right, y)), fg_color, bg_color);
for c in grid.row_iter(x..(get_x(bottom_right) + 1), y) {
grid[c].set_fg(att.fg).set_bg(att.bg).set_attrs(att.attrs);
}
idx += 1;
}
if idx == 0 {
@@ -146,15 +146,32 @@ impl ListingTrait for CompactListing {
} else {
self.color_cache.odd.bg
};
let attrs = if self.cursor_pos.2 == idx {
self.color_cache.highlighted.attrs
} else if self.selection[&thread_hash] {
self.color_cache.selected.attrs
} else if thread.unseen() > 0 {
self.color_cache.unseen.attrs
} else if idx % 2 == 0 {
self.color_cache.even.attrs
} else {
self.color_cache.odd.attrs
};

let (upper_left, bottom_right) = area;
change_colors(grid, area, fg_color, bg_color);
let x = get_x(upper_left)
+ self.data_columns.widths[0]
+ self.data_columns.widths[1]
+ self.data_columns.widths[2]
+ 3 * 2;

for c in grid.row_iter(
get_x(upper_left)..(get_x(bottom_right) + 1),
get_y(upper_left),
) {
grid[c].set_fg(fg_color).set_bg(bg_color).set_attrs(attrs);
}

copy_area(
grid,
&self.data_columns.columns[3],
@@ -165,7 +182,7 @@ impl ListingTrait for CompactListing {
),
);
for c in grid.row_iter(x..(self.data_columns.widths[3] + x), get_y(upper_left)) {
grid[c].set_bg(bg_color);
grid[c].set_bg(bg_color).set_attrs(attrs);
}
return;
}
@@ -641,6 +658,12 @@ impl CompactListing {
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())
{
self.color_cache.highlighted.attrs |= Attr::Reverse;
}

// Get mailbox as a reference.
//
@@ -119,6 +119,15 @@ impl ListingTrait for ConversationsListing {
} else {
self.color_cache.theme_default.bg
};
let attrs = if self.cursor_pos.2 == idx {
self.color_cache.highlighted.attrs
} else if self.selection[&thread_hash] {
self.color_cache.selected.attrs
} else if thread.unseen() > 0 {
self.color_cache.unseen.attrs
} else {
self.color_cache.theme_default.attrs
};

copy_area(
grid,
@@ -134,26 +143,38 @@ impl ListingTrait for ConversationsListing {
let (x, y) = upper_left;
if self.cursor_pos.2 == idx || self.selection[&thread_hash] {
for x in x..=get_x(bottom_right) {
grid[(x, y)].set_fg(fg_color);
grid[(x, y)].set_bg(bg_color);
grid[(x, y)]
.set_fg(fg_color)
.set_bg(bg_color)
.set_attrs(attrs);

grid[(x, y + 1)].set_fg(fg_color);
grid[(x, y + 1)].set_bg(bg_color);
grid[(x, y + 1)]
.set_fg(fg_color)
.set_bg(bg_color)
.set_attrs(attrs);

grid[(x, y + 2)].set_fg(padding_fg);
grid[(x, y + 2)].set_bg(bg_color);
grid[(x, y + 2)]
.set_fg(padding_fg)
.set_bg(bg_color)
.set_attrs(attrs);
}
} else if width < width!(area) {
/* fill any remaining columns, if our view is wider than self.content */
for x in (x + width)..=get_x(bottom_right) {
grid[(x, y)].set_fg(fg_color);
grid[(x, y)].set_bg(bg_color);
grid[(x, y)]
.set_fg(fg_color)
.set_bg(bg_color)
.set_attrs(attrs);

grid[(x, y + 1)].set_fg(fg_color);
grid[(x, y + 1)].set_bg(bg_color);
grid[(x, y + 1)]
.set_fg(fg_color)
.set_bg(bg_color)
.set_attrs(attrs);

grid[(x, y + 2)].set_fg(padding_fg);
grid[(x, y + 2)].set_bg(bg_color);
grid[(x, y + 2)]
.set_fg(padding_fg)
.set_bg(bg_color)
.set_attrs(attrs);
}
}
return;
@@ -570,6 +591,12 @@ impl 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())
{
self.color_cache.highlighted.attrs |= Attr::Reverse;
}
// Get mailbox as a reference.
//
match context.accounts[self.cursor_pos.0].status(self.folder_hash) {

0 comments on commit 6a7cae0

Please sign in to comment.