Recalculate unreadHard on reflow

weechat-hashes
C. McEnroe 2020-09-02 21:29:03 -04:00
parent a46fbea0ec
commit 0968a8ac7c
3 changed files with 16 additions and 5 deletions

View File

@ -186,16 +186,19 @@ int bufferPush(
return flow(&buffer->hard, cols, soft); return flow(&buffer->hard, cols, soft);
} }
void bufferReflow(struct Buffer *buffer, int cols, bool ignore) { int bufferReflow(struct Buffer *buffer, int cols, bool ignore, size_t tail) {
buffer->hard.len = 0; buffer->hard.len = 0;
for (size_t i = 0; i < BufferCap; ++i) { for (size_t i = 0; i < BufferCap; ++i) {
free(buffer->hard.lines[i].str); free(buffer->hard.lines[i].str);
buffer->hard.lines[i].str = NULL; buffer->hard.lines[i].str = NULL;
} }
int flowed = 0;
for (size_t i = 0; i < BufferCap; ++i) { for (size_t i = 0; i < BufferCap; ++i) {
const struct Line *soft = bufferSoft(buffer, i); const struct Line *soft = bufferSoft(buffer, i);
if (!soft) continue; if (!soft) continue;
if (soft->heat < Cold && ignore) continue; if (soft->heat < Cold && ignore) continue;
flow(&buffer->hard, cols, soft); int n = flow(&buffer->hard, cols, soft);
if (i >= BufferCap - tail) flowed += n;
} }
return flowed;
} }

2
chat.h
View File

@ -291,7 +291,7 @@ int bufferPush(
struct Buffer *buffer, int cols, bool ignore, struct Buffer *buffer, int cols, bool ignore,
enum Heat heat, time_t time, const char *str enum Heat heat, time_t time, const char *str
); );
void bufferReflow(struct Buffer *buffer, int cols, bool ignore); int bufferReflow(struct Buffer *buffer, int cols, bool ignore, size_t tail);
enum Edit { enum Edit {
EditHead, EditHead,

12
ui.c
View File

@ -542,6 +542,7 @@ void uiWrite(uint id, enum Heat heat, const time_t *src, const char *str) {
} }
if (window->mark && heat > Cold) { if (window->mark && heat > Cold) {
if (!window->unreadWarm++) { if (!window->unreadWarm++) {
window->unreadSoft++;
lines += bufferPush(window->buffer, COLS, false, Cold, ts, ""); lines += bufferPush(window->buffer, COLS, false, Cold, ts, "");
} }
if (heat > window->heat) window->heat = heat; if (heat > window->heat) window->heat = heat;
@ -576,7 +577,9 @@ static void resize(void) {
wresize(main, MAIN_LINES, COLS); wresize(main, MAIN_LINES, COLS);
for (uint num = 0; num < windows.len; ++num) { for (uint num = 0; num < windows.len; ++num) {
struct Window *window = windows.ptrs[num]; struct Window *window = windows.ptrs[num];
bufferReflow(window->buffer, COLS, window->ignore); window->unreadHard = bufferReflow(
window->buffer, COLS, window->ignore, window->unreadSoft
);
} }
windowUpdate(); windowUpdate();
} }
@ -753,7 +756,9 @@ void uiCloseNum(uint num) {
static void toggleIgnore(struct Window *window) { static void toggleIgnore(struct Window *window) {
window->ignore ^= true; window->ignore ^= true;
bufferReflow(window->buffer, COLS, window->ignore); window->unreadHard = bufferReflow(
window->buffer, COLS, window->ignore, window->unreadSoft
);
windowUpdate(); windowUpdate();
statusUpdate(); statusUpdate();
} }
@ -1015,6 +1020,9 @@ void uiLoad(const char *name) {
readString(file, &buf, &cap); readString(file, &buf, &cap);
bufferPush(window->buffer, COLS, window->ignore, heat, time, buf); bufferPush(window->buffer, COLS, window->ignore, heat, time, buf);
} }
window->unreadHard = bufferReflow(
window->buffer, COLS, window->ignore, window->unreadSoft
);
} }
free(buf); free(buf);