degesch: retain the unseen marker

Don't erase the message counts immediately.

Also make the marker visible in the pager.
This commit is contained in:
Přemysl Eric Janouch 2016-03-26 03:09:29 +01:00
parent 410bcdcd78
commit e646afe5ae
1 changed files with 50 additions and 37 deletions

View File

@ -1505,8 +1505,8 @@ struct buffer
struct buffer_line *lines_tail; ///< The tail of buffer lines struct buffer_line *lines_tail; ///< The tail of buffer lines
unsigned lines_count; ///< How many lines we have unsigned lines_count; ///< How many lines we have
unsigned unseen_messages_count; ///< # messages since last visited unsigned new_messages_count; ///< # messages since last left
unsigned unseen_unimportant_count; ///< How much of that is unimportant unsigned new_unimportant_count; ///< How much of that is unimportant
bool highlighted; ///< We've been highlighted bool highlighted; ///< We've been highlighted
FILE *log_file; ///< Log file FILE *log_file; ///< Log file
@ -3689,7 +3689,7 @@ buffer_line_display (struct app_context *ctx,
static void static void
buffer_line_write_to_backlog (struct app_context *ctx, buffer_line_write_to_backlog (struct app_context *ctx,
struct buffer_line *line, FILE *log_file) struct buffer_line *line, FILE *log_file, bool raw_attributes)
{ {
struct formatter f; struct formatter f;
formatter_init (&f, ctx, NULL); formatter_init (&f, ctx, NULL);
@ -3703,8 +3703,7 @@ buffer_line_write_to_backlog (struct app_context *ctx,
else else
formatter_add (&f, "#a#s#r ", ATTR_TIMESTAMP, buf); formatter_add (&f, "#a#s#r ", ATTR_TIMESTAMP, buf);
buffer_line_flush (line, &f, log_file, !get_config_boolean buffer_line_flush (line, &f, log_file, raw_attributes);
(ctx->config.root, "behaviour.backlog_helper_strip_formatting"));
} }
static void static void
@ -3774,15 +3773,15 @@ log_formatter (struct app_context *ctx,
else else
displayed = false; displayed = false;
if (!displayed) if (!displayed || buffer == ctx->current_buffer)
{ {
buffer->unseen_messages_count++; buffer->new_messages_count++;
if (flags & BUFFER_LINE_UNIMPORTANT) if (flags & BUFFER_LINE_UNIMPORTANT)
buffer->unseen_unimportant_count++; buffer->new_unimportant_count++;
buffer->highlighted |= important; buffer->highlighted |= important;
refresh_prompt (ctx);
} }
if (!displayed)
refresh_prompt (ctx);
} }
static void static void
@ -3974,14 +3973,14 @@ buffer_remove (struct app_context *ctx, struct buffer *buffer)
} }
static void static void
buffer_print_read_marker (struct app_context *ctx) buffer_print_read_marker (struct app_context *ctx, FILE *stream, bool raw_attrs)
{ {
struct formatter f; struct formatter f;
formatter_init (&f, ctx, NULL); formatter_init (&f, ctx, NULL);
formatter_add (&f, "#a-- -- -- ---\n", ATTR_READ_MARKER); formatter_add (&f, "#a-- -- -- ---\n", ATTR_READ_MARKER);
formatter_flush (&f, stdout, false); formatter_flush (&f, stream, raw_attrs);
// Flush the trailing formatting reset item // Flush the trailing formatting reset item
fflush (stdout); fflush (stream);
formatter_free (&f); formatter_free (&f);
} }
@ -4023,18 +4022,15 @@ buffer_print_backlog (struct app_context *ctx, struct buffer *buffer)
to_display++; to_display++;
// Once we've found where we want to start with the backlog, print it // Once we've found where we want to start with the backlog, print it
int until_marker = to_display - (int) buffer->unseen_messages_count; int until_marker = to_display - (int) buffer->new_messages_count;
for (; line; line = line->next) for (; line; line = line->next)
{ {
if (until_marker-- == 0) if (until_marker-- == 0
buffer_print_read_marker (ctx); && buffer->new_messages_count != buffer->lines_count)
buffer_print_read_marker (ctx, stdout, false);
buffer_line_display (ctx, line, false); buffer_line_display (ctx, line, false);
} }
buffer->unseen_messages_count = 0;
buffer->unseen_unimportant_count = 0;
buffer->highlighted = false;
// So that it is obvious if the last line in the buffer is not from today // So that it is obvious if the last line in the buffer is not from today
buffer_update_time (ctx, time (NULL)); buffer_update_time (ctx, time (NULL));
@ -4047,6 +4043,12 @@ buffer_activate (struct app_context *ctx, struct buffer *buffer)
{ {
if (ctx->current_buffer == buffer) if (ctx->current_buffer == buffer)
return; return;
if (ctx->current_buffer)
{
ctx->current_buffer->new_messages_count = 0;
ctx->current_buffer->new_unimportant_count = 0;
ctx->current_buffer->highlighted = false;
}
buffer_print_backlog (ctx, buffer); buffer_print_backlog (ctx, buffer);
CALL_ (ctx->input, buffer_switch, buffer->input_data); CALL_ (ctx->input, buffer_switch, buffer->input_data);
@ -5676,7 +5678,8 @@ make_unseen_prefix (struct app_context *ctx, struct str *active_buffers)
LIST_FOR_EACH (struct buffer, iter, ctx->buffers) LIST_FOR_EACH (struct buffer, iter, ctx->buffers)
{ {
buffer_no++; buffer_no++;
if (!(iter->unseen_messages_count - iter->unseen_unimportant_count)) if (!(iter->new_messages_count - iter->new_unimportant_count)
|| iter == ctx->current_buffer)
continue; continue;
if (active_buffers->len) if (active_buffers->len)
@ -11926,10 +11929,19 @@ on_display_backlog (int count, int key, void *user_data)
"Failed to create a temporary file", strerror (errno)); "Failed to create a temporary file", strerror (errno));
return false; return false;
} }
bool raw_attributes = !get_config_boolean
(ctx->config.root, "behaviour.backlog_helper_strip_formatting");
for (struct buffer_line *line = ctx->current_buffer->lines; struct buffer *buffer = ctx->current_buffer;
line; line = line->next) int until_marker =
buffer_line_write_to_backlog (ctx, line, backlog); (int) buffer->lines_count - (int) buffer->new_messages_count;
for (struct buffer_line *line = buffer->lines; line; line = line->next)
{
if (until_marker-- == 0
&& buffer->new_messages_count != buffer->lines_count)
buffer_print_read_marker (ctx, backlog, raw_attributes);
buffer_line_write_to_backlog (ctx, line, backlog, raw_attributes);
}
rewind (backlog); rewind (backlog);
set_cloexec (fileno (backlog)); set_cloexec (fileno (backlog));
@ -12025,15 +12037,16 @@ on_goto_highlight (int count, int key, void *user_data)
(void) key; (void) key;
struct app_context *ctx = user_data; struct app_context *ctx = user_data;
struct buffer *new_buffer = ctx->current_buffer; struct buffer *iter = ctx->current_buffer;;
while (!new_buffer->highlighted) do
{ {
if (!(new_buffer = new_buffer->next)) if (!(iter = iter->next))
new_buffer = ctx->buffers; iter = ctx->buffers;
if (new_buffer == ctx->current_buffer) if (iter == ctx->current_buffer)
return false; return false;
} }
buffer_activate (ctx, new_buffer); while (!iter->highlighted);
buffer_activate (ctx, iter);
return true; return true;
} }
@ -12044,16 +12057,16 @@ on_goto_activity (int count, int key, void *user_data)
(void) key; (void) key;
struct app_context *ctx = user_data; struct app_context *ctx = user_data;
struct buffer *new_buffer = ctx->current_buffer; struct buffer *iter = ctx->current_buffer;
while (new_buffer->unseen_messages_count do
== new_buffer->unseen_unimportant_count)
{ {
if (!(new_buffer = new_buffer->next)) if (!(iter = iter->next))
new_buffer = ctx->buffers; iter = ctx->buffers;
if (new_buffer == ctx->current_buffer) if (iter == ctx->current_buffer)
return false; return false;
} }
buffer_activate (ctx, new_buffer); while (iter->new_messages_count == iter->new_unimportant_count);
buffer_activate (ctx, iter);
return true; return true;
} }