From 34894724b0a85f7d047f31dcdc893dbd47b8f9c3 Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Sat, 6 Feb 2021 19:48:14 -0500 Subject: Add xterm output to scheme --- bin/man1/scheme.1 | 7 +++++-- bin/scheme.c | 24 +++++++++++++++++++++++- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/bin/man1/scheme.1 b/bin/man1/scheme.1 index 9aa4f054..9f72d945 100644 --- a/bin/man1/scheme.1 +++ b/bin/man1/scheme.1 @@ -1,4 +1,4 @@ -.Dd July 6, 2019 +.Dd February 6, 2021 .Dt SCHEME 1 .Os . @@ -8,7 +8,7 @@ . .Sh SYNOPSIS .Nm -.Op Fl acghilmstx +.Op Fl Xacghilmstx .Op Fl p Ar n . .Sh DESCRIPTION @@ -19,6 +19,9 @@ and outputs it in a number of formats. .Pp The arguments are as follows: .Bl -tag -width Ds +.It Fl X +Output Xresources for +.Xr xterm 1 . .It Fl a Generate the 16 ANSI colors. This is the default. diff --git a/bin/scheme.c b/bin/scheme.c index b921a77e..2bae8f82 100644 --- a/bin/scheme.c +++ b/bin/scheme.c @@ -156,6 +156,27 @@ static void outputEnum(const struct HSV *hsv, uint len) { printf("};\n"); } +#define FORMAT_X "rgb:%02hhX/%02hhX/%02hhX" + +static const char *Resources[SchemeLen] = { + [Background] = "background", + [Foreground] = "foreground", + [Bold] = "colorBD", + [Selection] = "highlightColor", + [Cursor] = "cursorColor", +}; + +static void outputXTerm(const struct HSV *hsv, uint len) { + for (uint i = 0; i < len; ++i) { + struct RGB rgb = convert(hsv[i]); + if (Resources[i]) { + printf("XTerm*%s: " FORMAT_X "\n", Resources[i], rgb.r, rgb.g, rgb.b); + } else { + printf("XTerm*color%u: " FORMAT_X "\n", i, rgb.r, rgb.g, rgb.b); + } + } +} + static const char *Mintty[SchemeLen] = { "Black", "Red", "Green", "Yellow", "Blue", "Magenta", "Cyan", "White", @@ -230,8 +251,9 @@ int main(int argc, char *argv[]) { uint len = 16; int opt; - while (0 < (opt = getopt(argc, argv, "acghilmp:stx"))) { + while (0 < (opt = getopt(argc, argv, "Xacghilmp:stx"))) { switch (opt) { + break; case 'X': output = outputXTerm; break; case 'a': len = 16; break; case 'c': output = outputEnum; break; case 'g': output = outputPNG; -- cgit 1.4.1