Hide ignored messages at the soft -> hard buffer layer

This restores normal scrolling behaviour.
weechat-hashes
C. McEnroe 2020-09-02 18:51:07 -04:00
parent e229931253
commit 96386adac3
3 changed files with 20 additions and 19 deletions

View File

@ -174,7 +174,7 @@ static int flow(struct Lines *hard, int cols, const struct Line *soft) {
} }
int bufferPush( int bufferPush(
struct Buffer *buffer, int cols, 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
) { ) {
struct Line *soft = linesNext(&buffer->soft); struct Line *soft = linesNext(&buffer->soft);
@ -182,10 +182,11 @@ int bufferPush(
soft->time = time; soft->time = time;
soft->str = strdup(str); soft->str = strdup(str);
if (!soft->str) err(EX_OSERR, "strdup"); if (!soft->str) err(EX_OSERR, "strdup");
if (heat < Cold && ignore) return 0;
return flow(&buffer->hard, cols, soft); return flow(&buffer->hard, cols, soft);
} }
void bufferReflow(struct Buffer *buffer, int cols) { void bufferReflow(struct Buffer *buffer, int cols, bool ignore) {
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);
@ -193,6 +194,8 @@ void bufferReflow(struct Buffer *buffer, int cols) {
} }
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) flow(&buffer->hard, cols, soft); if (!soft) continue;
if (soft->heat < Cold && ignore) continue;
flow(&buffer->hard, cols, soft);
} }
} }

4
chat.h
View File

@ -288,10 +288,10 @@ void bufferFree(struct Buffer *buffer);
const struct Line *bufferSoft(const struct Buffer *buffer, size_t i); const struct Line *bufferSoft(const struct Buffer *buffer, size_t i);
const struct Line *bufferHard(const struct Buffer *buffer, size_t i); const struct Line *bufferHard(const struct Buffer *buffer, size_t i);
int bufferPush( int bufferPush(
struct Buffer *buffer, int cols, 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); void bufferReflow(struct Buffer *buffer, int cols, bool ignore);
enum Edit { enum Edit {
EditHead, EditHead,

26
ui.c
View File

@ -462,8 +462,7 @@ static void windowUpdate(void) {
size_t bottom = BufferCap - 1 - window->scroll + !!window->scroll; size_t bottom = BufferCap - 1 - window->scroll + !!window->scroll;
for (size_t i = bottom; i < BufferCap; --i) { for (size_t i = bottom; i < BufferCap; --i) {
const struct Line *line = bufferHard(window->buffer, i); const struct Line *line = bufferHard(window->buffer, i);
if (!line) continue; if (!line) break;
if (line->heat < Cold && window->ignore) continue;
mainAdd(y, line->str); mainAdd(y, line->str);
if (!y--) break; if (!y--) break;
} }
@ -477,8 +476,7 @@ static void windowUpdate(void) {
y = MAIN_LINES - 1; y = MAIN_LINES - 1;
for (size_t i = BufferCap - 1; i < BufferCap; --i) { for (size_t i = BufferCap - 1; i < BufferCap; --i) {
const struct Line *line = bufferHard(window->buffer, i); const struct Line *line = bufferHard(window->buffer, i);
if (!line) continue; if (!line) break;
if (line->heat < Cold && window->ignore) continue;
mainAdd(y, line->str); mainAdd(y, line->str);
if (--y < MAIN_LINES - SplitLines) break; if (--y < MAIN_LINES - SplitLines) break;
} }
@ -537,21 +535,19 @@ static void notify(uint id, const char *str) {
void uiWrite(uint id, enum Heat heat, const time_t *src, const char *str) { void uiWrite(uint id, enum Heat heat, const time_t *src, const char *str) {
struct Window *window = windows.ptrs[windowFor(id)]; struct Window *window = windows.ptrs[windowFor(id)];
time_t ts = (src ? *src : time(NULL)); time_t ts = (src ? *src : time(NULL));
if (heat < Cold && window->ignore) {
window->unreadHard += bufferPush(window->buffer, COLS, heat, ts, str);
return;
}
int lines = 0; int lines = 0;
if (!window->unreadSoft++) window->unreadHard = 0; if (heat > Ice || !window->ignore) {
if (!window->unreadSoft++) window->unreadHard = 0;
}
if (window->mark && heat > Cold) { if (window->mark && heat > Cold) {
if (!window->unreadWarm++) { if (!window->unreadWarm++) {
lines += bufferPush(window->buffer, COLS, Cold, 0, ""); lines += bufferPush(window->buffer, COLS, false, Cold, 0, "");
} }
if (heat > window->heat) window->heat = heat; if (heat > window->heat) window->heat = heat;
statusUpdate(); statusUpdate();
} }
lines += bufferPush(window->buffer, COLS, heat, ts, str); lines += bufferPush(window->buffer, COLS, window->ignore, heat, ts, str);
window->unreadHard += lines; window->unreadHard += lines;
if (window->scroll) windowScroll(window, lines); if (window->scroll) windowScroll(window, lines);
if (window == windows.ptrs[windows.show]) windowUpdate(); if (window == windows.ptrs[windows.show]) windowUpdate();
@ -579,7 +575,8 @@ static void resize(void) {
wclear(main); wclear(main);
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) {
bufferReflow(windows.ptrs[num]->buffer, COLS); struct Window *window = windows.ptrs[num];
bufferReflow(window->buffer, COLS, window->ignore);
} }
windowUpdate(); windowUpdate();
} }
@ -756,6 +753,7 @@ 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);
windowUpdate(); windowUpdate();
statusUpdate(); statusUpdate();
} }
@ -789,7 +787,7 @@ static void showAuto(void) {
} }
static void insertBlank(struct Window *window) { static void insertBlank(struct Window *window) {
int lines = bufferPush(window->buffer, COLS, Cold, 0, ""); int lines = bufferPush(window->buffer, COLS, false, Cold, 0, "");
window->unreadHard += lines; window->unreadHard += lines;
if (window->scroll) { if (window->scroll) {
windowScroll(window, lines); windowScroll(window, lines);
@ -1015,7 +1013,7 @@ void uiLoad(const char *name) {
if (!time) break; if (!time) break;
enum Heat heat = (version > 2 ? readTime(file) : Cold); enum Heat heat = (version > 2 ? readTime(file) : Cold);
readString(file, &buf, &cap); readString(file, &buf, &cap);
bufferPush(window->buffer, COLS, heat, time, buf); bufferPush(window->buffer, COLS, window->ignore, heat, time, buf);
} }
} }