From c5d36aa55b3e3382fbd120468c127baa6d321794 Mon Sep 17 00:00:00 2001 From: karl Date: Tue, 28 Nov 2023 20:33:12 +0100 Subject: [PATCH] re-implement keyboard commands in noncurses #536 uses read() with VMIN and VTIME set to 0 have yet to notice the same issues we had with #379 --- cava.c | 10 ++++++---- output/terminal_noncurses.c | 9 +++++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/cava.c b/cava.c index 5d4359a..6c5658f 100644 --- a/cava.c +++ b/cava.c @@ -767,11 +767,11 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co if (output_mode == OUTPUT_NCURSES) ch = getch(); #endif - /* - // disabled key controls in non-curses mode, caused garbage on screen + +#ifndef _MSC_VER if (output_mode == OUTPUT_NONCURSES) - ch = fgetc(stdin); - */ + read(0, &ch, sizeof(ch)); +#endif switch (ch) { case 65: // key up @@ -815,6 +815,8 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co should_quit = 1; } + ch = 0; + if (should_reload) { reloadConf = true; diff --git a/output/terminal_noncurses.c b/output/terminal_noncurses.c index 431346d..4a20eea 100644 --- a/output/terminal_noncurses.c +++ b/output/terminal_noncurses.c @@ -42,10 +42,15 @@ int setecho(int fd, int onoff) { if (tcgetattr(fd, &t) == -1) return -1; - if (onoff == 0) + if (onoff == 0) { t.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL | ICANON); - else + t.c_cc[VTIME] = 0; + t.c_cc[VMIN] = 0; + } else { t.c_lflag |= (ECHO | ECHOE | ECHOK | ECHONL | ICANON); + t.c_cc[VTIME] = 0; + t.c_cc[VMIN] = 1; + } if (tcsetattr(fd, TCSANOW, &t) == -1) return -1;