summary refs log tree commit diff
path: root/bin
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
commitbabcd724ec287444204a6b256c40a1ff3fefc25d (patch)
tree37a693c2fabf3ee9d9bdbfc2b534be41a44d60c4 /bin
parentAdd diff syntax to hi (diff)
downloadsrc-babcd724ec287444204a6b256c40a1ff3fefc25d.tar.gz
src-babcd724ec287444204a6b256c40a1ff3fefc25d.zip
Add CSS output to scheme
Diffstat (limited to 'bin')
-rw-r--r--bin/man1/scheme.110
-rw-r--r--bin/scheme.c17
2 files changed, 23 insertions, 4 deletions
diff --git a/bin/man1/scheme.1 b/bin/man1/scheme.1
index 738d9cd7..9aa4f054 100644
--- a/bin/man1/scheme.1
+++ b/bin/man1/scheme.1
@@ -1,4 +1,4 @@
-.Dd February 12, 2019
+.Dd July 6, 2019
 .Dt SCHEME 1
 .Os
 .
@@ -8,7 +8,7 @@
 .
 .Sh SYNOPSIS
 .Nm
-.Op Fl acghilmtx
+.Op Fl acghilmstx
 .Op Fl p Ar n
 .
 .Sh DESCRIPTION
@@ -41,6 +41,12 @@ Use with
 .It Fl p Ar n
 Generate only the color
 .Ar n .
+.It Fl s
+Output CSS
+for classes named
+.Sy fg Ns Ar n
+and
+.Sy bg Ns Ar n .
 .It Fl t
 Generate the 16 ANSI colors as well as
 background, foreground, bold, selection and cursor colors.
diff --git a/bin/scheme.c b/bin/scheme.c
index b71308da..acbcebb7 100644
--- a/bin/scheme.c
+++ b/bin/scheme.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2018  June McEnroe <june@causal.agency>
+/* Copyright (C) 2018, 2019  June 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;