summary refs log tree commit diff
path: root/bin/shotty.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2019-07-14 13:08:33 -0400
committerJune McEnroe <june@causal.agency>2019-07-14 13:08:33 -0400
commit9898219c44c4ae57ee8c3cd630935d5e971b431c (patch)
treec423d616a54cf0b5db1c041be3ffae8a60fd105f /bin/shotty.c
parentAdd shotty -d (diff)
downloadsrc-9898219c44c4ae57ee8c3cd630935d5e971b431c.tar.gz
src-9898219c44c4ae57ee8c3cd630935d5e971b431c.zip
Handle OSC in shotty
Diffstat (limited to 'bin/shotty.c')
-rw-r--r--bin/shotty.c45
1 files changed, 32 insertions, 13 deletions
diff --git a/bin/shotty.c b/bin/shotty.c
index a39c4f90..a75ba850 100644
--- a/bin/shotty.c
+++ b/bin/shotty.c
@@ -148,22 +148,24 @@ static char updateNUL(wchar_t ch) {
 
 enum {
 	CSI = '[',
+	ST  = '\\',
+	OSC = ']',
 	CUU = 'A',
-	CUD,
-	CUF,
-	CUB,
-	CNL,
-	CPL,
-	CHA,
-	CUP,
-	ED = 'J',
-	EL,
-	DL = 'M',
+	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,
+	SM  = 'h',
+	RM  = 'l',
+	SGR = 'm',
 };
 
 static char updateESC(wchar_t ch) {
@@ -176,6 +178,7 @@ static char updateESC(wchar_t ch) {
 		case '(': discard = true; return ESC;
 		case '=': return NUL;
 		case CSI: return CSI;
+		case OSC: return OSC;
 		default: warnx("unhandled ESC %lc", ch); return NUL;
 	}
 }
@@ -313,12 +316,28 @@ static char updateCSI(wchar_t ch) {
 	return NUL;
 }
 
+static char updateOSC(wchar_t ch) {
+	static bool esc;
+	switch (ch) {
+		break; case BEL: return NUL;
+		break; case ESC: esc = true;
+		break; case ST: {
+			if (!esc) break;
+			esc = false;
+			return NUL;
+		}
+	}
+	esc = false;
+	return NUL;
+}
+
 static void update(wchar_t ch) {
 	static char seq;
 	switch (seq) {
 		break; case NUL: seq = updateNUL(ch);
 		break; case ESC: seq = updateESC(ch);
 		break; case CSI: seq = updateCSI(ch);
+		break; case OSC: seq = updateOSC(ch);
 	}
 }