Generalize ignore toggling to visibility threshold

weechat-hashes
C. McEnroe 2021-01-16 12:58:16 -05:00
parent 51c92f94ff
commit d05872303e
4 changed files with 36 additions and 22 deletions

View File

@ -199,7 +199,7 @@ static int flow(struct Lines *hard, int cols, const struct Line *soft) {
}
int bufferPush(
struct Buffer *buffer, int cols, bool ignore,
struct Buffer *buffer, int cols, enum Heat thresh,
enum Heat heat, time_t time, const char *str
) {
struct Line *soft = linesNext(&buffer->soft);
@ -207,11 +207,12 @@ int bufferPush(
soft->time = time;
soft->str = strdup(str);
if (!soft->str) err(EX_OSERR, "strdup");
if (heat < Cold && ignore) return 0;
if (heat < thresh) return 0;
return flow(&buffer->hard, cols, soft);
}
int bufferReflow(struct Buffer *buffer, int cols, bool ignore, size_t tail) {
int
bufferReflow(struct Buffer *buffer, int cols, enum Heat thresh, size_t tail) {
buffer->hard.len = 0;
for (size_t i = 0; i < BufferCap; ++i) {
free(buffer->hard.lines[i].str);
@ -221,7 +222,7 @@ int bufferReflow(struct Buffer *buffer, int cols, bool ignore, size_t tail) {
for (size_t i = 0; i < BufferCap; ++i) {
const struct Line *soft = bufferSoft(buffer, i);
if (!soft) continue;
if (soft->heat < Cold && ignore) continue;
if (soft->heat < thresh) continue;
int n = flow(&buffer->hard, cols, soft);
if (i >= BufferCap - tail) flowed += n;
}

View File

@ -1,4 +1,4 @@
.Dd January 10, 2021
.Dd January 16, 2021
.Dt CATGIRL 1
.Os
.
@ -545,8 +545,14 @@ Scroll to previous line matching input.
Scroll to next line matching input.
.It Ic C-v
Scroll down a page.
.It Ic M-+
Raise message visibility threshold,
hiding ignored messages,
general events,
or non-highlighted messages.
.It Ic M--
Toggle visibility of filtered messages.
Lower message visibility threshold,
showing ignored messages.
.It Ic M-=
Toggle mute.
Muted windows do not appear in the status line

6
chat.h
View File

@ -309,10 +309,12 @@ void bufferFree(struct Buffer *buffer);
const struct Line *bufferSoft(const struct Buffer *buffer, size_t i);
const struct Line *bufferHard(const struct Buffer *buffer, size_t i);
int bufferPush(
struct Buffer *buffer, int cols, bool ignore,
struct Buffer *buffer, int cols, enum Heat thresh,
enum Heat heat, time_t time, const char *str
);
int bufferReflow(struct Buffer *buffer, int cols, bool ignore, size_t tail);
int bufferReflow(
struct Buffer *buffer, int cols, enum Heat thresh, size_t tail
);
enum Edit {
EditHead,

33
ui.c
View File

@ -78,7 +78,7 @@ struct Window {
int scroll;
bool mark;
bool mute;
bool ignore;
enum Heat thresh;
enum Heat heat;
uint unreadSoft;
uint unreadHard;
@ -135,7 +135,7 @@ static uint windowFor(uint id) {
window->id = id;
window->mark = true;
window->ignore = true;
window->thresh = Cold;
window->buffer = bufferAlloc();
return windowPush(window);
@ -204,8 +204,9 @@ static short colorPair(short fg, short bg) {
X(KeyMetaEnter, "\33\r", "\33\n") \
X(KeyMetaGt, "\33>", "\33.") \
X(KeyMetaLt, "\33<", "\33,") \
X(KeyMetaEqual, "\33=", "\33+") \
X(KeyMetaEqual, "\33=", NULL) \
X(KeyMetaMinus, "\33-", "\33_") \
X(KeyMetaPlus, "\33+", NULL) \
X(KeyMetaSlash, "\33/", "\33?") \
X(KeyFocusIn, "\33[I", NULL) \
X(KeyFocusOut, "\33[O", NULL) \
@ -388,8 +389,9 @@ static void statusUpdate(void) {
&cat, "\3%d%s %u ",
idColors[window->id], (num == windows.show ? "\26" : ""), num
);
if (!window->ignore || window->mute) {
catf(&cat, "%s%s ", &"-"[window->ignore], &"="[!window->mute]);
if (window->thresh != Cold || window->mute) {
const char *thresh[] = { "-", "", "+", "++" };
catf(&cat, "%s%s ", thresh[window->thresh], &"="[!window->mute]);
}
catf(&cat, "%s ", idNames[window->id]);
if (window->mark && window->unreadWarm) {
@ -560,7 +562,7 @@ void uiWrite(uint id, enum Heat heat, const time_t *src, const char *str) {
struct Window *window = windows.ptrs[windowFor(id)];
time_t ts = (src ? *src : time(NULL));
if (heat > Ice || !window->ignore) {
if (heat >= window->thresh) {
if (!window->unreadSoft++) window->unreadHard = 0;
}
if (window->mark && heat > Cold) {
@ -575,7 +577,7 @@ void uiWrite(uint id, enum Heat heat, const time_t *src, const char *str) {
if (heat > window->heat) window->heat = heat;
statusUpdate();
}
int lines = bufferPush(window->buffer, COLS, window->ignore, heat, ts, str);
int lines = bufferPush(window->buffer, COLS, window->thresh, heat, ts, str);
window->unreadHard += lines;
if (window->scroll) windowScroll(window, lines);
if (window == windows.ptrs[windows.show]) windowUpdate();
@ -605,7 +607,7 @@ static void resize(void) {
for (uint num = 0; num < windows.len; ++num) {
struct Window *window = windows.ptrs[num];
window->unreadHard = bufferReflow(
window->buffer, COLS, window->ignore, window->unreadSoft
window->buffer, COLS, window->thresh, window->unreadSoft
);
}
windowUpdate();
@ -781,10 +783,12 @@ void uiCloseNum(uint num) {
if (num < windows.len) windowClose(num);
}
static void toggleIgnore(struct Window *window) {
window->ignore ^= true;
static void incThresh(struct Window *window, int n) {
if (n < 0 && window->thresh == Ice) return;
if (n > 0 && window->thresh == Hot) return;
window->thresh += n;
window->unreadHard = bufferReflow(
window->buffer, COLS, window->ignore, window->unreadSoft
window->buffer, COLS, window->thresh, window->unreadSoft
);
windowUpdate();
statusUpdate();
@ -828,7 +832,8 @@ static void keyCode(int code) {
break; case KeyMetaEnter: edit(id, EditInsert, L'\n');
break; case KeyMetaEqual: window->mute ^= true; statusUpdate();
break; case KeyMetaMinus: toggleIgnore(window);
break; case KeyMetaMinus: incThresh(window, -1);
break; case KeyMetaPlus: incThresh(window, +1);
break; case KeyMetaSlash: windowShow(windows.swap);
break; case KeyMetaGt: windowScroll(window, -BufferCap);
@ -1050,10 +1055,10 @@ void uiLoad(const char *name) {
if (!time) break;
enum Heat heat = (version > 2 ? readTime(file) : Cold);
readString(file, &buf, &cap);
bufferPush(window->buffer, COLS, window->ignore, heat, time, buf);
bufferPush(window->buffer, COLS, window->thresh, heat, time, buf);
}
window->unreadHard = bufferReflow(
window->buffer, COLS, window->ignore, window->unreadSoft
window->buffer, COLS, window->thresh, window->unreadSoft
);
}
urlLoad(file, version);