Skip to content

Commit

Permalink
trap SIGINT to clean up the display
Browse files Browse the repository at this point in the history
I missed this initially because my zsh config does this automatically
for badly-behaved programs like pipeline.
  • Loading branch information
codekitchen committed Nov 29, 2019
1 parent b338349 commit c07c55c
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <math.h>
#include <ncurses.h>
#include <readline/readline.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
Expand Down Expand Up @@ -200,6 +201,12 @@ int setup() {
return 0;
}

void cleanup(int sig) {
printf("\n");
termput0("cd");
exit(0);
}

static struct option const long_options[] = {
{"truncate", no_argument, NULL, 't'},
{"help", no_argument, NULL, 'h'},
Expand Down Expand Up @@ -241,7 +248,10 @@ int main(int argc, char *const *argv) {

setupterm(NULL, 1, NULL);
rl_startup_hook = setup;
signal(SIGINT, cleanup);
char *line = readline("pipeline> ");
// as far as I'm aware, we'll never reach this point because
// we always exit with Ctrl-C.
free(line);
return 0;
}

0 comments on commit c07c55c

Please sign in to comment.