Skip to content

Commit

Permalink
Disable signals from ^C (and friends)
Browse files Browse the repository at this point in the history
Allows us to interpret ^C through ^Z as control codes and handle them
properly.

Also fixes resetting termios after ^C
  • Loading branch information
jhawthorn committed Oct 19, 2014
1 parent b44be63 commit c333504
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions fzy.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ void run(tty_t *tty, choices_t *choices){
strncpy(search, choices_get(choices, choices->selection), SEARCH_SIZE_MAX);
search_size = strlen(search);
choices_search(choices, search);
}else if(ch == 3 || ch == 4){ /* ^C || ^D */
clear(tty);
tty_close(tty);
exit(EXIT_FAILURE);
}else if(ch == 10){ /* Enter */
clear(tty);

Expand Down
3 changes: 2 additions & 1 deletion tty.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ void tty_init(tty_t *tty, const char *tty_filename){
* Disable both of
* ICANON Canonical input (erase and kill processing).
* ECHO Enable echo.
* ISIG Disable signals from control characters
*/
new_termios.c_lflag &= ~(ICANON | ECHO);
new_termios.c_lflag &= ~(ICANON | ECHO | ISIG);

if(tcsetattr(tty->fdin, TCSANOW, &new_termios))
perror("tcsetattr");
Expand Down

0 comments on commit c333504

Please sign in to comment.