summary refs log tree commit diff
path: root/bin/shotty.l
diff options
context:
space:
mode:
Diffstat (limited to 'bin/shotty.l')
-rw-r--r--bin/shotty.l23
1 files changed, 18 insertions, 5 deletions
diff --git a/bin/shotty.l b/bin/shotty.l
index ab1ce202..070022a2 100644
--- a/bin/shotty.l
+++ b/bin/shotty.l
@@ -431,9 +431,17 @@ static void update(enum Code cc) {
 }
 
 static bool bright;
+static bool colors;
 static int defaultBg = 0;
 static int defaultFg = 7;
 
+static const char *Inline[16] = {
+	"#000000;", "#CD0000;", "#00CD00;", "#CDCD00;",
+	"#0000EE;", "#CD00CD;", "#00CDCD;", "#E5E5E5;",
+	"#7F7F7F;", "#FF0000;", "#00FF00;", "#FFFF00;",
+	"#5C5CFF;", "#FF00FF;", "#00FFFF;", "#FFFFFF;",
+};
+
 static void span(const struct Cell *prev, const struct Cell *cell) {
 	if (
 		!prev ||
@@ -443,18 +451,22 @@ static void span(const struct Cell *prev, const struct Cell *cell) {
 	) {
 		if (prev) printf("</span>");
 		int attr = cell->attr;
-		int bg = (cell->bg < 0 ? defaultBg : cell->bg);
-		int fg = (cell->fg < 0 ? defaultFg : cell->fg);
+		int bg = (attr & Reverse ? cell->fg : cell->bg);
+		int fg = (attr & Reverse ? cell->bg : cell->fg);
+		if (bg < 0) bg = defaultBg;
+		if (fg < 0) fg = defaultFg;
 		if (bright && cell->attr & Bold) {
 			if (fg < 8) fg += 8;
 			attr &= ~Bold;
 		}
 		printf(
-			Q(<span style="%s%s%s" class="bg%d fg%d">),
+			Q(<span class="bg%d fg%d" style="%s%s%s%s%s%s%s">),
+			bg, fg,
 			(attr & Bold ? "font-weight:bold;" : ""),
 			(attr & Italic ? "font-style:italic;" : ""),
 			(attr & Underline ? "text-decoration:underline;" : ""),
-			(attr & Reverse ? fg : bg), (attr & Reverse ? bg : fg)
+			(colors ? "background-color:" : ""), (colors ? Inline[bg] : ""),
+			(colors ? "color:" : ""), (colors ? Inline[fg] : "")
 		);
 	}
 	switch (cell->ch) {
@@ -496,13 +508,14 @@ int main(int argc, char *argv[]) {
 	bool size = false;
 	bool hide = false;
 
-	for (int opt; 0 < (opt = getopt(argc, argv, "Bb:df:h:nsw:"));) {
+	for (int opt; 0 < (opt = getopt(argc, argv, "Bb:df:h:insw:"));) {
 		switch (opt) {
 			break; case 'B': bright = true;
 			break; case 'b': defaultBg = atoi(optarg);
 			break; case 'd': debug = true;
 			break; case 'f': defaultFg = atoi(optarg);
 			break; case 'h': rows = atoi(optarg);
+			break; case 'i': colors = true;
 			break; case 'n': hide = true;
 			break; case 's': size = true;
 			break; case 'w': cols = atoi(optarg);
6-05 15:37:49 +0200'>2019-06-05git: update to v2.21.0Christian Hesse 2019-06-05ui-ssdiff: ban strncat()Christian Hesse 2019-06-05global: make 'char *path' const where possibleChristian Hesse 2019-05-20ui-shared: restrict to 15 levelsJason A. Donenfeld 2019-02-23ui-diff,ui-tag: don't use htmlf with non-formatted stringsChris Mayo 2019-02-23ui-ssdiff: resolve HTML5 validation errorsChris Mayo 2019-01-03filters: migrate from luacrypto to luaosslJason A. Donenfeld 2019-01-02ui-shared: fix broken sizeof in title setting and rewriteJason A. Donenfeld 2018-12-09git: update to v2.20.0Christian Hesse 2018-11-25ui-blame: set repo for sbJason A. Donenfeld 2018-11-25auth-filter: pass url with query string attachedJason A. Donenfeld 2018-11-21git: use xz compressed archive for downloadChristian Hesse 2018-10-12git: update to v2.19.1Christian Hesse 2018-09-11ui-ssdiff: ban strcat()Christian Hesse 2018-09-11ui-ssdiff: ban strncpy()Christian Hesse 2018-09-11ui-shared: ban strcat()Christian Hesse 2018-09-11ui-patch: ban sprintf()Christian Hesse 2018-09-11ui-log: ban strncpy()Christian Hesse 2018-09-11ui-log: ban strcpy()Christian Hesse 2018-09-11parsing: ban sprintf()Christian Hesse 2018-09-11parsing: ban strncpy()Christian Hesse 2018-08-28filters: generate anchor links from markdownChristian Hesse 2018-08-03Bump version.Jason A. Donenfeld 2018-08-03clone: fix directory traversalJason A. Donenfeld 2018-08-03config: record repo.snapshot-prefix in the per-repo configKonstantin Ryabitsev