aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2015-07-11 05:39:00 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2015-07-11 05:41:39 +0200
commitccc167d12039f8d09b548dd81251a0df6025a075 (patch)
tree322d0bb6de5ce1e2b4d93fe902d82bcf70e09de6
parentd48adf4557cf9c8f392977de7929c329d2d136f3 (diff)
downloadxK-ccc167d12039f8d09b548dd81251a0df6025a075.tar.gz
xK-ccc167d12039f8d09b548dd81251a0df6025a075.tar.xz
xK-ccc167d12039f8d09b548dd81251a0df6025a075.zip
degesch: print a marker for unread messages
-rw-r--r--degesch.c69
1 files changed, 45 insertions, 24 deletions
diff --git a/degesch.c b/degesch.c
index a3da97d..9078473 100644
--- a/degesch.c
+++ b/degesch.c
@@ -20,17 +20,18 @@
// A table of all attributes we use for output
// FIXME: awful naming, collides with ATTRIBUTE_*
#define ATTR_TABLE(XX) \
- XX( PROMPT, "prompt", "Terminal attributes for the prompt" ) \
- XX( RESET, "reset", "String to reset terminal attributes" ) \
- XX( WARNING, "warning", "Terminal attributes for warnings" ) \
- XX( ERROR, "error", "Terminal attributes for errors" ) \
- XX( EXTERNAL, "external", "Terminal attributes for external lines" ) \
- XX( TIMESTAMP, "timestamp", "Terminal attributes for timestamps" ) \
- XX( HIGHLIGHT, "highlight", "Terminal attributes for highlights" ) \
- XX( ACTION, "action", "Terminal attributes for user actions" ) \
- XX( USERHOST, "userhost", "Terminal attributes for user@host" ) \
- XX( JOIN, "join", "Terminal attributes for joins" ) \
- XX( PART, "part", "Terminal attributes for parts" )
+ XX( PROMPT, "prompt", "Terminal attrs for the prompt" ) \
+ XX( RESET, "reset", "String to reset terminal attributes" ) \
+ XX( READ_MARKER, "read_marker", "Terminal attrs for the read marker" ) \
+ XX( WARNING, "warning", "Terminal attrs for warnings" ) \
+ XX( ERROR, "error", "Terminal attrs for errors" ) \
+ XX( EXTERNAL, "external", "Terminal attrs for external lines" ) \
+ XX( TIMESTAMP, "timestamp", "Terminal attrs for timestamps" ) \
+ XX( HIGHLIGHT, "highlight", "Terminal attrs for highlights" ) \
+ XX( ACTION, "action", "Terminal attrs for user actions" ) \
+ XX( USERHOST, "userhost", "Terminal attrs for user@host" ) \
+ XX( JOIN, "join", "Terminal attrs for joins" ) \
+ XX( PART, "part", "Terminal attrs for parts" )
enum
{
@@ -1943,17 +1944,18 @@ init_colors (struct app_context *ctx)
#define INIT_ATTR(id, ti) defaults[ATTR_ ## id] = xstrdup (have_ti ? (ti) : "")
- INIT_ATTR (PROMPT, enter_bold_mode);
- INIT_ATTR (RESET, exit_attribute_mode);
- INIT_ATTR (WARNING, g_terminal.color_set_fg[COLOR_YELLOW]);
- INIT_ATTR (ERROR, g_terminal.color_set_fg[COLOR_RED]);
+ INIT_ATTR (PROMPT, enter_bold_mode);
+ INIT_ATTR (RESET, exit_attribute_mode);
+ INIT_ATTR (READ_MARKER, g_terminal.color_set_fg[COLOR_MAGENTA]);
+ INIT_ATTR (WARNING, g_terminal.color_set_fg[COLOR_YELLOW]);
+ INIT_ATTR (ERROR, g_terminal.color_set_fg[COLOR_RED]);
- INIT_ATTR (EXTERNAL, g_terminal.color_set_fg[COLOR_WHITE]);
- INIT_ATTR (TIMESTAMP, g_terminal.color_set_fg[COLOR_WHITE]);
- INIT_ATTR (ACTION, g_terminal.color_set_fg[COLOR_RED]);
- INIT_ATTR (USERHOST, g_terminal.color_set_fg[COLOR_CYAN]);
- INIT_ATTR (JOIN, g_terminal.color_set_fg[COLOR_GREEN]);
- INIT_ATTR (PART, g_terminal.color_set_fg[COLOR_RED]);
+ INIT_ATTR (EXTERNAL, g_terminal.color_set_fg[COLOR_WHITE]);
+ INIT_ATTR (TIMESTAMP, g_terminal.color_set_fg[COLOR_WHITE]);
+ INIT_ATTR (ACTION, g_terminal.color_set_fg[COLOR_RED]);
+ INIT_ATTR (USERHOST, g_terminal.color_set_fg[COLOR_CYAN]);
+ INIT_ATTR (JOIN, g_terminal.color_set_fg[COLOR_GREEN]);
+ INIT_ATTR (PART, g_terminal.color_set_fg[COLOR_RED]);
char *highlight = xstrdup_printf ("%s%s%s",
g_terminal.color_set_fg[COLOR_YELLOW],
@@ -2928,6 +2930,16 @@ buffer_remove (struct app_context *ctx, struct buffer *buffer)
}
static void
+buffer_print_read_marker (struct app_context *ctx)
+{
+ struct formatter f;
+ formatter_init (&f, ctx, NULL);
+ formatter_add (&f, "#a-- -- -- ---\n", ATTR_READ_MARKER);
+ formatter_flush (&f, stdout);
+ formatter_free (&f);
+}
+
+static void
buffer_print_backlog (struct app_context *ctx, struct buffer *buffer)
{
// The prompt can take considerable time to redraw
@@ -2935,14 +2947,23 @@ buffer_print_backlog (struct app_context *ctx, struct buffer *buffer)
print_status ("%s", buffer->name);
// That is, minus the buffer switch line and the readline prompt
- int to_display = MAX (10, g_terminal.lines - 2);
+ int display_limit =
+ MAX (MAX (10, buffer->unseen_messages_count), g_terminal.lines - 2);
+
struct buffer_line *line = buffer->lines_tail;
- while (line && line->prev && --to_display > 0)
- line = line->prev;
+ int to_display = line != NULL;
+ for (; line && line->prev && --display_limit > 0; line = line->prev)
+ to_display++;
// Once we've found where we want to start with the backlog, print it
+ int until_marker = to_display - (int) buffer->unseen_messages_count;
for (; line; line = line->next)
+ {
+ if (until_marker-- == 0)
+ buffer_print_read_marker (ctx);
buffer_line_display (ctx, line, false);
+ }
+
buffer->unseen_messages_count = 0;
buffer->highlighted = false;