Skip to content

Commit

Permalink
vis-menu: also re-open /dev/tty as stderr
Browse files Browse the repository at this point in the history
This means vis-menu will also work when stderr is used for other purposes.

This will be used by the vis editor:

 - stdin is used for the initial completion candidates
 - stdout is used to return the selected entry
 - stderr is used for error reporting
  • Loading branch information
martanne committed Nov 25, 2016
1 parent e9f28e9 commit 1c9c526
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion vis-menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ drawmenu(void) {

}
fprintf(stderr, "\033[%iG", (int)(promptw+textwn(text, cursor)-1));
fflush(stderr);
}

static char*
Expand Down Expand Up @@ -317,7 +318,8 @@ setup(void) {
struct winsize ws;

/* re-open stdin to read keyboard */
if (!freopen("/dev/tty", "r", stdin)) die("Can't reopen tty.");
if (!freopen("/dev/tty", "r", stdin)) die("Can't reopen tty as stdin.");
if (!freopen("/dev/tty", "w", stderr)) die("Can't reopen tty as stderr.");

/* ioctl() the tty to get size */
fd = open("/dev/tty", O_RDWR);
Expand Down

0 comments on commit 1c9c526

Please sign in to comment.