Fix NO_COLOR cursor highlight in sidebar and progress spinner

jmap-eventsource
Manos Pitsidianakis 2020-11-12 03:11:57 +02:00
parent 60350eaa88
commit aaee6d094c
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
3 changed files with 60 additions and 31 deletions

View File

@ -273,28 +273,35 @@ impl ContactList {
let width = width!(area);
let must_highlight_account: bool = self.account_pos == a.index;
let (fg_color, bg_color) = if must_highlight_account {
if self.account_pos == a.index {
(Color::Byte(233), Color::Byte(15))
} else {
(Color::Byte(15), Color::Byte(233))
let account_attrs = if must_highlight_account {
let mut v = crate::conf::value(context, "mail.sidebar_highlighted");
if !context.settings.terminal.use_color() {
v.attrs |= Attr::REVERSE;
}
v
} else {
(self.theme_default.fg, self.theme_default.bg)
crate::conf::value(context, "mail.sidebar_account_name")
};
let s = format!(" [{}]", context.accounts[a.index].address_book.len());
if a.name.grapheme_len() + s.len() > width + 1 {
/* Print account name */
let (x, y) =
write_string_to_grid(&a.name, grid, fg_color, bg_color, Attr::BOLD, area, None);
let (x, y) = write_string_to_grid(
&a.name,
grid,
account_attrs.fg,
account_attrs.bg,
account_attrs.attrs,
area,
None,
);
write_string_to_grid(
&s,
grid,
fg_color,
bg_color,
Attr::BOLD,
account_attrs.fg,
account_attrs.bg,
account_attrs.attrs,
(
pos_dec(
(get_x(bottom_right!(area)), get_y(upper_left!(area))),
@ -307,9 +314,9 @@ impl ContactList {
write_string_to_grid(
"",
grid,
fg_color,
bg_color,
Attr::BOLD,
account_attrs.fg,
account_attrs.bg,
account_attrs.attrs,
(
pos_dec(
(get_x(bottom_right!(area)), get_y(upper_left!(area))),
@ -321,20 +328,29 @@ impl ContactList {
);
for x in x..=get_x(bottom_right!(area)) {
grid[(x, y)].set_fg(fg_color);
grid[(x, y)].set_bg(bg_color);
grid[(x, y)]
.set_fg(account_attrs.fg)
.set_bg(account_attrs.bg)
.set_attrs(account_attrs.attrs);
}
} else {
/* Print account name */
let (x, y) =
write_string_to_grid(&a.name, grid, fg_color, bg_color, Attr::BOLD, area, None);
let (x, y) = write_string_to_grid(
&a.name,
grid,
account_attrs.fg,
account_attrs.bg,
account_attrs.attrs,
area,
None,
);
write_string_to_grid(
&s,
grid,
fg_color,
bg_color,
Attr::BOLD,
account_attrs.fg,
account_attrs.bg,
account_attrs.attrs,
(
pos_dec(
(get_x(bottom_right!(area)), get_y(upper_left!(area))),
@ -345,8 +361,10 @@ impl ContactList {
None,
);
for x in x..=get_x(bottom_right!(area)) {
grid[(x, y)].set_fg(fg_color);
grid[(x, y)].set_bg(bg_color);
grid[(x, y)]
.set_fg(account_attrs.fg)
.set_bg(account_attrs.bg)
.set_attrs(account_attrs.attrs);
}
}
}

View File

@ -1526,13 +1526,18 @@ impl Listing {
let account_attrs = if must_highlight_account {
if self.focus == ListingFocus::Menu && self.menu_cursor_pos.1 == 0 {
crate::conf::value(context, "mail.sidebar_highlighted")
let mut v = crate::conf::value(context, "mail.sidebar_highlighted");
if !context.settings.terminal.use_color() {
v.attrs |= Attr::REVERSE;
}
v
} else {
crate::conf::value(context, "mail.sidebar_highlighted_account_name")
}
} else {
crate::conf::value(context, "mail.sidebar_account_name")
};
/* Print account name first */
write_string_to_grid(
&a.name,
@ -1549,8 +1554,8 @@ impl Listing {
"offline",
grid,
Color::Byte(243),
self.theme_default.bg,
self.theme_default.attrs,
account_attrs.bg,
account_attrs.attrs,
(pos_inc(upper_left, (0, 1)), bottom_right),
None,
);

View File

@ -1158,6 +1158,7 @@ pub struct ProgressSpinner {
stage: usize,
pub kind: std::result::Result<usize, Vec<String>>,
pub width: usize,
theme_attr: ThemeAttribute,
active: bool,
dirty: bool,
id: ComponentId,
@ -1212,11 +1213,17 @@ impl ProgressSpinner {
.map(|f| f.grapheme_len())
.max()
.unwrap_or(0);
let mut theme_attr = crate::conf::value(context, "status.bar");
if !context.settings.terminal.use_color() {
theme_attr.attrs |= Attr::REVERSE;
}
theme_attr.attrs |= Attr::BOLD;
ProgressSpinner {
timer,
stage: 0,
kind: Ok(kind),
width,
theme_attr,
dirty: true,
active: false,
id: ComponentId::new_v4(),
@ -1278,8 +1285,7 @@ impl fmt::Display for ProgressSpinner {
impl Component for ProgressSpinner {
fn draw(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) {
if self.dirty {
let theme_attr = crate::conf::value(context, "status.bar");
clear_area(grid, area, theme_attr);
clear_area(grid, area, self.theme_attr);
if self.active {
write_string_to_grid(
match self.kind.as_ref() {
@ -1287,9 +1293,9 @@ impl Component for ProgressSpinner {
Err(custom) => custom[self.stage].as_ref(),
},
grid,
theme_attr.fg,
theme_attr.bg,
theme_attr.attrs,
self.theme_attr.fg,
self.theme_attr.bg,
self.theme_attr.attrs,
area,
None,
);