ui: add attribute support

bold/italic etc
embed
Manos Pitsidianakis 2019-08-18 15:44:40 +03:00
parent 2610e9c055
commit 1845b046fa
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
14 changed files with 109 additions and 9 deletions

View File

@ -76,6 +76,7 @@ impl ContactManager {
&mut self.content,
Color::Byte(250),
Color::Default,
Attr::Default,
((0, 0), (width, 0)),
false,
);
@ -84,6 +85,7 @@ impl ContactManager {
&mut self.content,
Color::Byte(250),
Color::Default,
Attr::Default,
((x, 0), (width, 0)),
false,
);

View File

@ -91,6 +91,7 @@ impl ContactList {
&mut self.content,
Color::Black,
Color::White,
Attr::Default,
((0, 0), (MAX_COLS - 1, self.length)),
false,
);
@ -102,6 +103,7 @@ impl ContactList {
&mut self.content,
Color::Black,
Color::White,
Attr::Default,
((maxima.0, 0), (MAX_COLS - 1, self.length)),
false,
);
@ -113,6 +115,7 @@ impl ContactList {
&mut self.content,
Color::Black,
Color::White,
Attr::Default,
((maxima.1, 0), (MAX_COLS - 1, self.length)),
false,
);
@ -127,6 +130,7 @@ impl ContactList {
&mut self.content,
Color::Default,
Color::Default,
Attr::Default,
((0, i + 1), (MAX_COLS - 1, self.length)),
false,
);
@ -135,6 +139,7 @@ impl ContactList {
&mut self.content,
Color::Default,
Color::Default,
Attr::Default,
((maxima.0, i + 1), (MAX_COLS - 1, self.length)),
false,
);
@ -143,6 +148,7 @@ impl ContactList {
&mut self.content,
Color::Default,
Color::Default,
Attr::Default,
((maxima.1, i + 1), (MAX_COLS - 1, self.length)),
false,
);

View File

@ -110,6 +110,7 @@ impl AccountsPanel {
&mut self.content,
Color::Default,
Color::Default,
Attr::Default,
((2, 3), (120 - 1, 3)),
true,
);
@ -124,6 +125,7 @@ impl AccountsPanel {
&mut self.content,
Color::Default,
Color::Default,
Attr::Bold,
((3, 5 + i * 10), (120 - 2, 5 + i * 10)),
true,
);
@ -132,6 +134,7 @@ impl AccountsPanel {
&mut self.content,
Color::Byte(32),
Color::Default,
Attr::Default,
((x, y), (120 - 2, 5 + i * 10)),
true,
);
@ -140,6 +143,7 @@ impl AccountsPanel {
&mut self.content,
Color::Default,
Color::Default,
Attr::Default,
((4, y + 2), (120 - 2, y + 2)),
true,
);
@ -157,6 +161,7 @@ impl AccountsPanel {
&mut self.content,
Color::Default,
Color::Default,
Attr::Default,
((5, y + 3), (120 - 2, y + 3)),
true,
);
@ -172,6 +177,7 @@ impl AccountsPanel {
&mut self.content,
Color::Default,
Color::Default,
Attr::Default,
((10 + x, y + 3), (120 - 2, y + 3)),
true,
);
@ -180,6 +186,7 @@ impl AccountsPanel {
&mut self.content,
Color::Default,
Color::Default,
Attr::Default,
((5, y + 4), (120 - 2, y + 4)),
true,
);
@ -188,6 +195,7 @@ impl AccountsPanel {
&mut self.content,
Color::Default,
Color::Default,
Attr::Default,
((5, y + 5), (120 - 2, y + 5)),
true,
);

View File

@ -225,6 +225,7 @@ impl Composer {
grid,
Color::Default,
Color::Default,
Attr::Default,
(pos_inc(upper_left!(area), (0, 1)), bottom_right!(area)),
false,
);
@ -234,6 +235,7 @@ impl Composer {
grid,
Color::Default,
Color::Default,
Attr::Default,
(pos_inc(upper_left!(area), (0, 1)), bottom_right!(area)),
false,
);
@ -250,6 +252,7 @@ impl Composer {
grid,
Color::Default,
Color::Default,
Attr::Default,
(pos_inc(upper_left!(area), (0, 2 + i)), bottom_right!(area)),
false,
);
@ -259,6 +262,7 @@ impl Composer {
grid,
Color::Default,
Color::Default,
Attr::Default,
(pos_inc(upper_left!(area), (0, 2 + i)), bottom_right!(area)),
false,
);
@ -388,6 +392,7 @@ impl Component for Composer {
grid,
Color::Byte(189),
Color::Byte(167),
Attr::Default,
(
pos_dec(upper_left!(header_area), (0, 1)),
bottom_right!(header_area),
@ -437,6 +442,7 @@ impl Component for Composer {
grid,
Color::Default,
Color::Default,
Attr::Default,
area,
true,
);
@ -445,6 +451,7 @@ impl Component for Composer {
grid,
Color::Byte(124),
Color::Default,
Attr::Default,
(set_y(upper_left!(area), y + 2), bottom_right!(area)),
true,
);
@ -453,6 +460,7 @@ impl Component for Composer {
grid,
Color::Byte(124),
Color::Default,
Attr::Default,
(set_y(upper_left!(area), y + 1), bottom_right!(area)),
true,
);
@ -461,6 +469,7 @@ impl Component for Composer {
grid,
Color::Byte(124),
Color::Default,
Attr::Default,
(set_y(upper_left!(area), y + 1), bottom_right!(area)),
true,
);

View File

@ -432,6 +432,7 @@ impl ListingTrait for CompactListing {
&mut self.data_columns.columns[0],
Color::Default,
Color::Default,
Attr::Default,
((0, 0), (MAX_COLS - 1, 0)),
false,
);
@ -556,6 +557,7 @@ impl CompactListing {
&mut self.data_columns.columns[0],
Color::Default,
Color::Default,
Attr::Default,
((0, 0), (MAX_COLS - 1, 0)),
false,
);
@ -681,6 +683,7 @@ impl CompactListing {
&mut self.data_columns.columns[0],
fg_color,
bg_color,
Attr::Default,
((0, idx), (min_width.0, idx)),
false,
);
@ -692,6 +695,7 @@ impl CompactListing {
&mut self.data_columns.columns[1],
fg_color,
bg_color,
Attr::Default,
((0, idx), (min_width.1, idx)),
false,
);
@ -703,6 +707,7 @@ impl CompactListing {
&mut self.data_columns.columns[2],
fg_color,
bg_color,
Attr::Default,
((0, idx), (min_width.2, idx)),
false,
);
@ -714,6 +719,7 @@ impl CompactListing {
&mut self.data_columns.columns[3],
fg_color,
bg_color,
Attr::Default,
((0, idx), (min_width.3, idx)),
false,
);
@ -725,6 +731,7 @@ impl CompactListing {
&mut self.data_columns.columns[4],
fg_color,
bg_color,
Attr::Default,
((0, idx), (min_width.4, idx)),
false,
);
@ -759,6 +766,7 @@ impl CompactListing {
&mut self.data_columns.columns[0],
Color::Default,
Color::Default,
Attr::Default,
((0, 0), (MAX_COLS - 1, 0)),
false,
);
@ -852,6 +860,7 @@ impl CompactListing {
&mut self.data_columns.columns[0],
fg_color,
bg_color,
Attr::Default,
((0, idx), (min_width.0, idx)),
false,
);
@ -863,6 +872,7 @@ impl CompactListing {
&mut self.data_columns.columns[1],
fg_color,
bg_color,
Attr::Default,
((0, idx), (min_width.1, idx)),
false,
);
@ -874,6 +884,7 @@ impl CompactListing {
&mut self.data_columns.columns[2],
fg_color,
bg_color,
Attr::Default,
((0, idx), (min_width.2, idx)),
false,
);
@ -885,6 +896,7 @@ impl CompactListing {
&mut self.data_columns.columns[3],
fg_color,
bg_color,
Attr::Default,
((0, idx), (min_width.3, idx)),
false,
);
@ -896,6 +908,7 @@ impl CompactListing {
&mut self.data_columns.columns[4],
fg_color,
bg_color,
Attr::Default,
((0, idx), (min_width.4, idx)),
false,
);
@ -958,6 +971,7 @@ impl Component for CompactListing {
grid,
Color::Default,
Color::Default,
Attr::Default,
area,
true,
);

View File

@ -280,6 +280,7 @@ impl PlainListing {
&mut self.content,
Color::Default,
Color::Default,
Attr::Default,
((0, 0), (MAX_COLS - 1, 0)),
false,
);
@ -297,6 +298,7 @@ impl PlainListing {
&mut self.content,
Color::Default,
Color::Default,
Attr::Default,
((0, 0), (MAX_COLS - 1, 0)),
true,
);
@ -379,6 +381,7 @@ impl PlainListing {
&mut self.content,
fg_color,
bg_color,
Attr::Default,
((0, idx), (widths.0, idx)),
false,
);
@ -391,6 +394,7 @@ impl PlainListing {
&mut self.content,
fg_color,
bg_color,
Attr::Default,
((_x, idx), (widths.1 + _x, idx)),
false,
);
@ -403,6 +407,7 @@ impl PlainListing {
&mut self.content,
fg_color,
bg_color,
Attr::Default,
((_x, idx), (widths.1 + _x, idx)),
false,
);
@ -415,6 +420,7 @@ impl PlainListing {
&mut self.content,
fg_color,
bg_color,
Attr::Default,
((_x, idx), (widths.2 + _x, idx)),
false,
);

View File

@ -259,6 +259,7 @@ impl ThreadListing {
&mut self.content,
Color::Default,
Color::Default,
Attr::Default,
((0, 0), (MAX_COLS - 1, 0)),
false,
);
@ -278,6 +279,7 @@ impl ThreadListing {
&mut self.content,
Color::Default,
Color::Default,
Attr::Default,
((0, 0), (MAX_COLS - 1, 0)),
true,
);
@ -326,6 +328,7 @@ impl ThreadListing {
&mut self.content,
fg_color,
bg_color,
Attr::Default,
((0, idx), (MAX_COLS - 1, idx)),
false,
);

View File

@ -318,6 +318,7 @@ impl Component for MailView {
grid,
Color::Byte(33),
Color::Default,
Attr::Default,
area,
true,
);
@ -331,6 +332,7 @@ impl Component for MailView {
grid,
Color::Byte(33),
Color::Default,
Attr::Default,
(set_y(upper_left, y + 1), bottom_right),
true,
);
@ -344,6 +346,7 @@ impl Component for MailView {
grid,
Color::Byte(33),
Color::Default,
Attr::Default,
(set_y(upper_left, y + 1), bottom_right),
true,
);
@ -357,6 +360,7 @@ impl Component for MailView {
grid,
Color::Byte(33),
Color::Default,
Attr::Default,
(set_y(upper_left, y + 1), bottom_right),
true,
);
@ -370,6 +374,7 @@ impl Component for MailView {
grid,
Color::Byte(33),
Color::Default,
Attr::Default,
(set_y(upper_left, y + 1), bottom_right),
true,
);
@ -384,6 +389,7 @@ impl Component for MailView {
grid,
Color::Byte(33),
Color::Default,
Attr::Default,
(set_y(upper_left, y + 1), bottom_right),
true,
);
@ -405,6 +411,7 @@ impl Component for MailView {
grid,
Color::Byte(33),
Color::Default,
Attr::Default,
(set_y(upper_left, _y + 1), bottom_right),
true,
);
@ -430,6 +437,7 @@ impl Component for MailView {
grid,
Color::Byte(33),
Color::Default,
Attr::Default,
(set_y(upper_left, y), bottom_right),
false,
);
@ -438,6 +446,7 @@ impl Component for MailView {
grid,
Color::Default,
Color::Default,
Attr::Default,
((_x, y), bottom_right),
false,
);
@ -449,6 +458,7 @@ impl Component for MailView {
grid,
Color::Byte(33),
Color::Default,
Attr::Default,
((x, y), bottom_right),
false,
);
@ -460,6 +470,7 @@ impl Component for MailView {
grid,
Color::Default,
Color::Default,
Attr::Default,
((x, y), bottom_right),
false,
);
@ -471,6 +482,7 @@ impl Component for MailView {
grid,
Color::Default,
Color::Default,
Attr::Default,
((x, y), bottom_right),
false,
);
@ -482,6 +494,7 @@ impl Component for MailView {
grid,
Color::Default,
Color::Default,
Attr::Default,
((x, y), bottom_right),
false,
);

View File

@ -240,6 +240,7 @@ impl Component for EnvelopeView {
grid,
Color::Byte(33),
Color::Default,
Attr::Default,
area,
true,
);
@ -253,6 +254,7 @@ impl Component for EnvelopeView {
grid,
Color::Byte(33),
Color::Default,
Attr::Default,
(set_y(upper_left, y + 1), bottom_right),
true,
);
@ -266,6 +268,7 @@ impl Component for EnvelopeView {
grid,
Color::Byte(33),
Color::Default,
Attr::Default,
(set_y(upper_left, y + 1), bottom_right),
true,
);
@ -279,6 +282,7 @@ impl Component for EnvelopeView {
grid,
Color::Byte(33),
Color::Default,
Attr::Default,
(set_y(upper_left, y + 1), bottom_right),
true,
);
@ -292,6 +296,7 @@ impl Component for EnvelopeView {
grid,
Color::Byte(33),
Color::Default,
Attr::Default,
(set_y(upper_left, y + 1), bottom_right),
true,
);

View File

@ -257,6 +257,7 @@ impl ThreadView {
} else {
Color::Byte(251)
},
Attr::Default,
(
(e.index.0 * 4 + 1, 2 * y),
(e.index.0 * 4 + e.heading.grapheme_width() + 1, height - 1),
@ -333,6 +334,7 @@ impl ThreadView {
} else {
Color::Byte(251)
},
Attr::Default,
(
(e.index.0 * 4 + 1, 2 * y),
(e.index.0 * 4 + e.heading.grapheme_width() + 1, height - 1),
@ -626,6 +628,7 @@ impl ThreadView {
grid,
Color::Byte(33),
Color::Default,
Attr::Default,
area,
true,
);
@ -711,6 +714,7 @@ impl ThreadView {
grid,
Color::Byte(33),
Color::Default,
Attr::Default,
area,
true,
);

View File

@ -420,6 +420,7 @@ impl Pager {
content,
Color::Default,
Color::Default,
Attr::Default,
((0, i), (width - 1, i)),
true,
);
@ -646,15 +647,21 @@ impl StatusBar {
grid,
Color::Byte(123),
Color::Byte(26),
Attr::Default,
area,
false,
);
let offset = self.status.find('|').unwrap_or_else(|| self.status.len());
for x in get_x(upper_left!(area))..get_x(upper_left!(area)) + offset {
grid[(x, y)].set_attrs(Attr::Bold);
}
if let Some(n) = self.notifications.pop_front() {
write_string_to_grid(
&n,
grid,
Color::Byte(219),
Color::Byte(88),
Attr::Default,
(
(std::cmp::max(x, width!(area).saturating_sub(n.len())), y),
bottom_right!(area),
@ -676,14 +683,16 @@ impl StatusBar {
}
fn draw_execute_bar(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) {
clear_area(grid, area);
write_string_to_grid(
let (x, y) = write_string_to_grid(
self.ex_buffer.as_str(),
grid,
Color::Byte(219),
Color::Byte(88),
Attr::Default,
area,
false,
);
grid[(x, y)].set_attrs(Attr::Underline);
change_colors(grid, area, Color::Byte(219), Color::Byte(88));
context.dirty_areas.push_back(area);
}
@ -852,6 +861,7 @@ impl Component for StatusBar {
grid,
Color::Byte(88), // DarkRed,
Color::Byte(174), //LightPink3
Attr::Default,
(
set_y(
upper_left!(hist_area),
@ -866,6 +876,7 @@ impl Component for StatusBar {
grid,
Color::White,
Color::Byte(174),
Attr::Default,
((x + 2, y), bottom_right!(hist_area)),
false,
);
@ -890,6 +901,7 @@ impl Component for StatusBar {
grid,
Color::Byte(97), // MediumPurple3,
Color::Byte(88), //LightPink3
Attr::Default,
(
(
get_y(upper_left)
@ -1144,6 +1156,7 @@ impl Tabbed {
grid,
fg,
bg,
Attr::Default,
(set_x(upper_left, x), bottom_right!(area)),
false,
);
@ -1241,6 +1254,7 @@ impl Component for Tabbed {
grid,
Color::Default,
Color::Default,
Attr::Default,
(
pos_inc(upper_left!(area), (2, 1 + idx)),
set_x(
@ -1259,6 +1273,7 @@ impl Component for Tabbed {
grid,
Color::Byte(29),
Color::Default,
Attr::Default,
(
pos_inc(upper_left!(area), (2, 1 + idx)),
set_x(
@ -1273,6 +1288,7 @@ impl Component for Tabbed {
grid,
Color::Default,
Color::Default,
Attr::Default,
(
(x + 2, y),
set_x(
@ -1413,6 +1429,7 @@ impl Component for Selector {
&mut self.content,
Color::Default,
Color::Default,
Attr::Default,
((1, self.cursor), (width, self.cursor)),
false,
);
@ -1422,6 +1439,7 @@ impl Component for Selector {
&mut self.content,
Color::Default,
Color::Default,
Attr::Default,
((1, self.cursor), (width, self.cursor)),
false,
);
@ -1479,6 +1497,7 @@ impl Selector {
&mut content,
Color::Default,
Color::Default,
Attr::Default,
((0, i), (width - 1, i)),
false,
);

View File

@ -111,6 +111,7 @@ impl Component for Field {
grid,
Color::Default,
Color::Default,
Attr::Default,
area,
true,
);
@ -317,6 +318,7 @@ impl Component for FormWidget {
grid,
Color::Default,
Color::Default,
Attr::Default,
(
pos_inc(upper_left, (1, i)),
set_y(bottom_right, i + get_y(upper_left)),
@ -530,6 +532,7 @@ where
} else {
Color::Default
},
Attr::Default,
(
pos_inc(upper_left, (len, 0)),
pos_inc(upper_left, (cur_len + len, 0)),
@ -712,6 +715,7 @@ impl AutoComplete {
&mut content,
Color::Byte(23),
Color::Byte(7),
Attr::Default,
((0, i), (width - 1, i)),
false,
);
@ -720,6 +724,7 @@ impl AutoComplete {
&mut content,
Color::Byte(23),
Color::Byte(7),
Attr::Default,
((x + 2, i), (width - 1, i)),
false,
);
@ -728,6 +733,7 @@ impl AutoComplete {
&mut content,
Color::Byte(23),
Color::Byte(7),
Attr::Default,
((width - 1, i), (width - 1, i)),
false,
);

View File

@ -421,6 +421,9 @@ impl State {
if c.fg() != Color::Default {
write!(self.stdout(), "{}", termion::color::Fg(c.fg().as_termion())).unwrap();
}
if c.attrs() != Attr::Default {
write!(self.stdout(), "\x1B[{}m", c.attrs() as u8).unwrap();
}
if !c.empty() {
write!(self.stdout(), "{}", c.ch()).unwrap();
}
@ -441,6 +444,9 @@ impl State {
)
.unwrap();
}
if c.attrs() != Attr::Default {
write!(self.stdout(), "\x1B[{}m", Attr::Default as u8).unwrap();
}
}
}

View File

@ -571,9 +571,9 @@ impl Color {
pub enum Attr {
Default = 0b000,
Bold = 0b001,
Underline = 0b010,
Underline = 0b100,
BoldUnderline = 0b011,
Reverse = 0b100,
Reverse = 0b010,
BoldReverse = 0b101,
UnderlineReverse = 0b110,
BoldReverseUnderline = 0b111,
@ -725,6 +725,7 @@ pub fn write_string_to_grid(
grid: &mut CellBuffer,
fg_color: Color,
bg_color: Color,
attrs: Attr,
area: Area,
line_break: bool,
) -> Pos {
@ -748,19 +749,16 @@ pub fn write_string_to_grid(
if c == '\r' {
continue;
}
grid[(x, y)].set_attrs(attrs);
grid[(x, y)].set_fg(fg_color);
grid[(x, y)].set_bg(bg_color);
if c == '\t' {
grid[(x, y)].set_ch(' ');
grid[(x, y)].set_fg(fg_color);
grid[(x, y)].set_bg(bg_color);
x += 1;
inspect_bounds!(grid, area, x, y, line_break);
grid[(x, y)].set_ch(' ');
grid[(x, y)].set_fg(fg_color);
grid[(x, y)].set_bg(bg_color);
} else {
grid[(x, y)].set_ch(c);
grid[(x, y)].set_fg(fg_color);
grid[(x, y)].set_bg(bg_color);
}
match wcwidth(u32::from(c)) {
@ -796,6 +794,7 @@ pub fn clear_area(grid: &mut CellBuffer, area: Area) {
grid[(x, y)].set_ch(' ');
grid[(x, y)].set_bg(Color::Default);
grid[(x, y)].set_fg(Color::Default);
grid[(x, y)].set_attrs(Attr::Default);
grid[(x, y)].empty = false;
}
}