summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2019-02-25 12:51:21 -0500
committerJune McEnroe <june@causal.agency>2019-02-25 12:51:21 -0500
commit9d6f9d76c3c57dd2da5f4b2fcab7526d520a9fd4 (patch)
treec4b2863293a0b05b6666e291000bc95ae3fe7930
parentScroll by full pages with PageUp/PageDown (diff)
downloadcatgirl-9d6f9d76c3c57dd2da5f4b2fcab7526d520a9fd4.tar.gz
catgirl-9d6f9d76c3c57dd2da5f4b2fcab7526d520a9fd4.zip
Refactor uiRead
Centralizes the branching.
Diffstat (limited to '')
-rw-r--r--ui.c66
1 files changed, 33 insertions, 33 deletions
diff --git a/ui.c b/ui.c
index f89c4c4..e31e824 100644
--- a/ui.c
+++ b/ui.c
@@ -444,41 +444,21 @@ static void keyCode(wchar_t code) {
 	uiStatus();
 }
 
-static void keyChar(wchar_t ch) {
+static void keyMeta(wchar_t ch) {
 	struct Window *win = windows.active;
-	if (ch < 0200) {
-		enum TermEvent event = termEvent((char)ch);
-		switch (event) {
-			break; case TermFocusIn:  if (win) windowUnmark(win);
-			break; case TermFocusOut: if (win) windowMark(win);
-			break; default: {}
-		}
-		if (event) {
-			uiStatus();
-			return;
-		}
-	}
-	if (ch == Del) ch = L'\b';
-
-	static bool meta;
-	if (ch == Esc) {
-		meta = true;
-		return;
-	}
-	if (meta) {
-		meta = false;
-		if (ch >= L'0' && ch <= L'9') uiShowNum(ch - L'0', false);
-		if (!win) return;
-		switch (ch) {
-			break; case L'b':  edit(win->tag, EditBackWord, 0);
-			break; case L'f':  edit(win->tag, EditForeWord, 0);
-			break; case L'\b': edit(win->tag, EditKillBackWord, 0);
-			break; case L'd':  edit(win->tag, EditKillForeWord, 0);
-			break; case L'm':  uiLog(win->tag, UICold, L"");
-		}
-		return;
+	if (ch >= L'0' && ch <= L'9') uiShowNum(ch - L'0', false);
+	if (!win) return;
+	switch (ch) {
+		break; case L'b':  edit(win->tag, EditBackWord, 0);
+		break; case L'f':  edit(win->tag, EditForeWord, 0);
+		break; case L'\b': edit(win->tag, EditKillBackWord, 0);
+		break; case L'd':  edit(win->tag, EditKillForeWord, 0);
+		break; case L'm':  uiLog(win->tag, UICold, L"");
 	}
+}
 
+static void keyChar(wchar_t ch) {
+	struct Window *win = windows.active;
 	if (ch == CTRL(L'L')) clearok(curscr, true);
 	if (!win) return;
 	switch (ch) {
@@ -511,10 +491,30 @@ static void keyChar(wchar_t ch) {
 
 void uiRead(void) {
 	if (ui.hide) uiShow();
+	static bool meta;
 	int ret;
 	wint_t ch;
+	enum TermEvent event;
 	while (ERR != (ret = wget_wch(ui.input, &ch))) {
-		(ret == KEY_CODE_YES ? keyCode(ch) : keyChar(ch));
+		if (ret == KEY_CODE_YES) {
+			keyCode(ch);
+		} else if (ch < 0200 && (event = termEvent((char)ch))) {
+			struct Window *win = windows.active;
+			switch (event) {
+				break; case TermFocusIn:  if (win) windowUnmark(win);
+				break; case TermFocusOut: if (win) windowMark(win);
+				break; default: {}
+			}
+			uiStatus();
+		} else if (ch == Esc) {
+			meta = true;
+			continue;
+		} else if (meta) {
+			keyMeta(ch == Del ? '\b' : ch);
+		} else {
+			keyChar(ch == Del ? '\b' : ch);
+		}
+		meta = false;
 	}
 	uiPrompt(false);
 }
lass='logsubject'>Add xx -p optionJune McEnroe 2019-05-27Add FrontierJune McEnroe 2019-05-27Break nicks with ZWNJJune McEnroe This should prevent bad wrapping. 2019-05-26Add DawnJune McEnroe 2019-05-20Declare vasprintf(3) for GNUJune McEnroe who the fuck is scraeming "#define _GNU_SOURCE" at my house. show yourself, coward. i will never #define _GNU_SOURCE 2019-05-20Fix comparison warning in ttpreJune McEnroe 2019-05-20Add AuthorityJune McEnroe 2019-05-19Specify precedence of unary versions of operatorsJune McEnroe 2019-05-18Add compound assignment operators to orderJune McEnroe 2019-05-15Support simple assignment in orderJune McEnroe 2019-05-15Implement sizeof in orderJune McEnroe 2019-05-15Add orderJune McEnroe 2019-05-12Add T suffix in bitJune McEnroe 2019-05-10Highlight yacc and lex files as CJune McEnroe Their %-prefixed directives should probably be highlighted Macro. 2019-05-10Use val instead of suboptargJune McEnroe suboptarg doesn't exist in GNU. Hopefully BSD getsubopt also sets val on failure? 2019-05-09Add Parable of the SowerJune McEnroe 2019-05-07Add bit without buildJune McEnroe Need to do some stuff in the Makefile for lex and yacc and generating HTML pages for it. 2019-05-04Fix MANDIR typoJune McEnroe 2019-05-04Move relay to binJune McEnroe