xC/xP: support hiding unimportant messages at all

This commit is contained in:
Přemysl Eric Janouch 2022-09-10 18:58:55 +02:00
parent 7d5e63be1f
commit 0015d26dc8
Signed by: p
GPG Key ID: A0420B94F92B9493
3 changed files with 13 additions and 4 deletions

View File

@ -63,6 +63,7 @@ struct EventMessage {
void; void;
case BUFFER_UPDATE: case BUFFER_UPDATE:
string buffer_name; string buffer_name;
bool hide_unimportant;
case BUFFER_STATS: case BUFFER_STATS:
string buffer_name; string buffer_name;
// These are cumulative, even for lines flushed out from buffers. // These are cumulative, even for lines flushed out from buffers.

5
xC.c
View File

@ -3068,6 +3068,7 @@ relay_prepare_buffer_update (struct app_context *ctx, struct buffer *buffer)
struct relay_event_data_buffer_update *e = &m->data.buffer_update; struct relay_event_data_buffer_update *e = &m->data.buffer_update;
e->event = RELAY_EVENT_BUFFER_UPDATE; e->event = RELAY_EVENT_BUFFER_UPDATE;
e->buffer_name = str_from_cstr (buffer->name); e->buffer_name = str_from_cstr (buffer->name);
e->hide_unimportant = buffer->hide_unimportant;
} }
static void static void
@ -14202,6 +14203,10 @@ on_toggle_unimportant (int count, int key, void *user_data)
(void) key; (void) key;
struct app_context *ctx = user_data; struct app_context *ctx = user_data;
ctx->current_buffer->hide_unimportant ^= true; ctx->current_buffer->hide_unimportant ^= true;
relay_prepare_buffer_update (ctx, ctx->current_buffer);
relay_broadcast (ctx);
buffer_print_backlog (ctx, ctx->current_buffer); buffer_print_backlog (ctx, ctx->current_buffer);
return true; return true;
} }

View File

@ -171,6 +171,7 @@ rpc.addEventListener('BufferUpdate', event => {
buffers.set(e.bufferName, (b = {lines: []})) buffers.set(e.bufferName, (b = {lines: []}))
resetBufferStats(b) resetBufferStats(b)
} }
b.hideUnimportant = e.hideUnimportant
}) })
rpc.addEventListener('BufferStats', event => { rpc.addEventListener('BufferStats', event => {
@ -465,6 +466,11 @@ let Buffer = {
let markBefore = b.lines.length let markBefore = b.lines.length
- b.newMessages - b.newUnimportantMessages - b.newMessages - b.newUnimportantMessages
b.lines.forEach((line, i) => { b.lines.forEach((line, i) => {
if (i == markBefore)
lines.push(m('.unread'))
if (line.isUnimportant && b.hideUnimportant)
return
let date = new Date(line.when) let date = new Date(line.when)
let dateMark = date.toLocaleDateString() let dateMark = date.toLocaleDateString()
if (dateMark !== lastDateMark) { if (dateMark !== lastDateMark) {
@ -472,14 +478,10 @@ let Buffer = {
lastDateMark = dateMark lastDateMark = dateMark
} }
if (i == markBefore)
lines.push(m('.unread'))
let attrs = {} let attrs = {}
if (line.leaked) if (line.leaked)
attrs.class = 'leaked' attrs.class = 'leaked'
// TODO: Make use of isUnimportant.
lines.push(m('.time', {...attrs}, date.toLocaleTimeString())) lines.push(m('.time', {...attrs}, date.toLocaleTimeString()))
lines.push(m(Content, {...attrs}, line)) lines.push(m(Content, {...attrs}, line))
}) })
@ -604,6 +606,7 @@ let Main = {
return m('.xP', {}, [ return m('.xP', {}, [
m('.title', {}, [`xP (${state})`, m(Toolbar)]), m('.title', {}, [`xP (${state})`, m(Toolbar)]),
m('.middle', {}, [m(BufferList), m(BufferContainer)]), m('.middle', {}, [m(BufferList), m(BufferContainer)]),
// TODO: Indicate hideUnimportant.
m('.status', {}, bufferCurrent), m('.status', {}, bufferCurrent),
m(Input), m(Input),
]) ])