From db2d3bd93b133e061510b023a7ade539ab0aad25 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Sat, 5 Sep 2020 04:31:28 +0200 Subject: [PATCH] Deal properly with EOF in the REPL, when built without readline --- src/ui/terminal/terminal-reader.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/ui/terminal/terminal-reader.c b/src/ui/terminal/terminal-reader.c index c23fad186f..071e435eca 100644 --- a/src/ui/terminal/terminal-reader.c +++ b/src/ui/terminal/terminal-reader.c @@ -413,9 +413,21 @@ command_generator (const char *text, int state) #else /* !HAVE_READLINE */ +static const char * the_prompt; + +static void +handler (int sig) +{ + if (the_prompt) + fputs (the_prompt, stdout); + fflush (stdout); +} + static void readline_init (void) { + if (SIG_ERR == signal (SIGINT, handler)) + perror ("Cannot add signal handler"); } static void @@ -423,19 +435,22 @@ readline_done (void) { } +/* Prompt the user for a line of input and return it in LINE. + Returns true if the LINE should be considered valid, false otherwise. + */ static bool readline_read (struct substring *line, enum prompt_style style) { struct string string; - const char *prompt = readline_prompt (style); + the_prompt = readline_prompt (style); - fputs (prompt, stdout); + fputs (the_prompt, stdout); fflush (stdout); ds_init_empty (&string); ds_read_line (&string, stdin, SIZE_MAX); *line = string.ss; - return false; + return true; } #endif /* !HAVE_READLINE */ -- 2.30.2