noice.c | 38 +++++++++++++++++++++++++++----------- diff --git a/noice.c b/noice.c index 062e26b78c44b38ae24956945a6c0d3576cd1224..91a6a891607a931a9790eb096119f722ae48f1f2 100644 --- a/noice.c +++ b/noice.c @@ -42,8 +42,8 @@ int die = 0; struct assoc { - char *ext; - char *bin; + char *ext; /* Extension */ + char *bin; /* Program */ } assocs[] = { { "avi", "mplayer" }, { "mp4", "mplayer" }, @@ -87,6 +87,25 @@ b = *(struct dirent **)vb; return strcmp(a->d_name, b->d_name); } + +void +initcurses(void) +{ + initscr(); + cbreak(); + noecho(); + nonl(); + intrflush(stdscr, FALSE); + keypad(stdscr, TRUE); + curs_set(FALSE); /* Hide cursor */ +} + +void +exitcurses(void) +{ + endwin(); /* Restore terminal */ +} + /* Warning shows up at the bottom */ void @@ -318,12 +337,16 @@ } DPRINTF_S(ext); DPRINTF_S(bin); + exitcurses(); + /* Run program */ pid = fork(); if (pid == 0) execlp(bin, bin, file, NULL); else waitpid(pid, NULL, 0); + + initcurses(); free(file); @@ -360,18 +383,11 @@ /* Set locale before curses setup */ setlocale(LC_ALL, ""); - /* Init curses */ - initscr(); - cbreak(); - noecho(); - nonl(); - intrflush(stdscr, FALSE); - keypad(stdscr, TRUE); - curs_set(FALSE); /* Hide cursor */ + initcurses(); browse(ipath); - endwin(); /* Restore terminal */ + exitcurses(); return 0; }