master
C. McEnroe 2020-02-09 12:13:51 -05:00
parent 347fabc2fe
commit f0e2c089c9
2 changed files with 22 additions and 10 deletions

View File

@ -254,6 +254,8 @@ Cycle through unread windows.
Insert a blank line in the window. Insert a blank line in the window.
.It Ic M- Ns Ar n .It Ic M- Ns Ar n
Switch to window by number 0\(en9. Switch to window by number 0\(en9.
.It Ic M-u
Scroll to first unread line.
.El .El
. .
.Ss IRC Formatting .Ss IRC Formatting

30
ui.c
View File

@ -71,10 +71,11 @@ struct Window {
size_t id; size_t id;
struct Buffer buffer; struct Buffer buffer;
WINDOW *pad; WINDOW *pad;
enum Heat heat;
int unread;
int scroll;
bool mark; bool mark;
enum Heat heat;
int unreadCount;
int unreadLines;
int scroll;
struct Window *prev; struct Window *prev;
struct Window *next; struct Window *next;
}; };
@ -200,6 +201,7 @@ static void errExit(void) {
X(KeyMetaD, "\33d") \ X(KeyMetaD, "\33d") \
X(KeyMetaF, "\33f") \ X(KeyMetaF, "\33f") \
X(KeyMetaM, "\33m") \ X(KeyMetaM, "\33m") \
X(KeyMetaU, "\33u") \
X(KeyMetaSlash, "\33/") \ X(KeyMetaSlash, "\33/") \
X(KeyFocusIn, "\33[I") \ X(KeyFocusIn, "\33[I") \
X(KeyFocusOut, "\33[O") \ X(KeyFocusOut, "\33[O") \
@ -347,7 +349,7 @@ static void statusUpdate(void) {
int num; int num;
const struct Window *window; const struct Window *window;
for (num = 0, window = windows.head; window; ++num, window = window->next) { for (num = 0, window = windows.head; window; ++num, window = window->next) {
if (!window->unread && window != windows.active) continue; if (!window->unreadCount && window != windows.active) continue;
int unread; int unread;
char buf[256]; char buf[256];
snprintf( snprintf(
@ -355,10 +357,10 @@ static void statusUpdate(void) {
idColors[window->id], (window == windows.active ? "\26" : ""), idColors[window->id], (window == windows.active ? "\26" : ""),
num, idNames[window->id], num, idNames[window->id],
&unread, (window->heat > Warm ? White : idColors[window->id]), &unread, (window->heat > Warm ? White : idColors[window->id]),
window->unread, window->unreadCount,
idColors[window->id] idColors[window->id]
); );
if (!window->unread) buf[unread] = '\0'; if (!window->unreadCount) buf[unread] = '\0';
statusAdd(buf); statusAdd(buf);
} }
wclrtoeol(status); wclrtoeol(status);
@ -368,9 +370,9 @@ static void statusUpdate(void) {
snprintf( snprintf(
buf, sizeof(buf), "%s %s%n (%d)", buf, sizeof(buf), "%s %s%n (%d)",
self.network, idNames[windows.active->id], self.network, idNames[windows.active->id],
&unread, windows.active->unread &unread, windows.active->unreadCount
); );
if (!windows.active->unread) buf[unread] = '\0'; if (!windows.active->unreadCount) buf[unread] = '\0';
putp(to_status_line); putp(to_status_line);
putp(buf); putp(buf);
putp(from_status_line); putp(from_status_line);
@ -380,7 +382,7 @@ static void statusUpdate(void) {
static void unmark(struct Window *window) { static void unmark(struct Window *window) {
if (!window->scroll) { if (!window->scroll) {
window->heat = Cold; window->heat = Cold;
window->unread = 0; window->unreadCount = 0;
window->mark = false; window->mark = false;
} }
statusUpdate(); statusUpdate();
@ -396,6 +398,11 @@ static void windowScroll(struct Window *window, int n) {
if (!window->scroll) unmark(window); if (!window->scroll) unmark(window);
} }
static void windowScrollUnread(struct Window *window) {
window->scroll = 0;
windowScroll(window, window->unreadLines - PAGE_LINES);
}
static int wordWidth(const char *str) { static int wordWidth(const char *str) {
size_t len = strcspn(str, " "); size_t len = strcspn(str, " ");
int width = 0; int width = 0;
@ -466,8 +473,9 @@ void uiWrite(size_t id, enum Heat heat, const time_t *src, const char *str) {
int lines = 1; int lines = 1;
waddch(window->pad, '\n'); waddch(window->pad, '\n');
if (window->mark && !window->unreadCount) window->unreadLines = 0;
if (window->mark && heat > Cold) { if (window->mark && heat > Cold) {
if (!window->unread++) { if (!window->unreadCount++) {
lines++; lines++;
waddch(window->pad, '\n'); waddch(window->pad, '\n');
} }
@ -475,6 +483,7 @@ void uiWrite(size_t id, enum Heat heat, const time_t *src, const char *str) {
statusUpdate(); statusUpdate();
} }
lines += wordWrap(window->pad, str); lines += wordWrap(window->pad, str);
if (window->mark) window->unreadLines += lines;
if (window->scroll) windowScroll(window, lines); if (window->scroll) windowScroll(window, lines);
if (heat > Warm) beep(); if (heat > Warm) beep();
} }
@ -689,6 +698,7 @@ static void keyCode(int code) {
break; case KeyMetaD: edit(id, EditDeleteNextWord, 0); break; case KeyMetaD: edit(id, EditDeleteNextWord, 0);
break; case KeyMetaF: edit(id, EditNextWord, 0); break; case KeyMetaF: edit(id, EditNextWord, 0);
break; case KeyMetaM: waddch(window->pad, '\n'); break; case KeyMetaM: waddch(window->pad, '\n');
break; case KeyMetaU: windowScrollUnread(window);
break; case KEY_BACKSPACE: edit(id, EditDeletePrev, 0); break; case KEY_BACKSPACE: edit(id, EditDeletePrev, 0);
break; case KEY_DC: edit(id, EditDeleteNext, 0); break; case KEY_DC: edit(id, EditDeleteNext, 0);