summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-02-07 20:41:27 -0500
committerJune McEnroe <june@causal.agency>2020-02-07 20:41:27 -0500
commita26c9ae0bc4b74b250031492b6c5a0bee39dd4d8 (patch)
tree7b5ae92c85eb6c2daebb3b30a04bdd4357d43e41
parentOnly treat the first tab as the alignment point (diff)
downloadcatgirl-a26c9ae0bc4b74b250031492b6c5a0bee39dd4d8.tar.gz
catgirl-a26c9ae0bc4b74b250031492b6c5a0bee39dd4d8.zip
Use define_key for meta keys
This will allow distinguishing meta from escape via ESCDELAY (which
should probably be set to something quite a lot shorter than its
default).
Diffstat (limited to '')
-rw-r--r--ui.c60
1 files changed, 35 insertions, 25 deletions
diff --git a/ui.c b/ui.c
index f556719..147381e 100644
--- a/ui.c
+++ b/ui.c
@@ -146,13 +146,6 @@ static short colorPair(short fg, short bg) {
 	return colorPairs++;
 }
 
-enum {
-	KeyFocusIn = KEY_MAX + 1,
-	KeyFocusOut,
-	KeyPasteOn,
-	KeyPasteOff,
-};
-
 // XXX: Assuming terminals will be fine with these even if they're unsupported,
 // since they're "private" modes.
 static const char *EnterFocusMode = "\33[?1004h";
@@ -188,6 +181,30 @@ static void errExit(int eval) {
 	reset_shell_mode();
 }
 
+#define ENUM_KEY \
+	X(KeyMeta0, "\0330") \
+	X(KeyMeta1, "\0331") \
+	X(KeyMeta2, "\0332") \
+	X(KeyMeta3, "\0333") \
+	X(KeyMeta4, "\0334") \
+	X(KeyMeta5, "\0335") \
+	X(KeyMeta6, "\0336") \
+	X(KeyMeta7, "\0337") \
+	X(KeyMeta8, "\0338") \
+	X(KeyMeta9, "\0339") \
+	X(KeyMetaM, "\33m") \
+	X(KeyFocusIn, "\33[I") \
+	X(KeyFocusOut, "\33[O") \
+	X(KeyPasteOn, "\33[200~") \
+	X(KeyPasteOff, "\33[201~")
+
+enum {
+	KeyMax = KEY_MAX,
+#define X(id, seq) id,
+	ENUM_KEY
+#undef X
+};
+
 void uiInit(void) {
 	initscr();
 	cbreak();
@@ -200,10 +217,9 @@ void uiInit(void) {
 		to_status_line = "\33]2;";
 		from_status_line = "\7";
 	}
-	define_key("\33[I", KeyFocusIn);
-	define_key("\33[O", KeyFocusOut);
-	define_key("\33[200~", KeyPasteOn);
-	define_key("\33[201~", KeyPasteOff);
+#define X(id, seq) define_key(seq, id);
+	ENUM_KEY
+#undef X
 
 	colorInit();
 	status = newwin(1, COLS, 0, 0);
@@ -556,20 +572,19 @@ static void keyCode(int code) {
 		break; case KeyPasteOn:; // TODO
 		break; case KeyPasteOff:; // TODO
 
+		break; case KeyMetaM: waddch(windows.active->pad, '\n');
+
 		break; case KEY_BACKSPACE: edit(id, EditErase, 0);
 		break; case KEY_END: edit(id, EditEnd, 0);
 		break; case KEY_ENTER: edit(id, EditEnter, 0);
 		break; case KEY_HOME: edit(id, EditHome, 0);
 		break; case KEY_LEFT: edit(id, EditLeft, 0);
 		break; case KEY_RIGHT: edit(id, EditRight, 0);
-	}
-}
-
-static void keyMeta(wchar_t ch) {
-	switch (ch) {
-		break; case L'm': waddch(windows.active->pad, '\n');
+		
 		break; default: {
-			if (ch >= L'0' && ch <= L'9') uiShowNum(ch - L'0');
+			if (code >= KeyMeta0 && code <= KeyMeta9) {
+				uiShowNum(code - KeyMeta0);
+			}
 		}
 	}
 }
@@ -602,15 +617,10 @@ static void keyStyle(wchar_t ch) {
 void uiRead(void) {
 	int ret;
 	wint_t ch;
-	static bool meta, style;
+	static bool style;
 	while (ERR != (ret = wget_wch(input, &ch))) {
 		if (ret == KEY_CODE_YES) {
 			keyCode(ch);
-		} else if (ch == '\33') {
-			meta = true;
-			continue;
-		} else if (meta) {
-			keyMeta(ch);
 		} else if (ch == (L'Z' ^ L'@')) {
 			style = true;
 			continue;
@@ -621,7 +631,7 @@ void uiRead(void) {
 		} else {
 			edit(windows.active->id, EditInsert, ch);
 		}
-		meta = style = false;
+		style = false;
 	}
 	inputUpdate();
 }
ss='logheader'>2020-10-27Switch gr alias back to git rebaseJune McEnroe I always type out git reset and sometimes still expect gr to be rebase... Never got used to it I guess. 2020-10-27Allow cd host: to cd to same path over sshJune McEnroe 2020-10-27Use SendEnv for cd host:pathJune McEnroe Works properly for weird paths, etc. 2020-10-27Allow cd host:path over sshJune McEnroe Requires AcceptEnv SSH_CD in the remote sshd_config. 2020-10-07Use mandoc -T utf8 for text.June McEnroe Don't depend on LANG being set. 2020-09-20Add The Awakened KingdomJune McEnroe A cute extra novella. Finally finished this series. 2020-09-12Move /opt/local back, cheat port select to use system manJune McEnroe This is not really how you're supposed to use the select system, I don't think, since the mandoc package actually creates those files, but it does work. This lets me actually use the git installed by MacPorts. 2020-09-12Move /opt/local behind /usr againJune McEnroe The reason I did this with pkgsrc was because I actually don't want the man(1) from mandoc, since it won't follow MANSECT. Same applies to MacPorts. I wish I could disable its man(1) with a variant or whatever. 2020-09-12Enable toc in cgit renderings of man pagesJune McEnroe But keep it disabled for READMEs since they always use non-standard sections and the TOC is just distracting there, I think. Also add the style so its h1 is the same size as the ones inside sections... 2020-09-11Install mandoc on macOSJune McEnroe 2020-09-11Rewrite install script yet againJune McEnroe 2020-09-11Remove NetBSD from install scriptJune McEnroe I never use it. 2020-09-11Use MacPorts rather than pkgsrcJune McEnroe My system is probably such a mess now... 2020-09-11Add debian VM name to sshJune McEnroe 2020-09-11Add influencer tweetJune McEnroe 2020-09-10Add The Kingdom of GodsJune McEnroe Reading has really slowed down :( 2020-09-07Add SunglassesJune McEnroe An IRC find. 2020-09-06Add Between the BreathsJune McEnroe One of those good songs from a soundtrack of a film that probably isn't? The summary sounds a lot more interesting than the title implies, at least. 2020-09-04Open /dev/tty in nudgeJune McEnroe This makes it work even when it's run connected to a pipe, i.e. as the notify command of catgirl... 2020-09-04Add nudgeJune McEnroe 2020-09-03Build fbclock with -lzJune McEnroe I guess this got lost somewhere, long ago... 2020-08-29Add tweets from retweetsJune McEnroe