>From 54ae6d94a1e4158997753417cc5c0342cd39a0da Mon Sep 17 00:00:00 2001 From: Brand Huntsman Date: Thu, 16 May 2019 22:16:20 -0600 Subject: [PATCH 3/3] files: add cancel option while reading an empty FIFO Signed-off-by: Brand Huntsman --- src/files.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/src/files.c b/src/files.c index c3aba679..cbba2786 100644 --- a/src/files.c +++ b/src/files.c @@ -29,6 +29,7 @@ #endif #include #include +#include #define LOCKBUFSIZE 8192 @@ -929,6 +930,17 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable) #endif } +/* Display message while reading a FIFO. */ +static void display_reading_fifo() +{ + blank_bottombars(); + + wmove(bottomwin, 2, 0); + post_one_key("^C", _("Cancel"), COLS); + + statusbar(_("Reading FIFO...")); +} + /* Open the file with the given name. If the file does not exist, display * "New File" if newfie is TRUE, and say "File not found" otherwise. * Return -2 if we say "New File", -1 if the file isn't opened, and the @@ -969,7 +981,43 @@ int open_file(const char *filename, bool newfie, bool quiet, FILE **f) } /* Try opening the file. */ - fd = open(full_filename, O_RDONLY); + if (S_ISFIFO(fileinfo.st_mode)) { + fd = open(full_filename, O_RDONLY | O_NONBLOCK); + if (fd != -1) { + bool helpless = ISSET(NO_HELP); + + if (helpless && LINES > 4) { + UNSET(NO_HELP); + window_init(); + } + + display_reading_fifo(); + + disable_waiting(); + while (TRUE) { + struct pollfd fds = { fd, -1, 0 }; + if (poll(&fds, 1, 1) == 1 && (fds.revents & POLLIN)) break; + + /* Consume all keys and abort if ^C. */ + int input; + while (TRUE) { + input = parse_kbinput(edit); + if(input == KEY_WINCH) display_reading_fifo(); + else if(input == ERR || input == 3) break; + else beep(); + } + if (input == 3) break; + } + enable_waiting(); + + if (helpless) { + SET(NO_HELP); + window_init(); + refresh_needed = TRUE; + } + } + } else + fd = open(full_filename, O_RDONLY); if (fd == -1) statusline(ALERT, _("Error reading %s: %s"), filename, strerror(errno)); -- 2.21.0