aboutsummaryrefslogtreecommitdiff
path: root/nncmpp.c
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2016-10-06 07:01:50 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2016-10-06 07:03:51 +0200
commit54936c4bcb8a61054ac03420464e7a45bf75bbd4 (patch)
treee394a2367531ea6d847dd48d61b6280fcab30456 /nncmpp.c
parentca38c1d91a472343de9e949b9d3fdd55a237f0ea (diff)
downloadnncmpp-54936c4bcb8a61054ac03420464e7a45bf75bbd4.tar.gz
nncmpp-54936c4bcb8a61054ac03420464e7a45bf75bbd4.tar.xz
nncmpp-54936c4bcb8a61054ac03420464e7a45bf75bbd4.zip
Further optimize terminal output
By calling addstr() once instead of several addch() calls. As a side effect, it's becoming easier to ditch ncurses altogether.
Diffstat (limited to 'nncmpp.c')
-rw-r--r--nncmpp.c36
1 files changed, 19 insertions, 17 deletions
diff --git a/nncmpp.c b/nncmpp.c
index b42c4d5..38d8602 100644
--- a/nncmpp.c
+++ b/nncmpp.c
@@ -671,12 +671,13 @@ row_buffer_ellipsis (struct row_buffer *self, int target, chtype attrs)
static void
row_buffer_print (uint32_t *ucs4, chtype attrs)
{
- // Cannot afford to convert negative numbers to the unsigned chtype.
- uint8_t *str = (uint8_t *) u32_strconv_to_locale (ucs4);
+ // This assumes that we can reset the attribute set without consequences
+ char *str = u32_strconv_to_locale (ucs4);
if (str)
{
- for (uint8_t *p = str; *p; p++)
- addch (*p | attrs);
+ attrset (attrs);
+ addstr (str);
+ attrset (0);
free (str);
}
}
@@ -1054,26 +1055,29 @@ app_draw_view (void)
if (item_index == tab->item_selected)
row_attrs = APP_ATTR (SELECTION);
- attrset (row_attrs);
- mvwhline (stdscr, g_ctx.header_height + row, 0, ' ', COLS);
-
struct row_buffer buf;
row_buffer_init (&buf);
-
tab->on_item_draw (item_index, &buf, view_width);
- if (item_index == tab->item_selected)
+
+ // Combine attributes used by the handler with the defaults.
+ // Avoiding attrset() because of row_buffer_flush().
+ for (size_t i = 0; i < buf.chars_len; i++)
{
- // Make it so that the selection color always wins
- for (size_t i = 0; i < buf.chars_len; i++)
- buf.chars[i].attrs &= ~(A_COLOR | A_REVERSE);
+ chtype *attrs = &buf.chars[i].attrs;
+ if (item_index == tab->item_selected)
+ *attrs = (*attrs & ~(A_COLOR | A_REVERSE)) | row_attrs;
+ else if ((*attrs & A_COLOR) && (row_attrs & A_COLOR))
+ *attrs |= (row_attrs & ~A_COLOR);
+ else
+ *attrs |= row_attrs;
}
if (buf.total_width > view_width)
row_buffer_ellipsis (&buf, view_width, row_attrs);
+ mvwhline (stdscr, g_ctx.header_height + row, 0, ' ' | row_attrs, COLS);
row_buffer_flush (&buf);
row_buffer_free (&buf);
}
- attrset (0);
if (want_scrollbar)
app_draw_scrollbar ();
@@ -2152,11 +2156,9 @@ app_log_handler (void *user_data, const char *quote, const char *fmt,
}
else
{
- // TODO: remember the position and attributes and restore them
- attrset (A_REVERSE);
+ // TODO: remember the position and restore it
mvwhline (stdscr, LINES - 1, 0, A_REVERSE, COLS);
- app_write_line (message.str, 0);
- attrset (0);
+ app_write_line (message.str, A_REVERSE);
}
str_free (&message);