diff options
author | 2014-12-23 23:27:49 -0500 | |
---|---|---|
committer | 2014-12-23 23:27:49 -0500 | |
commit | eb5de3fc6818026daf64d8880cce97d941a96f3f (patch) | |
tree | 358f8ecedc552aa8420d2f70aa3396e165a717b2 /src | |
parent | bef10e0044c6abeaaa52b0fd1816b344f9ff4245 (diff) | |
download | textadept-eb5de3fc6818026daf64d8880cce97d941a96f3f.tar.gz textadept-eb5de3fc6818026daf64d8880cce97d941a96f3f.zip |
Enable suspend in the terminal version.
Patch libtermkey to allow this and also to support mouse enabling/disabling.
Needed to change ^Z undo to M-Z and added M-S-Z as extra redo.
Diffstat (limited to 'src')
-rw-r--r-- | src/termkey.patch | 52 | ||||
-rw-r--r-- | src/textadept.c | 38 |
2 files changed, 55 insertions, 35 deletions
diff --git a/src/termkey.patch b/src/termkey.patch index f649cbaf..7bc52b86 100644 --- a/src/termkey.patch +++ b/src/termkey.patch @@ -1,6 +1,6 @@ -diff -r a94d84bdd4a6 driver-win32-pdcurses.c +diff -r 49c8684413c0 driver-win32-pdcurses.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 -+++ b/driver-win32-pdcurses.c Fri Oct 24 21:59:44 2014 -0400 ++++ b/driver-win32-pdcurses.c Tue Dec 23 13:31:50 2014 -0500 @@ -0,0 +1,106 @@ +// Copyright 2014 Mitchell mitchell.att.foicica.com. See LICENSE. + @@ -108,9 +108,9 @@ diff -r a94d84bdd4a6 driver-win32-pdcurses.c + .free_driver = free_driver, + .peekkey = peekkey, +}; -diff -r a94d84bdd4a6 termkey-internal.h ---- a/termkey-internal.h Fri Oct 24 21:58:29 2014 -0400 -+++ b/termkey-internal.h Fri Oct 24 21:59:44 2014 -0400 +diff -r 49c8684413c0 termkey-internal.h +--- a/termkey-internal.h Tue Dec 23 10:36:54 2014 -0500 ++++ b/termkey-internal.h Tue Dec 23 13:31:50 2014 -0500 @@ -4,7 +4,9 @@ #include "termkey.h" @@ -152,9 +152,9 @@ diff -r a94d84bdd4a6 termkey-internal.h +#endif #endif -diff -r a94d84bdd4a6 termkey.c ---- a/termkey.c Fri Oct 24 21:58:29 2014 -0400 -+++ b/termkey.c Fri Oct 24 21:59:44 2014 -0400 +diff -r 49c8684413c0 termkey.c +--- a/termkey.c Tue Dec 23 10:36:54 2014 -0500 ++++ b/termkey.c Tue Dec 23 13:31:50 2014 -0500 @@ -3,8 +3,12 @@ #include <ctype.h> @@ -216,26 +216,40 @@ diff -r a94d84bdd4a6 termkey.c if(tk->fd != -1 && !(tk->flags & TERMKEY_FLAG_NOTERMIOS)) { struct termios termios; if(tcgetattr(tk->fd, &termios) == 0) { -@@ -487,6 +496,7 @@ +@@ -472,9 +481,9 @@ + /* want no signal keys at all, so just disable ISIG */ + termios.c_lflag &= ~ISIG; + else { +- /* Disable Ctrl-\==VQUIT and Ctrl-D==VSUSP but leave Ctrl-C as SIGINT */ ++ /* Disable Ctrl-\==VQUIT and Ctrl-C==VINTR but leave Ctrl-Z as SIGTSTP */ + termios.c_cc[VQUIT] = _POSIX_VDISABLE; +- termios.c_cc[VSUSP] = _POSIX_VDISABLE; ++ termios.c_cc[VINTR] = _POSIX_VDISABLE; + /* Some OSes have Ctrl-Y==VDSUSP */ + #ifdef VDSUSP + termios.c_cc[VDSUSP] = _POSIX_VDISABLE; +@@ -487,6 +496,8 @@ tcsetattr(tk->fd, TCSANOW, &termios); } } ++ printf("\033[?1002h"), fflush(stdout); // enable mouse mode +#endif struct TermKeyDriverNode *p; for(p = tk->drivers; p; p = p->next) -@@ -512,8 +522,10 @@ +@@ -512,8 +523,11 @@ if(p->driver->stop_driver) (*p->driver->stop_driver)(tk, p->info); +#if !_WIN32 if(tk->restore_termios_valid) tcsetattr(tk->fd, TCSANOW, &tk->restore_termios); ++ printf("\033[?1002l"), fflush(stdout); // disable mouse mode +#endif tk->is_started = 0; -@@ -525,11 +537,18 @@ +@@ -525,11 +539,18 @@ return tk->is_started; } @@ -255,7 +269,7 @@ diff -r a94d84bdd4a6 termkey.c int termkey_get_flags(TermKey *tk) { return tk->flags; -@@ -1012,7 +1031,7 @@ +@@ -1012,7 +1033,7 @@ TermKeyResult termkey_waitkey(TermKey *tk, TermKeyKey *key) { @@ -264,7 +278,7 @@ diff -r a94d84bdd4a6 termkey.c errno = EBADF; return TERMKEY_RES_ERROR; } -@@ -1026,6 +1045,7 @@ +@@ -1026,6 +1047,7 @@ case TERMKEY_RES_ERROR: return ret; @@ -272,7 +286,7 @@ diff -r a94d84bdd4a6 termkey.c case TERMKEY_RES_NONE: ret = termkey_advisereadable(tk); if(ret == TERMKEY_RES_ERROR) -@@ -1064,6 +1084,7 @@ +@@ -1064,6 +1086,7 @@ return termkey_getkey_force(tk, key); } break; @@ -280,7 +294,7 @@ diff -r a94d84bdd4a6 termkey.c } } -@@ -1072,6 +1093,7 @@ +@@ -1072,6 +1095,7 @@ TermKeyResult termkey_advisereadable(TermKey *tk) { @@ -288,7 +302,7 @@ diff -r a94d84bdd4a6 termkey.c ssize_t len; if(tk->fd == -1) { -@@ -1109,6 +1131,9 @@ +@@ -1109,6 +1133,9 @@ tk->buffcount += len; return TERMKEY_RES_AGAIN; } @@ -298,9 +312,9 @@ diff -r a94d84bdd4a6 termkey.c } size_t termkey_push_bytes(TermKey *tk, const char *bytes, size_t len) -diff -r a94d84bdd4a6 termkey.h ---- a/termkey.h Fri Oct 24 21:58:29 2014 -0400 -+++ b/termkey.h Fri Oct 24 21:59:44 2014 -0400 +diff -r 49c8684413c0 termkey.h +--- a/termkey.h Tue Dec 23 10:36:54 2014 -0500 ++++ b/termkey.h Tue Dec 23 13:31:50 2014 -0500 @@ -14,6 +14,14 @@ #define TERMKEY_CHECK_VERSION \ termkey_check_version(TERMKEY_VERSION_MAJOR, TERMKEY_VERSION_MINOR) diff --git a/src/textadept.c b/src/textadept.c index 5296c51b..67283583 100644 --- a/src/textadept.c +++ b/src/textadept.c @@ -2372,15 +2372,22 @@ static void new_window() { } #if (CURSES && !_WIN32) -/** Signal for a terminal resize. */ -static void resize(int signal) { - struct winsize win; - ioctl(0, TIOCGWINSZ, &win); - resizeterm(win.ws_row, win.ws_col), pane_resize(pane, LINES - 2, COLS, 1, 0); - WINDOW *ce_win = scintilla_get_window(command_entry); - wresize(ce_win, 1, COLS), mvwin(ce_win, LINES - 1 - getmaxy(ce_win), 0); - lL_event(lua, "update_ui", -1); - refresh_all(); +/** + * Signal for a terminal suspend, continue, and resize. + * libtermkey has been patched to enable suspend as well as enable/disable mouse + * mode (1002). + */ +static void t_signal(int signal) { + if (signal != SIGTSTP) { + if (signal == SIGCONT) termkey_start(ta_tk); + struct winsize w; + ioctl(0, TIOCGWINSZ, &w); + resizeterm(w.ws_row, w.ws_col), pane_resize(pane, LINES - 2, COLS, 1, 0); + WINDOW *ce_win = scintilla_get_window(command_entry); + wresize(ce_win, 1, COLS), mvwin(ce_win, LINES - 1 - getmaxy(ce_win), 0); + lL_event(lua, "update_ui", -1); + refresh_all(); + } else endwin(), termkey_stop(ta_tk), kill(0, SIGSTOP); } /** Replacement for `termkey_waitkey()` that handles asynchronous I/O. */ @@ -2416,7 +2423,7 @@ int main(int argc, char **argv) { #if GTK gtk_init(&argc, &argv); #elif CURSES - ta_tk = termkey_new(0, 0); + ta_tk = termkey_new(0, 0); // patched to auto-enable mouse mode (1002) setlocale(LC_CTYPE, ""); // for displaying UTF-8 characters properly initscr(); // raw()/cbreak() and noecho() are taken care of in libtermkey curs_set(0); // disable cursor when Scintilla has focus @@ -2498,14 +2505,13 @@ int main(int argc, char **argv) { #if !_WIN32 stderr = freopen("/dev/null", "w", stderr); // redirect stderr - // Prevent ^C from generating SIGINT. TERMKEY_FLAG_CTRLC is ineffective since - // initscr() overrides it. - struct termios term; - tcgetattr(0, &term), term.c_lflag &= ~ISIG, tcsetattr(0, TCSANOW, &term); - // Set terminal resize handler. + // Set terminal suspend, resume, and resize handlers, preventing any signals + // in them from causing interrupts. struct sigaction act; memset(&act, 0, sizeof(struct sigaction)); - act.sa_handler = resize, sigaction(SIGWINCH, &act, NULL); + act.sa_handler = t_signal, sigfillset(&act.sa_mask); + sigaction(SIGTSTP, &act, NULL), sigaction(SIGCONT, &act, NULL); + sigaction(SIGWINCH, &act, NULL); #else freopen("NUL", "w", stderr); // redirect stderr #endif |