summary refs log tree commit diff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--term.c129
1 files changed, 68 insertions, 61 deletions
diff --git a/term.c b/term.c
index 719e630..f4bb566 100644
--- a/term.c
+++ b/term.c
@@ -26,6 +26,8 @@
 
 #include "stream.h"
 
+#define E(c, e) e = c
+
 enum C0 {
 	NUL, SOH, STX, ETX, EOT, ENQ, ACK, BEL,
 	BS, HT, NL, VT, NP, CR, SO, SI,
@@ -131,13 +133,13 @@ static char updateNUL(wchar_t ch) {
 }
 
 enum C1 {
-	DECSC = '7',
-	DECRC = '8',
-	IND = 'D',
-	RI  = 'M',
-	CSI = '[',
-	ST  = '\\',
-	OSC = ']',
+	E('7', DECSC),
+	E('8', DECRC),
+	E('D', IND),
+	E('M', RI),
+	E('[', CSI),
+	E('\\', ST),
+	E(']', OSC),
 };
 
 static char updateESC(wchar_t ch) {
@@ -167,31 +169,35 @@ static char updateESC(wchar_t ch) {
 }
 
 enum SGR {
-	Reset,
-	SetBold,
-	SetDim,
-	SetItalic,
-	SetUnderline,
-	SetBlink,
-	SetReverse = 7,
-	UnsetBoldDim = 22,
-	UnsetItalic,
-	UnsetUnderline,
-	UnsetBlink,
-	UnsetReverse = 27,
-	SetFg0 = 30,
-	SetFg7 = 37,
-	SetFg,
-	ResetFg,
-	SetBg0,
-	SetBg7 = 47,
-	SetBg,
-	ResetBg,
-	SetFg8 = 90,
-	SetFg15 = 97,
-	SetBg8 = 100,
-	SetBg15 = 107,
-	Color256 = 5,
+	E(0, Reset),
+	E(1, SetBold),
+	E(2, SetDim),
+	E(3, SetItalic),
+	E(4, SetUnderline),
+	E(5, SetBlink),
+	E(7, SetReverse),
+
+	E(22, UnsetBoldDim),
+	E(23, UnsetItalic),
+	E(24, UnsetUnderline),
+	E(25, UnsetBlink),
+	E(27, UnsetReverse),
+
+	E(30, SetFg0),
+	E(37, SetFg7),
+	E(38, SetFg),
+	E(39, ResetFg),
+	E(40, SetBg0),
+	E(47, SetBg7),
+	E(48, SetBg),
+	E(49, ResetBg),
+
+	E(90, SetFg8),
+	E(97, SetFg15),
+	E(100, SetBg8),
+	E(107, SetBg15),
+
+	E(5, Color256),
 };
 
 static void updateSGR(uint ps[], uint n) {
@@ -245,38 +251,39 @@ static void updateSGR(uint ps[], uint n) {
 enum { CSIMax = 5 + 2 * 3 };
 
 enum CSI {
-	DEC = '?',
-	ICH = '@',
-	CUU = 'A',
-	CUD,
-	CUF,
-	CUB,
-	CNL,
-	CPL,
-	CHA,
-	CUP,
-	ED  = 'J',
-	EL,
-	IL  = 'L',
-	DL  = 'M',
-	DCH = 'P',
-	SU  = 'S',
-	SD  = 'T',
-	ECH = 'X',
-	VPA = 'd',
-	SM  = 'h',
-	RM  = 'l',
-	SGR,
-	DECSTBM = 'r',
-	DECSET = DEC + SM,
-	DECRST = DEC + RM,
+	E('?', DEC),
+	E('@', ICH),
+	E('A', CUU),
+	E('B', CUD),
+	E('C', CUF),
+	E('D', CUB),
+	E('E', CNL),
+	E('F', CPL),
+	E('G', CHA),
+	E('H', CUP),
+	E('J', ED),
+	E('K', EL),
+	E('L', IL),
+	E('M', DL),
+	E('P', DCH),
+	E('S', SU),
+	E('T', SD),
+	E('X', ECH),
+	E('d', VPA),
+	E('h', SM),
+	E('l', RM),
+	E('m', SGR),
+	E('r', DECSTBM),
+	E(DEC + SM, DECSET),
+	E(DEC + RM, DECRST),
 };
 
 enum Mode {
-	IRM = 4,
-	DECCKM = 1,
-	DECAWM = 7,
-	DECTCEM = 25,
+	E(4, IRM),
+
+	E(1, DECCKM),
+	E(7, DECAWM),
+	E(25, DECTCEM),
 };
 
 static char updateCSI(wchar_t ch) {