=?utf-8?q?=5Bfolks=5D_Bug_660235_=E2=80=94_Consistent_signal_handlers_to_?= =?utf-8?q?a_terminal_would_be_cool?=



commit 456575eb920abe5c132d22db0871b5a7fcdde74f
Author: Philip Withnall <philip tecnocode co uk>
Date:   Fri Jan 13 19:37:29 2012 +0000

    Bug 660235 â Consistent signal handlers to a terminal would be cool
    
    Fix folks-inspectâs handling of SIGINT, SIGTERM and EOF. In the former case,
    we want to clear the current input buffer and display a new prompt. In
    the case of SIGTERM we want to exit cleanly, and in the case of EOF we want
    to exit if the input buffer is empty.
    
    The combination of readline, Unix signals and threads in this was unfun.
    
    Closes: https://bugzilla.gnome.org/show_bug.cgi?id=660235

 NEWS                       |    1 +
 tools/inspect/Makefile.am  |    1 +
 tools/inspect/inspect.vala |   30 +++++++++++++++++++++++++++++-
 3 files changed, 31 insertions(+), 1 deletions(-)
---
diff --git a/NEWS b/NEWS
index c1c9858..b5a6bdd 100644
--- a/NEWS
+++ b/NEWS
@@ -15,6 +15,7 @@ Bugs fixed:
 * Bug 671900 â Folks should not suggest linking contacts from telepathy-salut
 * Bug 670872 â Should be less sensitive to accentuated chars
 * Bug 669984 â Does not notify when contacts are added to groups
+* Bug 660235 â Consistent signal handlers to a terminal would be cool
 
 Overview of changes from libfolks 0.6.6 to libfolks 0.6.7
 =============================================================
diff --git a/tools/inspect/Makefile.am b/tools/inspect/Makefile.am
index 3ceb370..0bf0c9b 100644
--- a/tools/inspect/Makefile.am
+++ b/tools/inspect/Makefile.am
@@ -1,6 +1,7 @@
 VALAFLAGS = \
 	$(AM_VALAFLAGS) \
 	--vapidir=$(top_srcdir)/folks \
+	--pkg=posix \
 	--pkg=readline \
 	--pkg=gobject-2.0 \
 	--pkg=gio-2.0 \
diff --git a/tools/inspect/inspect.vala b/tools/inspect/inspect.vala
index f0c587f..1f34103 100644
--- a/tools/inspect/inspect.vala
+++ b/tools/inspect/inspect.vala
@@ -57,9 +57,19 @@ public class Folks.Inspect.Client : Object
           return 1;
         }
 
-      /* Create the client and run the command. */
+      /* Create the client. */
       main_client = new Client ();
 
+      /* Set up signal handling. */
+      Unix.signal_add (Posix.SIGTERM, () =>
+        {
+          /* Quit the client and let that exit the process. */
+          main_client.quit ();
+
+          return false;
+        });
+
+      /* Run the command. */
       if (args.length == 1)
         {
           main_client.run_interactive ();
@@ -209,6 +219,24 @@ public class Folks.Inspect.Client : Object
           assert_not_reached ();
         });
 
+      /* Handle SIGINT. */
+      Unix.signal_add (Posix.SIGINT, () =>
+        {
+          /* Tidy up. */
+          Readline.free_line_state ();
+          Readline.cleanup_after_signal ();
+          Readline.reset_after_signal ();
+
+          /* Display a fresh prompt. */
+          stdout.printf ("^C");
+          Readline.crlf ();
+          Readline.reset_line_state ();
+          Readline.replace_line ("", 0);
+          Readline.redisplay ();
+
+          return true;
+        });
+
       /* Allow things to be set for folks-inspect in ~/.inputrc, and install our
        * own completion function. */
       Readline.readline_name = "folks-inspect";



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]