diff options
| -rw-r--r-- | vis.c | 25 |
1 files changed, 15 insertions, 10 deletions
@@ -1685,14 +1685,8 @@ int main(int argc, char *argv[]) { for (int i = 1; i < argc; i++) { if (argv[i][0] == '-') { switch (argv[i][1]) { - case '\0': - if (!editor_window_new_fd(vis, STDIN_FILENO)) - die("Can not read from stdin\n"); - int fd = open("/dev/tty", O_RDONLY); - if (fd == -1) - die("Can not reopen stdin\n"); - dup2(fd, STDIN_FILENO); - close(fd); + /* handle command line arguments */ + default: break; } } else if (!editor_window_new(vis, argv[i])) { @@ -1700,8 +1694,19 @@ int main(int argc, char *argv[]) { } } - if (!vis->windows && !editor_window_new(vis, NULL)) - die("Can not create empty buffer\n"); + if (!vis->windows) { + if (!strcmp(argv[argc-1], "-") || !isatty(STDIN_FILENO)) { + if (!editor_window_new_fd(vis, STDIN_FILENO)) + die("Can not read from stdin\n"); + int fd = open("/dev/tty", O_RDONLY); + if (fd == -1) + die("Can not reopen stdin\n"); + dup2(fd, STDIN_FILENO); + close(fd); + } else if (!editor_window_new(vis, NULL)) { + die("Can not create empty buffer\n"); + } + } mainloop(); editor_free(vis); |
