summary refs log tree commit diff
path: root/term.c
diff options
context:
space:
mode:
Diffstat (limited to 'term.c')
-rw-r--r--term.c31
1 files changed, 16 insertions, 15 deletions
diff --git a/term.c b/term.c
index 1266328..4f62d20 100644
--- a/term.c
+++ b/term.c
@@ -21,7 +21,6 @@
 
 #include "chat.h"
 
-#define PAIR(a, b) (((short)(a) << 8) | ((short)(b) & 0xFF))
 
 static bool xterm;
 
@@ -48,20 +47,22 @@ void termMode(enum TermMode mode, bool set) {
 	}
 }
 
+#define ESC '\33'
+#define T(s, i) ((s) << 8 | (i))
+
 enum TermEvent termEvent(char ch) {
-	static char state = '\0';
-	switch (PAIR(state, ch)) {
-		break; case PAIR('\0', '\33'): state = '\33';
-		break; case PAIR('\33', '['):  state = '[';
-		break; case PAIR('[', 'I'):    state = '\0'; return TERM_FOCUS_IN;
-		break; case PAIR('[', 'O'):    state = '\0'; return TERM_FOCUS_OUT;
-		break; case PAIR('[', '2'):    state = '2';
-		break; case PAIR('2', '0'):    state = '0';
-		break; case PAIR('0', '0'):    state = '0';
-		break; case PAIR('0', '~'):    state = '\0'; return TERM_PASTE_START;
-		break; case PAIR('0', '1'):    state = '1';
-		break; case PAIR('1', '~'):    state = '\0'; return TERM_PASTE_END;
-		break; default:                state = '\0';
+	static int state = 0;
+	switch (T(state, ch)) {
+		case T(0, ESC): state = 1; return 0;
+		case T(1, '['): state = 2; return 0;
+		case T(2, 'I'): state = 0; return TERM_FOCUS_IN;
+		case T(2, 'O'): state = 0; return TERM_FOCUS_OUT;
+		case T(2, '2'): state = 3; return 0;
+		case T(3, '0'): state = 4; return 0;
+		case T(4, '0'): state = 5; return 0;
+		case T(5, '~'): state = 0; return TERM_PASTE_START;
+		case T(4, '1'): state = 6; return 0;
+		case T(6, '~'): state = 0; return TERM_PASTE_END;
+		default:        state = 0; return 0;
 	}
-	return TERM_NONE;
 }
ef='/catgirl/commit/ui.c?h=2.0a&id=55866686a80d33e19434a453f583bf716b1d4ac0&follow=1'>Call def_prog_mode after termNoFlowJune McEnroe 2019-02-22Move IRC formatting reset to C-sJune McEnroe 2019-02-22Disable terminal flow controlJune McEnroe 2019-02-22Bind up and down arrows to scrollJune McEnroe 2019-02-22Remove topic TODOJune McEnroe 2019-02-22Add /znc commandJune McEnroe 2019-02-22Update status line after scrolling and term eventsJune McEnroe 2019-02-22Reorganize input.cJune McEnroe 2019-02-22Fix name of <raw> window in man pageJune McEnroe 2019-02-22Rename global tags with angle bracketsJune McEnroe 2019-02-22Show status window while connectingJune McEnroe 2019-02-22Reorganize UI code for the umpteenth timeJune McEnroe 2019-02-21Replace "view" with "window"June McEnroe 2019-02-21Remove ROT13June McEnroe 2019-02-21Clean up man pageJune McEnroe 2019-01-26Draw UI before connectingJune McEnroe 2019-01-25Avoid unused variable warnings with getyxJune McEnroe 2019-01-25Add GNU/Linux build instructionsJune McEnroe