Changeset: 3a06927d82e1 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/3a06927d82e1
Modified Files:
clients/mapiclient/ReadlineTools.c
Branch: client_interrupts
Log Message:
Handle SIGINT on mclient prompts
If readline support is available, Ctrl-C on mclient prompts does not terminate
mclient, but instead it clears the current input and presents a fresh prompt.
diffs (46 lines):
diff --git a/clients/mapiclient/ReadlineTools.c
b/clients/mapiclient/ReadlineTools.c
--- a/clients/mapiclient/ReadlineTools.c
+++ b/clients/mapiclient/ReadlineTools.c
@@ -31,6 +31,10 @@
#include <sys/stat.h>
#endif
+#ifdef HAVE_SIGACTION
+#include <signal.h> /* to intercept SIGINT */
+#endif
+
static const char *sql_commands[] = {
"SELECT",
"INSERT",
@@ -418,6 +422,16 @@ bailout:
return 1;
}
+static void
+prompt_int_handler(int status)
+{
+ (void)status;
+ printf("\n"); // Move to a new line
+ rl_on_new_line(); // Regenerate the prompt on a newline
+ rl_replace_line("", 0); // Clear the previous text
+ rl_redisplay();
+}
+
void
init_readline(Mapi mid, const char *lang, bool save_history)
{
@@ -440,6 +454,8 @@ init_readline(Mapi mid, const char *lang
rl_add_funmap_entry("invoke-editor", invoke_editor);
rl_bind_keyseq("\\M-e", invoke_editor);
+ signal(SIGINT, prompt_int_handler);
+
if (save_history) {
int len;
if (getenv("HOME") != NULL) {
@@ -498,5 +514,4 @@ save_line(const char *s)
append_history(1, _history_file);
}
-
#endif /* HAVE_LIBREADLINE */
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]