diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2013-01-19 11:51:56 +0100 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2013-01-19 11:51:56 +0100 |
commit | 72b948fb1eaba1fc06de7325cc095f0889ce4d7f (patch) | |
tree | 4f53e793ddda10ca4ddcff9355a5c51953a389e6 /src | |
parent | a54b49f5a8858ae6603d0db56019adc3ce0dff90 (diff) | |
download | sciteco-72b948fb1eaba1fc06de7325cc095f0889ce4d7f.tar.gz |
allow <CTRL/C> to be typed; aborts last typed char
* CTRL/C will be a command so it is important to be able to type it directly
* aborting character processing is important because it allows aborting infinite loops
* since the loop interruption currently relies on SIGINT handling, there is only limited
support for XCurses and GTK - CTRL/C has to be typed in the terminal window.
later support for input queue polling might be added
Diffstat (limited to 'src')
-rw-r--r-- | src/interface-ncurses.cpp | 10 | ||||
-rw-r--r-- | src/interface.h | 8 | ||||
-rw-r--r-- | src/main.cpp | 19 | ||||
-rw-r--r-- | src/parser.cpp | 3 | ||||
-rw-r--r-- | src/sciteco.h | 4 |
5 files changed, 42 insertions, 2 deletions
diff --git a/src/interface-ncurses.cpp b/src/interface-ncurses.cpp index 97c050d..98f2dca 100644 --- a/src/interface-ncurses.cpp +++ b/src/interface-ncurses.cpp @@ -43,7 +43,7 @@ InterfaceNCurses interface; extern "C" { static void scintilla_notify(Scintilla *sci, int idFrom, - void *notify, void *user_data); + void *notify, void *user_data); } #define UNNAMED_FILE "(Unnamed)" @@ -63,7 +63,6 @@ static void scintilla_notify(Scintilla *sci, int idFrom, InterfaceNCurses::InterfaceNCurses() { init_screen(); - raw(); cbreak(); noecho(); curs_set(0); /* Scintilla draws its own cursor */ @@ -368,7 +367,12 @@ InterfaceNCurses::event_loop(void) if (popup.window) wrefresh(popup.window); + /* no special <CTRL/C> handling */ + raw(); key = wgetch(cmdline_window); + /* allow asynchronous interruptions on <CTRL/C> */ + cbreak(); + switch (key) { #ifdef KEY_RESIZE case ERR: @@ -403,6 +407,8 @@ InterfaceNCurses::event_loop(void) if (key <= 0xFF) cmdline_keypress((gchar)key); } + + sigint_occurred = FALSE; } } diff --git a/src/interface.h b/src/interface.h index 28be9fe..38cd725 100644 --- a/src/interface.h +++ b/src/interface.h @@ -19,6 +19,7 @@ #define __INTERFACE_H #include <stdarg.h> +#include <signal.h> #include <glib.h> @@ -29,6 +30,7 @@ /* avoid include dependency conflict */ class QRegister; class Buffer; +extern sig_atomic_t sigint_occurred; /* * Base class for all user interfaces - used mereley as a class interface. @@ -107,6 +109,12 @@ public: virtual void popup_show(void) = 0; virtual void popup_clear(void) = 0; + virtual inline bool + is_interrupted(void) + { + return sigint_occurred != FALSE; + } + /* main entry point */ virtual void event_loop(void) = 0; diff --git a/src/main.cpp b/src/main.cpp index 2adb505..f5cd780 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -23,6 +23,7 @@ #include <stdio.h> #include <string.h> #include <stdlib.h> +#include <signal.h> #include <glib.h> #include <glib/gprintf.h> @@ -51,6 +52,12 @@ namespace Flags { static gchar *mung_file = NULL; +sig_atomic_t sigint_occurred = FALSE; + +extern "C" { +static void sigint_handler(int signal); +} + void Interface::stdio_vmsg(MessageType type, const gchar *fmt, va_list ap) { @@ -160,6 +167,8 @@ main(int argc, char **argv) static GotoTable cmdline_goto_table; static QRegisterTable local_qregs; + signal(SIGINT, sigint_handler); + process_options(argc, argv); interface.ssm(SCI_SETCARETSTYLE, CARETSTYLE_BLOCK); @@ -213,3 +222,13 @@ main(int argc, char **argv) return 0; } + +/* + * Callbacks + */ + +static void +sigint_handler(int signal __attribute__((unused))) +{ + sigint_occurred = TRUE; +} diff --git a/src/parser.cpp b/src/parser.cpp index 1843b1d..658dbe5 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -79,6 +79,9 @@ Execute::step(const gchar *macro) throw (State::Error) States::current, mode); #endif + if (interface.is_interrupted()) + throw State::Error("Interrupted"); + State::input(macro[macro_pc]); macro_pc++; } diff --git a/src/sciteco.h b/src/sciteco.h index 92014e2..a03c1d5 100644 --- a/src/sciteco.h +++ b/src/sciteco.h @@ -18,6 +18,8 @@ #ifndef __SCITECO_H #define __SCITECO_H +#include <signal.h> + #include <glib.h> #include "interface.h" @@ -30,6 +32,8 @@ namespace Flags { extern gint64 ed; } +extern sig_atomic_t sigint_occurred; + extern gchar *cmdline; extern bool quit_requested; |