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
unsigned lines_count; ///< How many lines we have
unsigned unseen_messages_count; ///< # messages since last visited
unsigned unseen_unimportant_count; ///< How much of that is unimportant
unsigned new_messages_count; ///< # messages since last left
unsigned new_unimportant_count; ///< How much of that is unimportant
bool highlighted; ///< We've been highlighted
FILE *log_file; ///< Log file
@ -3689,7 +3689,7 @@ buffer_line_display (struct app_context *ctx,
static void
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;
formatter_init (&f, ctx, NULL);
@ -3703,8 +3703,7 @@ buffer_line_write_to_backlog (struct app_context *ctx,
else
formatter_add (&f, "#a#s#r ", ATTR_TIMESTAMP, buf);
buffer_line_flush (line, &f, log_file, !get_config_boolean
(ctx->config.root, "behaviour.backlog_helper_strip_formatting"));
buffer_line_flush (line, &f, log_file, raw_attributes);
}
static void
@ -3774,15 +3773,15 @@ log_formatter (struct app_context *ctx,
else
displayed = false;
if (!displayed)
if (!displayed || buffer == ctx->current_buffer)
{
buffer->unseen_messages_count++;
buffer->new_messages_count++;
if (flags & BUFFER_LINE_UNIMPORTANT)
buffer->unseen_unimportant_count++;
buffer->new_unimportant_count++;
buffer->highlighted |= important;
refresh_prompt (ctx);
}
if (!displayed)
refresh_prompt (ctx);
}
static void
@ -3974,14 +3973,14 @@ buffer_remove (struct app_context *ctx, struct buffer *buffer)
}
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;
formatter_init (&f, ctx, NULL);
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
fflush (stdout);
fflush (stream);
formatter_free (&f);
}
@ -4023,18 +4022,15 @@ buffer_print_backlog (struct app_context *ctx, struct buffer *buffer)
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;
int until_marker = to_display - (int) buffer->new_messages_count;
for (; line; line = line->next)
{
if (until_marker-- == 0)
buffer_print_read_marker (ctx);
if (until_marker-- == 0
&& buffer->new_messages_count != buffer->lines_count)
buffer_print_read_marker (ctx, stdout, 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
buffer_update_time (ctx, time (NULL));
@ -4047,6 +4043,12 @@ buffer_activate (struct app_context *ctx, struct buffer *buffer)
{
if (ctx->current_buffer == buffer)
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);
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)
{
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;
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));
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;
line; line = line->next)
buffer_line_write_to_backlog (ctx, line, backlog);
struct buffer *buffer = ctx->current_buffer;
int until_marker =
(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);
set_cloexec (fileno (backlog));
@ -12025,15 +12037,16 @@ on_goto_highlight (int count, int key, void *user_data)
(void) key;
struct app_context *ctx = user_data;
struct buffer *new_buffer = ctx->current_buffer;
while (!new_buffer->highlighted)
struct buffer *iter = ctx->current_buffer;;
do
{
if (!(new_buffer = new_buffer->next))
new_buffer = ctx->buffers;
if (new_buffer == ctx->current_buffer)
if (!(iter = iter->next))
iter = ctx->buffers;
if (iter == ctx->current_buffer)
return false;
}
buffer_activate (ctx, new_buffer);
while (!iter->highlighted);
buffer_activate (ctx, iter);
return true;
}
@ -12044,16 +12057,16 @@ on_goto_activity (int count, int key, void *user_data)
(void) key;
struct app_context *ctx = user_data;
struct buffer *new_buffer = ctx->current_buffer;
while (new_buffer->unseen_messages_count
== new_buffer->unseen_unimportant_count)
struct buffer *iter = ctx->current_buffer;
do
{
if (!(new_buffer = new_buffer->next))
new_buffer = ctx->buffers;
if (new_buffer == ctx->current_buffer)
if (!(iter = iter->next))
iter = ctx->buffers;
if (iter == ctx->current_buffer)
return false;
}
buffer_activate (ctx, new_buffer);
while (iter->new_messages_count == iter->new_unimportant_count);
buffer_activate (ctx, iter);
return true;
}