Add activity indicator, fix window redraw on switch
- Status bar shows (Act: 2,3) for windows with unread messages - Activity clears when switching to that window - Re-set scroll region on every window redraw to prevent display issues
This commit is contained in:
@@ -31,6 +31,7 @@
|
||||
|
||||
static int current_level = WL_STATUS;
|
||||
static int scroll_offset = 0; /* 0 = bottom (live), >0 = scrolled up */
|
||||
static int win_activity[WL_MAX]; /* activity flag per window */
|
||||
static volatile sig_atomic_t got_sigint = 0;
|
||||
static volatile sig_atomic_t got_sigwinch = 0;
|
||||
|
||||
@@ -114,6 +115,24 @@ static void draw_statusbar(void)
|
||||
prefix_str, nick,
|
||||
cmodes[0] ? "[" : "", cmodes, cmodes[0] ? "]" : "");
|
||||
|
||||
/* Append activity indicator */
|
||||
char act[64] = "";
|
||||
int apos = 0;
|
||||
for (int i = 0; i < WL_MAX; i++) {
|
||||
if (win_activity[i] && i != current_level) {
|
||||
if (apos == 0)
|
||||
apos += snprintf(act + apos, sizeof(act) - apos, " (Act: ");
|
||||
else
|
||||
apos += snprintf(act + apos, sizeof(act) - apos, ",");
|
||||
apos += snprintf(act + apos, sizeof(act) - apos, "%d", i + 1);
|
||||
}
|
||||
}
|
||||
if (apos > 0)
|
||||
snprintf(act + apos, sizeof(act) - apos, ")");
|
||||
|
||||
size_t blen = strlen(bar);
|
||||
snprintf(bar + blen, sizeof(bar) - blen, "%s", act);
|
||||
|
||||
/* Status bar on second-to-last row */
|
||||
printf("\033[%d;1H\033[7m%-*.*s\033[0m",
|
||||
term_rows - 1, term_cols, term_cols, bar);
|
||||
@@ -136,6 +155,7 @@ static void buf_store(int level, const char *line)
|
||||
static void redraw_window(void)
|
||||
{
|
||||
get_term_size();
|
||||
printf("\033[1;%dr", term_rows - 2); /* ensure scroll region is set */
|
||||
int visible = term_rows - 2;
|
||||
int count = win_buf[current_level].count;
|
||||
|
||||
@@ -205,7 +225,10 @@ static void wprintf(int level, const char *fmt, ...)
|
||||
printf("\033[%d;1H\n\033[K%s", term_rows - 2, timestamped);
|
||||
draw_statusbar();
|
||||
}
|
||||
/* If scrolled up, don't disturb the view */
|
||||
} else {
|
||||
/* Mark activity on other window */
|
||||
win_activity[level] = 1;
|
||||
draw_statusbar();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -995,6 +1018,7 @@ int main(int argc, char *argv[])
|
||||
int lvl = ch - '1';
|
||||
if (lvl < WL_MAX) {
|
||||
current_level = lvl;
|
||||
win_activity[lvl] = 0;
|
||||
scroll_offset = 0;
|
||||
redraw_window();
|
||||
redraw_input(input_line, input_len, input_pos);
|
||||
|
||||
Reference in New Issue
Block a user