From eb5de3fc6818026daf64d8880cce97d941a96f3f Mon Sep 17 00:00:00 2001
From: mitchell <70453897+667e-11@users.noreply.github.com>
Date: Tue, 23 Dec 2014 23:27:49 -0500
Subject: 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.
---
core/ui.lua | 12 +---------
modules/textadept/keys.lua | 58 ++++++++++++++++++++++------------------------
src/termkey.patch | 52 ++++++++++++++++++++++++++---------------
src/textadept.c | 38 +++++++++++++++++-------------
4 files changed, 84 insertions(+), 76 deletions(-)
diff --git a/core/ui.lua b/core/ui.lua
index 4574fca0..c215ae09 100644
--- a/core/ui.lua
+++ b/core/ui.lua
@@ -401,18 +401,8 @@ events_connect(events.BUFFER_DELETED, function()
if i and _BUFFERS[buffer] ~= i then view:goto_buffer(i) end
end)
--- Enables and disables mouse mode in curses and focuses and resizes views based
--- on mouse events.
+-- Focuses and resizes views based on mouse events in curses.
if CURSES then
- if not WIN32 then
- io.stdout:write("\x1b[?1002h") -- enable mouse mode
- io.stdout:flush()
- events.connect(events.QUIT, function()
- io.stdout:write("\x1b[?1002l") -- disable mouse mode
- io.stdout:flush()
- end)
- end
-
-- Retrieves the view or split at the given terminal coordinates.
-- @param view View or split to test for coordinates within.
-- @param y The y terminal coordinate.
diff --git a/modules/textadept/keys.lua b/modules/textadept/keys.lua
index 63496632..7b306d76 100644
--- a/modules/textadept/keys.lua
+++ b/modules/textadept/keys.lua
@@ -26,8 +26,8 @@ local M = {}
-- None |None |None |Load session...
-- Ctrl+Q |⌘Q |^Q |Quit
-- **Edit** | | |
--- Ctrl+Z
Alt+Bksp |⌘Z |^Z |Undo
--- Ctrl+Y
Ctrl+Shift+Z |⌘⇧Z |^Y |Redo
+-- Ctrl+Z
Alt+Bksp |⌘Z |M-Z |Undo
+-- Ctrl+Y
Ctrl+Shift+Z |⌘⇧Z |M-S-Z
^Y |Redo
-- Ctrl+X
Shift+Del |⌘X
⇧⌦|^X |Cut
-- Ctrl+C
Ctrl+Ins |⌘C |^C |Copy
-- Ctrl+V
Shift+Ins |⌘V |^V |Paste
@@ -191,30 +191,28 @@ local M = {}
-- N/A |N/A |^] |Swap caret and mark anchor
-- **UTF-8 Input** | | |
-- Ctrl+Shift+U *xxxx* Enter|⌘⇧U *xxxx* ↩|M-U *xxxx* Enter|Insert U-*xxxx* char.
--- **Entry Fields**| | |
--- Left |⇠
^B |^B
Left |Cursor left
--- Right |⇢
^F |^F
Right|Cursor right
--- Del |⌦ |Del |Delete forward
--- Bksp |⌫ |^H
Bksp |Delete back
--- Ctrl+V |⌘V |^V |Paste
--- N/A |N/A |^X |Cut all
--- N/A |N/A |^Y |Copy all
--- N/A |N/A |^U |Erase all
--- Home |↖
⌘⇠
^A|^A |Home
--- End |↘
⌘⇢
^E|^E |End
--- N/A |N/A |^T |Transpose characters
--- N/A |N/A |^L |Refresh
--- **Find Fields**| | |
--- N/A |N/A|Tab |Focus find buttons
--- N/A |N/A|S-Tab|Focus replace buttons
--- Tab |⇥ |Down |Focus replace field
--- Shift+Tab |⇧⇥ |Up |Focus find field
--- Down |⇣ |^P |Cycle back through find/replace history
--- Up |⇡ |^N |Cycle forward through find/replace history
--- N/A |N/A|F1 |Toggle "Match Case"
--- N/A |N/A|F2 |Toggle "Whole Word"
--- N/A |N/A|F3 |Toggle "Lua Pattern"
--- N/A |N/A|F4 |Toggle "Find in Files"
+-- **Find Fields**| | |
+-- Left |⇠
^B |^B
Left |Cursor left
+-- Right |⇢
^F |^F
Right|Cursor right
+-- Del |⌦ |Del |Delete forward
+-- Bksp |⌫ |^H
Bksp |Delete back
+-- Ctrl+V |⌘V |^V |Paste
+-- N/A |N/A |^X |Cut all
+-- N/A |N/A |^Y |Copy all
+-- N/A |N/A |^U |Erase all
+-- Home |↖
⌘⇠
^A|^A |Home
+-- End |↘
⌘⇢
^E|^E |End
+-- N/A |N/A |^T |Transpose characters
+-- N/A |N/A |Tab |Focus find buttons
+-- N/A |N/A |S-Tab |Focus replace buttons
+-- Tab |⇥ |Down |Focus replace field
+-- Shift+Tab |⇧⇥ |Up |Focus find field
+-- Down |⇣ |^P |Cycle back through history
+-- Up |⇡ |^N |Cycle forward through history
+-- N/A |N/A |F1 |Toggle "Match Case"
+-- N/A |N/A |F2 |Toggle "Whole Word"
+-- N/A |N/A |F3 |Toggle "Lua Pattern"
+-- N/A |N/A |F4 |Toggle "Find in Files"
--
-- †: Ctrl+Enter in Win32 curses.
module('textadept.keys')]]
@@ -370,9 +368,9 @@ for _, f in ipairs(menu_buffer_functions) do buffer[f] = buffer[f] end
-- are.
--
-- Unassigned keys (~ denotes keys reserved by the operating system):
--- c: g~~ ~
+-- c: g~~ ~ ~
-- cm: cd g~~ k ~ q t yz
--- m: e J qQ sS vVw yYzZ_ +
+-- m: e J qQ sS vVw yY _ +
-- Note: m[befhstv] may be used by Linux/BSD GUI terminals for menu access.
--
-- CTRL = 'c' (Control ^)
@@ -397,9 +395,9 @@ keys[not OSX and (not CURSES and 'cW' or 'cmw') or 'mW'] = io.close_all_buffers
keys[not OSX and 'cq' or 'mq'] = quit
-- Edit.
-keys[not OSX and 'cz' or 'mz'] = buffer.undo
+keys[not OSX and not CURSES and 'cz' or 'mz'] = buffer.undo
if not OSX then keys.cy = buffer.redo end
-if not CURSES then keys[not OSX and 'cZ' or 'mZ'] = buffer.redo end
+keys[not OSX and not CURSES and 'cZ' or 'mZ'] = buffer.redo
keys[not OSX and 'cx' or 'mx'] = buffer.cut
keys[not OSX and 'cc' or 'mc'] = buffer.copy
keys[not OSX and 'cv' or 'mv'] = buffer.paste
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
@@ -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
--
cgit v1.2.3