1
0
Fork 0
forked from murx/irc9

Reduce TUI flicker during input editing

This commit is contained in:
Johannes Findeisen 2026-11-28 23:50:57 +01:00
commit 69535eda41

36
irc9.c
View file

@ -155,6 +155,8 @@ static int connect_pipe[2] = { -1, -1 };
static Window *curwin;
static volatile sig_atomic_t quit_flag;
static int dirty = 1;
static int input_dirty;
static time_t status_minute;
static int cols = 80, lines = 24;
static int treew = TREEW, mainh = 1;
static struct termios saved_terminal;
@ -1707,7 +1709,7 @@ static void replace_completion(int start, int tail_at, const char *chosen,
input_len = input_pos = (int)strlen(input);
comp_start = start;
comp_end = start + (int)strlen(chosen) + (int)strlen(sep);
dirty = 1;
input_dirty = 1;
}
/* Complete the command word after '/'; repeated tabs cycle the matches. */
@ -2046,20 +2048,20 @@ static void edit_line(int c, char text[MAXINPUT], int *len, int *pos)
--*pos;
--*len;
}
dirty = 1;
input_dirty = 1;
return;
}
if (c == KEY_LEFT) { if (*pos > 0) (*pos)--; dirty = 1; return; }
if (c == KEY_RIGHT) { if (*pos < *len) (*pos)++; dirty = 1; return; }
if (c == KEY_HOME) { *pos = 0; dirty = 1; return; }
if (c == KEY_END) { *pos = *len; dirty = 1; return; }
if (c == KEY_LEFT) { if (*pos > 0) (*pos)--; input_dirty = 1; return; }
if (c == KEY_RIGHT) { if (*pos < *len) (*pos)++; input_dirty = 1; return; }
if (c == KEY_HOME) { *pos = 0; input_dirty = 1; return; }
if (c == KEY_END) { *pos = *len; input_dirty = 1; return; }
if (((c >= 32 && c < 127) || (c >= 0x80 && c < 0x100)) &&
*len < MAXINPUT - 1) {
memmove(text + *pos + 1, text + *pos,
(size_t)(*len - *pos) + 1);
text[(*pos)++] = (char)c;
++*len;
dirty = 1;
input_dirty = 1;
}
}
@ -2104,8 +2106,8 @@ static void handle_key(int c)
if (c == '\n' || c == '\r') { submit_input(); return; }
if (c == KEY_UP) { history_browse(-1); dirty = 1; return; }
if (c == KEY_DOWN) { history_browse(1); dirty = 1; return; }
if (c == KEY_UP) { history_browse(-1); input_dirty = 1; return; }
if (c == KEY_DOWN) { history_browse(1); input_dirty = 1; return; }
if (c == KEY_PPAGE) {
if (curwin) {
int height = mainh - layout_topic(0);
@ -2506,8 +2508,9 @@ static void draw_main(void)
}
}
static void draw_input(void)
static void draw_status(void)
{
status_minute = time(NULL) / 60;
if (lines < 4) return;
terminal_move(lines - 3, 0);
terminal_accent();
@ -2542,7 +2545,11 @@ static void draw_input(void)
}
}
fputs("\033[0m", stdout);
}
static void draw_input(void)
{
if (lines < 4) return;
terminal_move(lines - 1, 0);
if (cols > 1) fputs("> ", stdout);
const char *text = saving ? save_path : input;
@ -2562,6 +2569,7 @@ static void draw_input(void)
x -= width;
}
terminal_text(text + start, cols - 3);
fputs("\033[K", stdout);
if (x >= cols) x = cols - 1;
terminal_move(lines - 1, x);
}
@ -2572,10 +2580,12 @@ static void redraw(void)
draw_title();
draw_tree();
draw_main();
draw_status();
draw_input();
fputs("\033[?25h", stdout);
fflush(stdout);
dirty = 0;
input_dirty = 0;
}
static void check_resize(void)
@ -2821,6 +2831,12 @@ int main(int argc, char **argv)
read_server(owner[i]);
if (dirty) redraw();
else if (input_dirty) {
if (!saving && now / 60 != status_minute) draw_status();
draw_input();
fflush(stdout);
input_dirty = 0;
}
}
terminal_finish();