summary refs log tree commit diff
path: root/bin/scheme.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2019-07-06 17:23:14 -0400
committerJune McEnroe <june@causal.agency>2019-07-06 17:23:14 -0400
commit34f31c38043f3a682be9466dd57fee4523cdf6f7 (patch)
tree4cd0ada75903940d3a4c9ae886f6aa4519dd2011 /bin/scheme.c
parentAdd diff syntax to hi (diff)
downloadsrc-34f31c38043f3a682be9466dd57fee4523cdf6f7.tar.gz
src-34f31c38043f3a682be9466dd57fee4523cdf6f7.zip
Add CSS output to scheme
Diffstat (limited to 'bin/scheme.c')
-rw-r--r--bin/scheme.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/bin/scheme.c b/bin/scheme.c
index 43fc26fc..b3d1f60d 100644
--- a/bin/scheme.c
+++ b/bin/scheme.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2018  C. McEnroe <june@causal.agency>
+/* Copyright (C) 2018, 2019  C. McEnroe <june@causal.agency>
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as published by
@@ -174,6 +174,18 @@ static void outputMintty(const struct HSV *hsv, uint len) {
 	}
 }
 
+static void outputCSS(const struct HSV *hsv, uint len) {
+	for (uint i = 0; i < len; ++i) {
+		struct RGB rgb = convert(hsv[i]);
+		printf(
+			".fg%u { color: #" FORMAT_RGB "; }\n"
+			".bg%u { background-color: #" FORMAT_RGB "; }\n",
+			i, rgb.r, rgb.g, rgb.b,
+			i, rgb.r, rgb.g, rgb.b
+		);
+	}
+}
+
 enum {
 	SwatchWidth = 64,
 	SwatchHeight = 64,
@@ -214,7 +226,7 @@ int main(int argc, char *argv[]) {
 	uint len = 16;
 
 	int opt;
-	while (0 < (opt = getopt(argc, argv, "acghilmp:tx"))) {
+	while (0 < (opt = getopt(argc, argv, "acghilmp:stx"))) {
 		switch (opt) {
 			break; case 'a': len = 16;
 			break; case 'c': output = outputEnum;
@@ -229,6 +241,7 @@ int main(int argc, char *argv[]) {
 				hsv = &scheme[p];
 				len = 1;
 			}
+			break; case 's': output = outputCSS;
 			break; case 't': len = SchemeLen;
 			break; case 'x': output = outputRGB;
 			break; default:  return EX_USAGE;