summary refs log tree commit diff
path: root/bin/shotty.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2019-07-14 14:26:00 -0400
committerJune McEnroe <june@causal.agency>2019-07-14 14:26:00 -0400
commitcc36a11e38b65ff512bf6e66f8c44d9ac8e55446 (patch)
treeb78c893817200a34a81796de4564967c033c4e46 /bin/shotty.c
parentIgnore CSI t (diff)
downloadsrc-cc36a11e38b65ff512bf6e66f8c44d9ac8e55446.tar.gz
src-cc36a11e38b65ff512bf6e66f8c44d9ac8e55446.zip
Add CSI names to shotty -d
Diffstat (limited to 'bin/shotty.c')
-rw-r--r--bin/shotty.c60
1 files changed, 38 insertions, 22 deletions
diff --git a/bin/shotty.c b/bin/shotty.c
index fb5482ca..a81e18c0 100644
--- a/bin/shotty.c
+++ b/bin/shotty.c
@@ -146,26 +146,38 @@ static char updateNUL(wchar_t ch) {
 	return NUL;
 }
 
+#define ENUM_CHARS \
+	X('?', DEC) \
+	X('A', CUU) \
+	X('B', CUD) \
+	X('C', CUF) \
+	X('D', CUB) \
+	X('E', CNL) \
+	X('F', CPL) \
+	X('G', CHA) \
+	X('H', CUP) \
+	X('J', ED)  \
+	X('K', EL)  \
+	X('M', DL)  \
+	X('P', DCH) \
+	X('[', CSI) \
+	X('\\', ST) \
+	X(']', OSC) \
+	X('d', VPA) \
+	X('h', SM)  \
+	X('l', RM)  \
+	X('m', SGR)
+
 enum {
-	CSI = '[',
-	ST  = '\\',
-	OSC = ']',
-	CUU = 'A',
-	CUD = 'B',
-	CUF = 'C',
-	CUB = 'D',
-	CNL = 'E',
-	CPL = 'F',
-	CHA = 'G',
-	CUP = 'H',
-	ED  = 'J',
-	EL  = 'K',
-	DL  = 'M',
-	DCH = 'P',
-	VPA = 'd',
-	SM  = 'h',
-	RM  = 'l',
-	SGR = 'm',
+#define X(ch, name) name = ch,
+	ENUM_CHARS
+#undef X
+};
+
+static const char *Name[128] = {
+#define X(ch, name) [ch] = #name,
+	ENUM_CHARS
+#undef X
 };
 
 static char updateESC(wchar_t ch) {
@@ -185,7 +197,7 @@ static char updateESC(wchar_t ch) {
 
 static char updateCSI(wchar_t ch) {
 	static bool dec;
-	if (ch == '?') {
+	if (ch == DEC) {
 		dec = true;
 		return CSI;
 	}
@@ -305,11 +317,15 @@ static char updateCSI(wchar_t ch) {
 	}
 
 	if (debug) {
-		printf("CSI %s", (dec ? "? " : ""));
+		printf("CSI %s", (dec ? "DEC " : ""));
 		for (uint i = 0; i < n; ++i) {
 			printf("%s%u ", (i ? "; " : ""), ps[i]);
 		}
-		printf("%lc\n", ch);
+		if (ch < 128 && Name[ch]) {
+			printf("%s\n", Name[ch]);
+		} else {
+			printf("%lc\n", ch);
+		}
 		html(true);
 	}