summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2018-03-31 22:25:40 -0400
committerJune McEnroe <june@causal.agency>2018-03-31 22:25:40 -0400
commit176a43c5ba9e964380d3bc2e50a4216a47af981c (patch)
tree27dc3fae08c2beadf9d87a631e4faf79ba266a69
parentAdd scheme to README (diff)
downloadsrc-176a43c5ba9e964380d3bc2e50a4216a47af981c.tar.gz
src-176a43c5ba9e964380d3bc2e50a4216a47af981c.zip
Output Linux console escapes from scheme
Diffstat (limited to '')
-rw-r--r--bin/scheme.c14
-rwxr-xr-xetc/console.sh27
2 files changed, 12 insertions, 29 deletions
diff --git a/bin/scheme.c b/bin/scheme.c
index 8f88ef6f..bb700f88 100644
--- a/bin/scheme.c
+++ b/bin/scheme.c
@@ -112,6 +112,14 @@ static void png(const struct Hsv *scheme, uint8_t len) {
     pngInt(crc);
 }
 
+static void linux(const struct Hsv *scheme, uint8_t len) {
+    if (len > 16) len = 16;
+    for (uint8_t i = 0; i < len; ++i) {
+        struct Rgb rgb = toRgb(scheme[i]);
+        printf("\x1B]P%x%02x%02x%02x", i, rgb.r, rgb.g, rgb.b);
+    }
+}
+
 static void hex(const struct Hsv *scheme, uint8_t len) {
     for (uint8_t i = 0; i < len; ++i) {
         struct Rgb rgb = toRgb(scheme[i]);
@@ -176,13 +184,14 @@ static struct Terminal genTerminal(struct Ansi ansi) {
 
 int main(int argc, char *argv[]) {
     enum { ANSI, TERMINAL } generate = ANSI;
-    enum { HEX, PNG } output = HEX;
+    enum { HEX, LINUX, PNG } output = HEX;
 
     int opt;
-    while (0 < (opt = getopt(argc, argv, "agtx"))) {
+    while (0 < (opt = getopt(argc, argv, "agltx"))) {
         switch (opt) {
             case 'a': generate = ANSI; break;
             case 'g': output = PNG; break;
+            case 'l': output = LINUX; break;
             case 't': generate = TERMINAL; break;
             case 'x': output = HEX; break;
             default: return EX_USAGE;
@@ -207,6 +216,7 @@ int main(int argc, char *argv[]) {
 
     switch (output) {
         case HEX: hex(scheme, len); break;
+        case LINUX: linux(scheme, len); break;
         case PNG: png(scheme, len); break;
     }
 
diff --git a/etc/console.sh b/etc/console.sh
deleted file mode 100755
index 2f372345..00000000
--- a/etc/console.sh
+++ /dev/null
@@ -1,27 +0,0 @@
-#!/usr/bin/env zsh
-
-# Set the console color palette.
-
-color() {
-  print -n "\e]P${1}${2}"
-}
-
-color 0 '1d2021'
-color 1 'cc241d'
-color 2 '98991a'
-color 3 'd89a22'
-color 4 '468589'
-color 5 'b16286'
-color 6 '689e6a'
-color 7 'a99a84'
-
-color 8 '938374'
-color 9 'fc4935'
-color a 'b8ba26'
-color b 'fbbe2f'
-color c '83a699'
-color d 'd4869c'
-color e '8fc17d'
-color f 'eddbb3'
-
-clear