diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..72e8ffc --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +* diff --git a/Makefile b/Makefile index e810133..cb83c68 100644 --- a/Makefile +++ b/Makefile @@ -69,9 +69,9 @@ ansi2html: Makefile $(C_FILES) $(H_FILES) all: format tags ansi2html .PHONY: format -format: Makefile $(C_FILES) $(H_FILES) +format: scripts/format.sh Makefile $(C_FILES) $(H_FILES) @start=$$(perl -MTime::HiRes=gettimeofday -E'say scalar gettimeofday') - @clang-format -i $(C_FILES) $(H_FILES) + @./scripts/format.sh clang-format -i $(C_FILES) $(H_FILES) @end=$$(perl -MTime::HiRes=gettimeofday -E'say scalar gettimeofday') @perl -E'say sprintf "Format time: %.4f seconds", $$ARGV[1] - $$ARGV[0]' "$$start" "$$end" diff --git a/scripts/format.sh b/scripts/format.sh new file mode 100755 index 0000000..350f03a --- /dev/null +++ b/scripts/format.sh @@ -0,0 +1,27 @@ +#!/bin/bash +set -euo pipefail +DEBIAN_VERSION=bookworm +CLANG_VERSION=20 +docker build -t ansi2html-formatter . -f-< /etc/apt/sources.list.d/llvm.list && \ + wget -qO /etc/apt/trusted.gpg.d/llvm.asc \ + https://apt.llvm.org/llvm-snapshot.gpg.key && \ + apt-get -qq update && \ + apt-get install -qqy -t $DEBIAN_VERSION \ + clang-$CLANG_VERSION clang-tidy-$CLANG_VERSION clang-format-$CLANG_VERSION lld-$CLANG_VERSION \ + && \ + for f in /usr/lib/llvm-*/bin/*; do ln -sf "\$f" /usr/bin; done && \ + ln -sf clang /usr/bin/cc && \ + ln -sf clang /usr/bin/c89 && \ + ln -sf clang /usr/bin/c99 && \ + ln -sf clang++ /usr/bin/c++ && \ + ln -sf clang++ /usr/bin/g++ && \ + rm -rf /var/lib/apt/lists/* +END_DOCKERFILE +docker run -it --rm --user "$(id -u)" -v "$(pwd):/src" --workdir /src ansi2html-formatter "$@" diff --git a/src/iterm2_color_schemes/ansi_color_palette.c b/src/iterm2_color_schemes/ansi_color_palette.c index 43531e5..11b6637 100644 --- a/src/iterm2_color_schemes/ansi_color_palette.c +++ b/src/iterm2_color_schemes/ansi_color_palette.c @@ -1,4 +1,4 @@ -// Generated by ./scripts/iterm2-color-schemes.pl from https://github.com/mbadolato/iTerm2-Color-Schemes/ at 92f20650771384b82f981fb0f249e5fbdcb69e9f +// Generated by ./scripts/iterm2-color-schemes.pl from https://github.com/mbadolato/iTerm2-Color-Schemes/ at 8b639f0c2605557bd23ba1b940842c67bbfd4ed0 #ifdef ITERM2_COLOR_SCHEMES #include "../structs/ansi_color_palette.h" // clang-format off @@ -6863,6 +6863,34 @@ struct ansi_color_palette real_PALETTE_I2_PEPPERMINT = { }; struct ansi_color_palette *PALETTE_I2_PEPPERMINT = &real_PALETTE_I2_PEPPERMINT; +// iTerm2-Color-Schemes/Xresources/Phala Green Dark: iTerm2 Color Schemes: Phala Green Dark -> i2_phala_green_dark +struct ansi_color_palette real_PALETTE_I2_PHALA_GREEN_DARK = { + "iTerm2 Color Schemes: Phala Green Dark", + {0x00, 0x00, 0x00}, + {0xCD, 0xFA, 0x50}, + { + {0x00, 0x00, 0x00}, + {0x9D, 0x28, 0x14}, + {0x4A, 0xAE, 0x31}, + {0xA9, 0xA7, 0x33}, + {0x0C, 0x23, 0xB8}, + {0xB2, 0x3B, 0xBA}, + {0x4B, 0xB1, 0xBD}, + {0xCB, 0xCB, 0xCB}, + }, + { + {0x79, 0x79, 0x79}, + {0xDA, 0x3B, 0x20}, + {0x5D, 0xD8, 0x3F}, + {0xE9, 0xE7, 0x4A}, + {0x14, 0x32, 0xF5}, + {0xDA, 0x4B, 0xE3}, + {0x64, 0xE5, 0xE8}, + {0xEA, 0xEA, 0xEA}, + }, +}; +struct ansi_color_palette *PALETTE_I2_PHALA_GREEN_DARK = &real_PALETTE_I2_PHALA_GREEN_DARK; + // iTerm2-Color-Schemes/Xresources/Piatto Light: iTerm2 Color Schemes: Piatto Light -> i2_piatto_light struct ansi_color_palette real_PALETTE_I2_PIATTO_LIGHT = { "iTerm2 Color Schemes: Piatto Light", @@ -8291,6 +8319,34 @@ struct ansi_color_palette real_PALETTE_I2_TANGO_HALF_ADAPTED = { }; struct ansi_color_palette *PALETTE_I2_TANGO_HALF_ADAPTED = &real_PALETTE_I2_TANGO_HALF_ADAPTED; +// iTerm2-Color-Schemes/Xresources/Tearout: iTerm2 Color Schemes: Tearout -> i2_tearout +struct ansi_color_palette real_PALETTE_I2_TEAROUT = { + "iTerm2 Color Schemes: Tearout", + {0x34, 0x39, 0x2D}, + {0xF4, 0xD2, 0xAE}, + { + {0x68, 0x57, 0x42}, + {0xCC, 0x96, 0x7B}, + {0x97, 0x97, 0x6D}, + {0x6C, 0x98, 0x61}, + {0xB5, 0x95, 0x5E}, + {0xC9, 0xA5, 0x54}, + {0xD7, 0xC4, 0x83}, + {0xB5, 0x95, 0x5E}, + }, + { + {0x68, 0x57, 0x42}, + {0xCC, 0x96, 0x7B}, + {0x97, 0x97, 0x6D}, + {0x6C, 0x98, 0x61}, + {0xB5, 0x95, 0x5E}, + {0xC9, 0xA5, 0x54}, + {0xD7, 0xC4, 0x83}, + {0xB5, 0x95, 0x5E}, + }, +}; +struct ansi_color_palette *PALETTE_I2_TEAROUT = &real_PALETTE_I2_TEAROUT; + // iTerm2-Color-Schemes/Xresources/Teerb: iTerm2 Color Schemes: Teerb -> i2_teerb struct ansi_color_palette real_PALETTE_I2_TEERB = { "iTerm2 Color Schemes: Teerb", @@ -11455,6 +11511,34 @@ struct ansi_color_palette real_PALETTE_I2_VIMBONES = { }; struct ansi_color_palette *PALETTE_I2_VIMBONES = &real_PALETTE_I2_VIMBONES; +// iTerm2-Color-Schemes/Xresources/violite: iTerm2 Color Schemes: violite -> i2_violite +struct ansi_color_palette real_PALETTE_I2_VIOLITE = { + "iTerm2 Color Schemes: violite", + {0x24, 0x1C, 0x36}, + {0xEE, 0xF4, 0xF6}, + { + {0x24, 0x1C, 0x36}, + {0xEC, 0x79, 0x79}, + {0x79, 0xEC, 0xB3}, + {0xEC, 0xE2, 0x79}, + {0xA9, 0x79, 0xEC}, + {0xEC, 0x79, 0xEC}, + {0x79, 0xEC, 0xEC}, + {0xEE, 0xF4, 0xF6}, + }, + { + {0x49, 0x37, 0x6D}, + {0xEF, 0x8F, 0x8F}, + {0x9F, 0xEF, 0xBF}, + {0xEF, 0xE7, 0x8F}, + {0xB7, 0x8F, 0xEF}, + {0xEF, 0x8F, 0xCF}, + {0x9F, 0xEF, 0xEF}, + {0xF8, 0xFA, 0xFC}, + }, +}; +struct ansi_color_palette *PALETTE_I2_VIOLITE = &real_PALETTE_I2_VIOLITE; + // iTerm2-Color-Schemes/Xresources/wilmersdorf: iTerm2 Color Schemes: wilmersdorf -> i2_wilmersdorf struct ansi_color_palette real_PALETTE_I2_WILMERSDORF = { "iTerm2 Color Schemes: wilmersdorf", diff --git a/src/iterm2_color_schemes/ansi_color_palette.h b/src/iterm2_color_schemes/ansi_color_palette.h index faaace9..a4af5a7 100644 --- a/src/iterm2_color_schemes/ansi_color_palette.h +++ b/src/iterm2_color_schemes/ansi_color_palette.h @@ -1,4 +1,4 @@ -// Generated by ./scripts/iterm2-color-schemes.pl from https://github.com/mbadolato/iTerm2-Color-Schemes/ at 92f20650771384b82f981fb0f249e5fbdcb69e9f +// Generated by ./scripts/iterm2-color-schemes.pl from https://github.com/mbadolato/iTerm2-Color-Schemes/ at 8b639f0c2605557bd23ba1b940842c67bbfd4ed0 #ifdef ITERM2_COLOR_SCHEMES #ifndef ITERM2_COLOR_SCHEMES_ANSI_COLOR_PALETTE_H_ #define ITERM2_COLOR_SCHEMES_ANSI_COLOR_PALETTE_H_ @@ -248,6 +248,7 @@ extern struct ansi_color_palette *PALETTE_I2_PAULMILLR; extern struct ansi_color_palette *PALETTE_I2_PENCILDARK; extern struct ansi_color_palette *PALETTE_I2_PENCILLIGHT; extern struct ansi_color_palette *PALETTE_I2_PEPPERMINT; +extern struct ansi_color_palette *PALETTE_I2_PHALA_GREEN_DARK; extern struct ansi_color_palette *PALETTE_I2_PIATTO_LIGHT; extern struct ansi_color_palette *PALETTE_I2_PNEVMA; extern struct ansi_color_palette *PALETTE_I2_POPPING_AND_LOCKING; @@ -299,6 +300,7 @@ extern struct ansi_color_palette *PALETTE_I2_SYMFONIC; extern struct ansi_color_palette *PALETTE_I2_SYNTHWAVEALPHA; extern struct ansi_color_palette *PALETTE_I2_TANGO_ADAPTED; extern struct ansi_color_palette *PALETTE_I2_TANGO_HALF_ADAPTED; +extern struct ansi_color_palette *PALETTE_I2_TEAROUT; extern struct ansi_color_palette *PALETTE_I2_TEERB; extern struct ansi_color_palette *PALETTE_I2_TERMINAL_BASIC; extern struct ansi_color_palette *PALETTE_I2_TERMINAL_BASIC_DARK; @@ -412,6 +414,7 @@ extern struct ansi_color_palette *PALETTE_I2_TOKYONIGHT_STORM; extern struct ansi_color_palette *PALETTE_I2_TOKYONIGHT_MOON; extern struct ansi_color_palette *PALETTE_I2_TOKYONIGHT_NIGHT; extern struct ansi_color_palette *PALETTE_I2_VIMBONES; +extern struct ansi_color_palette *PALETTE_I2_VIOLITE; extern struct ansi_color_palette *PALETTE_I2_WILMERSDORF; extern struct ansi_color_palette *PALETTE_I2_XCODEDARK; extern struct ansi_color_palette *PALETTE_I2_XCODEDARKHC; diff --git a/src/iterm2_color_schemes/named_palettes.h b/src/iterm2_color_schemes/named_palettes.h index 344467e..0091a8d 100644 --- a/src/iterm2_color_schemes/named_palettes.h +++ b/src/iterm2_color_schemes/named_palettes.h @@ -1,4 +1,4 @@ -// Generated by ./scripts/iterm2-color-schemes.pl from https://github.com/mbadolato/iTerm2-Color-Schemes/ at 92f20650771384b82f981fb0f249e5fbdcb69e9f +// Generated by ./scripts/iterm2-color-schemes.pl from https://github.com/mbadolato/iTerm2-Color-Schemes/ at 8b639f0c2605557bd23ba1b940842c67bbfd4ed0 #ifdef ITERM2_COLOR_SCHEMES #ifndef ITERM2_COLOR_SCHEMES_NAMED_PALETTES_H_ #define ITERM2_COLOR_SCHEMES_NAMED_PALETTES_H_ @@ -248,6 +248,7 @@ {"i2_pencildark", PALETTE_I2_PENCILDARK }, {"i2_pencillight", PALETTE_I2_PENCILLIGHT }, {"i2_peppermint", PALETTE_I2_PEPPERMINT }, +{"i2_phala_green_dark", PALETTE_I2_PHALA_GREEN_DARK }, {"i2_piatto_light", PALETTE_I2_PIATTO_LIGHT }, {"i2_pnevma", PALETTE_I2_PNEVMA }, {"i2_popping_and_locking", PALETTE_I2_POPPING_AND_LOCKING }, @@ -299,6 +300,7 @@ {"i2_synthwavealpha", PALETTE_I2_SYNTHWAVEALPHA }, {"i2_tango_adapted", PALETTE_I2_TANGO_ADAPTED }, {"i2_tango_half_adapted", PALETTE_I2_TANGO_HALF_ADAPTED }, +{"i2_tearout", PALETTE_I2_TEAROUT }, {"i2_teerb", PALETTE_I2_TEERB }, {"i2_terminal_basic", PALETTE_I2_TERMINAL_BASIC }, {"i2_terminal_basic_dark", PALETTE_I2_TERMINAL_BASIC_DARK }, @@ -412,6 +414,7 @@ {"i2_tokyonight_moon", PALETTE_I2_TOKYONIGHT_MOON }, {"i2_tokyonight_night", PALETTE_I2_TOKYONIGHT_NIGHT }, {"i2_vimbones", PALETTE_I2_VIMBONES }, +{"i2_violite", PALETTE_I2_VIOLITE }, {"i2_wilmersdorf", PALETTE_I2_WILMERSDORF }, {"i2_xcodedark", PALETTE_I2_XCODEDARK }, {"i2_xcodedarkhc", PALETTE_I2_XCODEDARKHC }, diff --git a/src/main.c b/src/main.c index 0436868..23e9d49 100644 --- a/src/main.c +++ b/src/main.c @@ -90,11 +90,13 @@ static inline void char_to_buffer(const unsigned char c) output_buffer[output_buffer_idx] = '\0'; } +#define SAY(fmt, ...) (void)fprintf(stdout, fmt "\n", __VA_ARGS__) +#define WARN(...) (void)fprintf(stderr, __VA_ARGS__) #define ERROR(fmt, ...) \ do \ { \ flush_buffer(); \ - (void)fprintf(stderr, "ERROR: " fmt, ##__VA_ARGS__); \ + WARN("ERROR: " fmt, ##__VA_ARGS__); \ exit(1); \ } while (0) @@ -286,7 +288,11 @@ just_strip_it(bool ignore_sgr_errors) exit(0); } -#define VRGB(r, g, b) (unsigned int)(r), (unsigned int)(g), (unsigned int)(b) +#define VRGB(p) \ + (unsigned int)((p).red), (unsigned int)((p).green), (unsigned int)((p).blue) +#define VRGB17(p) \ + (unsigned int)((p).red / 17), (unsigned int)((p).green / 17), \ + (unsigned int)((p).blue / 17) static inline __attribute__((always_inline)) void ansi2html( struct ansi_style style, struct ansi_color_palette *palette, @@ -298,14 +304,7 @@ static inline __attribute__((always_inline)) void ansi2html( printf("
default_fg.red, palette->default_fg.green,
-                palette->default_fg.blue
-            ),
-            VRGB(
-                palette->default_bg.red, palette->default_bg.green,
-                palette->default_bg.blue
-            )
+            VRGB(palette->default_fg), VRGB(palette->default_bg)
         );
         if (pre_add_style)
             append_to_buffer(pre_add_style);
@@ -626,7 +625,7 @@ int main(int argc, char *argv[])
 #define SHOW_USAGE()                                                           \
     do                                                                         \
     {                                                                          \
-        (void)fprintf(stderr, USAGE_FMT, argv[0]);                             \
+        WARN(USAGE_FMT, argv[0]);                                              \
     } while (0)
     struct named_palettes
     {
@@ -655,15 +654,15 @@ int main(int argc, char *argv[])
     {                                                                          \
         for (size_t j = 0;                                                     \
              j < sizeof(named_palettes) / sizeof(named_palettes[0]); j++)      \
-            (void)fprintf(stdout, "%s\n", named_palettes[j].name);             \
+            SAY("%s", named_palettes[j].name);                                 \
     } while (0)
 #define SHOW_VALID_PALETTES()                                                  \
     do                                                                         \
     {                                                                          \
-        (void)fprintf(stderr, "Valid palettes:\n");                            \
+        WARN("Valid palettes:\n");                                             \
         for (size_t j = 0;                                                     \
              j < sizeof(named_palettes) / sizeof(named_palettes[0]); j++)      \
-            (void)fprintf(stderr, "- %s\n", named_palettes[j].name);           \
+            WARN("- %s\n", named_palettes[j].name);                            \
     } while (0)
 
     // We start with a "reset" style:
@@ -717,8 +716,7 @@ int main(int argc, char *argv[])
                 }
                 if (!palette)
                 {
-                    (void
-                    )fprintf(stderr, "Error: Unknown palette '%s'.\n", argv[i]);
+                    WARN("Error: Unknown palette '%s'.\n", argv[i]);
                     SHOW_VALID_PALETTES();
                     SHOW_USAGE();
                     exit(1);
@@ -726,8 +724,7 @@ int main(int argc, char *argv[])
             }
             else
             {
-                (void
-                )fprintf(stderr, "Error: Missing argument to '--palette'.\n");
+                WARN("Error: Missing argument to '--palette'.\n");
                 SHOW_VALID_PALETTES();
                 SHOW_USAGE();
                 exit(1);
@@ -746,32 +743,19 @@ int main(int argc, char *argv[])
                 i++;
                 if (!strcmp(argv[i], "fg"))
                 {
-                    (void)printf(
-                        "#%02X%02X%02X\n",
-                        VRGB(
-                            palette->default_fg.red, palette->default_fg.green,
-                            palette->default_fg.blue
-                        )
-                    );
+                    (void)printf("#%02X%02X%02X\n", VRGB(palette->default_fg));
                     exit(0);
                 }
                 else if (!strcmp(argv[i], "bg"))
                 {
-                    (void)printf(
-                        "#%02X%02X%02X\n",
-                        VRGB(
-                            palette->default_bg.red, palette->default_bg.green,
-                            palette->default_bg.blue
-                        )
-                    );
+                    (void)printf("#%02X%02X%02X\n", VRGB(palette->default_bg));
                     exit(0);
                 }
                 char *endptr = NULL;
                 long color = strtol(argv[i], &endptr, 10);
                 if (!endptr || *endptr != '\0')
                 {
-                    (void)fprintf(
-                        stderr,
+                    WARN(
                         "Error: Invalid color '%s' needs to be 0-15 or fg or "
                         "bg.\n",
                         argv[i]
@@ -786,15 +770,12 @@ int main(int argc, char *argv[])
                         rgb = palette->base[color];
                     else
                         rgb = palette->bright[color - 8];
-                    (void)printf(
-                        "#%02X%02X%02X\n", VRGB(rgb.red, rgb.green, rgb.blue)
-                    );
+                    (void)printf("#%02X%02X%02X\n", VRGB(rgb));
                     exit(0);
                 }
                 else
                 {
-                    (void)fprintf(
-                        stderr,
+                    WARN(
                         "Error: Invalid color '%s' needs to be 0-15 or fg or "
                         "bg.\n",
                         argv[i]
@@ -805,9 +786,7 @@ int main(int argc, char *argv[])
             }
             else
             {
-                (void)fprintf(
-                    stderr, "Error: Missing argument to '--show-rgb-for'.\n"
-                );
+                WARN("Error: Missing argument to '--show-rgb-for'.\n");
                 SHOW_USAGE();
                 exit(1);
             }
@@ -834,9 +813,7 @@ int main(int argc, char *argv[])
         {
             if (!wrap_in_pre)
             {
-                (void)fprintf(
-                    stderr, "Error: Need to use --pre before --pre-add-style.\n"
-                );
+                WARN("Error: Need to use --pre before --pre-add-style.\n");
                 SHOW_USAGE();
                 exit(1);
             }
@@ -847,9 +824,7 @@ int main(int argc, char *argv[])
             }
             else
             {
-                (void)fprintf(
-                    stderr, "Error: Missing argument to '--pre-add-style'.\n"
-                );
+                WARN("Error: Missing argument to '--pre-add-style'.\n");
                 SHOW_USAGE();
                 exit(1);
             }
@@ -882,40 +857,24 @@ int main(int argc, char *argv[])
                             (palette->default_fg.blue % 17) == 0)
                             printf(
                                 "color:#%01X%01X%01X;",
-                                VRGB(
-                                    palette->default_fg.red / 17,
-                                    palette->default_fg.green / 17,
-                                    palette->default_fg.blue / 17
-                                )
+                                VRGB17(palette->default_fg)
                             );
                         else
                             printf(
                                 "color:#%02X%02X%02X;",
-                                VRGB(
-                                    palette->default_fg.red,
-                                    palette->default_fg.green,
-                                    palette->default_fg.blue
-                                )
+                                VRGB(palette->default_fg)
                             );
                         if ((palette->default_bg.red % 17) == 0 &&
                             (palette->default_bg.green % 17) == 0 &&
                             (palette->default_bg.blue % 17) == 0)
                             printf(
                                 "background-color:#%01X%01X%01X;",
-                                VRGB(
-                                    palette->default_bg.red / 17,
-                                    palette->default_bg.green / 17,
-                                    palette->default_bg.blue / 17
-                                )
+                                VRGB17(palette->default_bg)
                             );
                         else
                             printf(
                                 "background-color:#%02X%02X%02X;",
-                                VRGB(
-                                    palette->default_bg.red,
-                                    palette->default_bg.green,
-                                    palette->default_bg.blue
-                                )
+                                VRGB(palette->default_bg)
                             );
                         printf("}");
                     }
@@ -925,14 +884,7 @@ int main(int argc, char *argv[])
                         ".ansi2html{"
                         "color:#%02X%02X%02X;background-color:#%02X%02X%02X;"
                         "}",
-                        VRGB(
-                            palette->default_fg.red, palette->default_fg.green,
-                            palette->default_fg.blue
-                        ),
-                        VRGB(
-                            palette->default_bg.red, palette->default_bg.green,
-                            palette->default_bg.blue
-                        )
+                        VRGB(palette->default_fg), VRGB(palette->default_bg)
                     );
             }
             if (use_compact && (palette->default_fg.red % 17) == 0 &&
@@ -940,38 +892,24 @@ int main(int argc, char *argv[])
                 (palette->default_fg.blue % 17) == 0)
                 printf(
                     ".ansi2html .fg-default{color:#%01X%01X%01X;}",
-                    VRGB(
-                        palette->default_fg.red / 17,
-                        palette->default_fg.green / 17,
-                        palette->default_fg.blue / 17
-                    )
+                    VRGB17(palette->default_fg)
                 );
             else
                 printf(
                     ".ansi2html .fg-default{color:#%02X%02X%02X;}",
-                    VRGB(
-                        palette->default_fg.red, palette->default_fg.green,
-                        palette->default_fg.blue
-                    )
+                    VRGB(palette->default_fg)
                 );
             if (use_compact && (palette->default_bg.red % 17) == 0 &&
                 (palette->default_bg.green % 17) == 0 &&
                 (palette->default_bg.blue % 17) == 0)
                 printf(
                     ".ansi2html .bg-default{background-color:#%01X%01X%01X;}",
-                    VRGB(
-                        palette->default_bg.red / 17,
-                        palette->default_bg.green / 17,
-                        palette->default_bg.blue / 17
-                    )
+                    VRGB17(palette->default_bg)
                 );
             else
                 printf(
                     ".ansi2html .bg-default{background-color:#%02X%02X%02X;}",
-                    VRGB(
-                        palette->default_bg.red, palette->default_bg.green,
-                        palette->default_bg.blue
-                    )
+                    VRGB(palette->default_bg)
                 );
             for (int j = 0; j < 256; j++)
             {
@@ -981,23 +919,17 @@ int main(int argc, char *argv[])
                     (rgb.green % 17) == 0 && (rgb.blue % 17) == 0)
                 {
                     printf(
-                        ".ansi2html .fg-%d{color:#%01X%01X%01X;}", j,
-                        VRGB(rgb.red / 17, rgb.green / 17, rgb.blue / 17)
-                    );
-                    printf(
-                        ".ansi2html .bg-%d{background-color:#%01X%01X%01X;}", j,
-                        VRGB(rgb.red / 17, rgb.green / 17, rgb.blue / 17)
+                        ".ansi2html .fg-%d{color:#%01X%01X%01X;}"
+                        ".ansi2html .bg-%d{background-color:#%01X%01X%01X;}",
+                        j, VRGB17(rgb), j, VRGB17(rgb)
                     );
                 }
                 else
                 {
                     printf(
-                        ".ansi2html .fg-%d{color:#%02X%02X%02X;}", j,
-                        VRGB(rgb.red, rgb.green, rgb.blue)
-                    );
-                    printf(
-                        ".ansi2html .bg-%d{background-color:#%02X%02X%02X;}", j,
-                        VRGB(rgb.red, rgb.green, rgb.blue)
+                        ".ansi2html .fg-%d{color:#%02X%02X%02X;}"
+                        ".ansi2html .bg-%d{background-color:#%02X%02X%02X;}",
+                        j, VRGB(rgb), j, VRGB(rgb)
                     );
                 }
             }
@@ -1020,8 +952,7 @@ int main(int argc, char *argv[])
                     long color = strtol(argv[i], &endptr, 10);
                     if (!endptr || *endptr != '\0')
                     {
-                        (void)fprintf(
-                            stderr,
+                        WARN(
                             "Error: Invalid color '%s' needs to be 0-15 or fg "
                             "or bg.\n",
                             argv[i]
@@ -1036,8 +967,7 @@ int main(int argc, char *argv[])
                 }
                 if (!which_rgb)
                 {
-                    (void)fprintf(
-                        stderr,
+                    WARN(
                         "Error: Invalid color '%s' needs to be 0-15 or fg or "
                         "bg.\n",
                         argv[i]
@@ -1054,8 +984,7 @@ int main(int argc, char *argv[])
                         color++;
                     if (strlen(color) != 6)
                     {
-                        (void)fprintf(
-                            stderr,
+                        WARN(
                             "Error: Invalid color '%s' needs to be #RRGGBB.\n",
                             argv[i]
                         );
@@ -1066,8 +995,7 @@ int main(int argc, char *argv[])
                     long lrgb = strtol(color, &endptr, 16);
                     if (!endptr || *endptr != '\0')
                     {
-                        (void)fprintf(
-                            stderr,
+                        WARN(
                             "Error: Invalid color '%s' needs to be #RRGGBB.\n",
                             argv[i]
                         );
@@ -1076,8 +1004,7 @@ int main(int argc, char *argv[])
                     }
                     if (lrgb < 0 || lrgb > 0xFFFFFF)
                     {
-                        (void)fprintf(
-                            stderr,
+                        WARN(
                             "Error: Invalid color '%s' needs to be #RRGGBB.\n",
                             argv[i]
                         );
@@ -1091,18 +1018,14 @@ int main(int argc, char *argv[])
                 }
                 else
                 {
-                    (void)fprintf(
-                        stderr, "Error: Missing argument 2 for '--rgb-for'.\n"
-                    );
+                    WARN("Error: Missing argument 2 for '--rgb-for'.\n");
                     SHOW_USAGE();
                     exit(1);
                 }
             }
             else
             {
-                (void)fprintf(
-                    stderr, "Error: Missing argument 1 for '--rgb-for'.\n"
-                );
+                WARN("Error: Missing argument 1 for '--rgb-for'.\n");
                 SHOW_USAGE();
                 exit(1);
             }
@@ -1110,7 +1033,7 @@ int main(int argc, char *argv[])
         }
         else
         {
-            (void)fprintf(stderr, "Error: Unknown argument '%s'.\n", argv[i]);
+            WARN("Error: Unknown argument '%s'.\n", argv[i]);
             SHOW_USAGE();
             exit(1);
         }
@@ -1118,9 +1041,7 @@ int main(int argc, char *argv[])
 
     if (ignore_sgr_errors && !just_strip)
     {
-        (void)fprintf(
-            stderr, "--ignore-sgr-errors is only available for --strip.\n"
-        );
+        WARN("--ignore-sgr-errors is only available for --strip.\n");
         SHOW_USAGE();
         exit(1);
     }