Skip to content

Commit

Permalink
re-implement keyboard commands in noncurses #536
Browse files Browse the repository at this point in the history
uses read() with VMIN and VTIME set to 0

have yet to notice the same issues we had with #379
  • Loading branch information
karlstav committed Nov 28, 2023
1 parent a95614b commit c5d36aa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
10 changes: 6 additions & 4 deletions cava.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand 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;
Expand Down
9 changes: 7 additions & 2 deletions output/terminal_noncurses.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit c5d36aa

Please sign in to comment.