add a console_callbacks::on_interrupt callback triggered by SIGINT while waiting
authorTero Marttila <terom@fixme.fi>
Thu, 21 May 2009 16:57:28 +0300
changeset 212 ddc79529a1e0
parent 211 b460d958a685
child 213 f0e52e026197
add a console_callbacks::on_interrupt callback triggered by SIGINT while waiting
src/console.c
src/console.h
--- a/src/console.c	Thu May 21 16:57:00 2009 +0300
+++ b/src/console.c	Thu May 21 16:57:28 2009 +0300
@@ -115,20 +115,26 @@
             break;
     }
 }
-
 static void on_sigint (int sig)
 {
     struct console *console = &_console;
 
     (void) sig;
 
-    // interrupt the input line
-    // XXX: is this the right function to call?
-    rl_free_line_state();
+    if (console->waiting) {
+        // notify user
+        if (console->callbacks->on_interrupt)
+            console->callbacks->on_interrupt(console->cb_arg);
 
-    // redisplay on new line
-    rl_crlf();
-    rl_callback_handler_install(console->config.prompt, console_line);
+    } else {
+        // interrupt the input line
+        // XXX: is this the right function to call?
+        rl_free_line_state();
+
+        // redisplay on new line
+        rl_crlf();
+        rl_callback_handler_install(console->config.prompt, console_line);
+    }
 }
 
 err_t console_init (struct console **console_ptr, struct event_base *ev_base, const struct console_config *config,
--- a/src/console.h	Thu May 21 16:57:00 2009 +0300
+++ b/src/console.h	Thu May 21 16:57:28 2009 +0300
@@ -54,6 +54,12 @@
      * Note that for interactive consoles, EOF isn't actually EOF - there might be multiple EOFs...
      */
     void (*on_eof) (void *arg);
+
+    /**
+     * An input interrupt (SIGINT) was recieved while in the wait state. This can be used to abort execution and
+     * call console_continue quickly.
+     */
+    void (*on_interrupt) (void *arg);
 };
 
 /**