summary refs log tree commit diff
diff options
context:
space:
mode:
-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;
 }
mmary.c?h=1.4.0&id=c0dfaf1c281d0697ce43131343d7a9f170a61ff9&follow=1'>ui-summary: Pass filename to about-filterJason A. Donenfeld 2013-05-25ui-summary: Use default branch for readme if : prefixJason A. Donenfeld 2013-05-25cgit.c: Do not reset HOME after unsetting it.Jason A. Donenfeld 2013-05-25cgit.c: sync repo config printing with struct cgit_repoJason A. Donenfeld 2013-05-25git: update to 1.8.3John Keeping 2013-05-22cache.c: cache ls_cache output properlyJohn Keeping 2013-05-22tests: introduce strip_header() helper functionJohn Keeping 2013-05-22shared.c: use die_errno() where appropriateJohn Keeping 2013-05-22html.c: die when write failsJohn Keeping 2013-05-22ui-log: add <span/> around commit decorationsJohn Keeping 2013-05-22Makefile: fix parallel "make test"John Keeping 2013-05-18cache.c: fix cache_lsJohn Keeping 2013-05-13t0109: "function" is a bash-ismJohn Keeping 2013-05-13New mailing list.Jason A. Donenfeld 2013-04-30ui-snapshot: do not access $HOMEJason A. Donenfeld 2013-04-27t0001: validate Git -rcN version numbers correctlyJohn Keeping 2013-04-27git: update to 1.8.2.2John Keeping 2013-04-17scan-tree: fix regression in section-from-path=-1John Keeping 2013-04-15t0001: ignore ".dirty" suffix on Git versionJohn Keeping 2013-04-15tests: set TEST_OUTPUT_DIRECTORY to the CGit test directoryJohn Keeping 2013-04-15t0109: test more URLsJohn Keeping 2013-04-10cgitrc.5.txt: Specify when scan-path must be defined before.Jason A. Donenfeld 2013-04-10ui-snapshot.c: Prepend "V" when guessing ref namesLukas Fleischer 2013-04-10t0107: Skip ZIP tests if unzip(1) isn't availableLukas Fleischer 2013-04-10tests/: Do not use `sed -i`Lukas Fleischer 2013-04-10Add branch-sort and repo.branch-sort options.Jason A. Donenfeld 2013-04-10t0109: chain operations with &&John Keeping 2013-04-10cgit.c: Do not restore unset environment variablesLukas Fleischer 2013-04-09t0107: Use `tar -z` for gzip'ed archivesLukas Fleischer