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);
 }