diff options
author | Nor Khasyatillah <mazznoer@ymail.com> | 2022-05-27 16:56:07 +0700 |
---|---|---|
committer | jaseg <git@jaseg.de> | 2022-11-19 13:00:17 +0100 |
commit | 6db5a0fa5005710ff1a71a721b3d625e61c37e78 (patch) | |
tree | 106ded39aaea1e4edb0de22a2ff0d1d9a771c5e9 /lolcat.c | |
parent | 37bb84e2977265331503236ed78d39ca04352226 (diff) | |
download | lolcat-6db5a0fa5005710ff1a71a721b3d625e61c37e78.tar.gz lolcat-6db5a0fa5005710ff1a71a721b3d625e61c37e78.tar.bz2 lolcat-6db5a0fa5005710ff1a71a721b3d625e61c37e78.zip |
Add new option `--invert`.
Diffstat (limited to 'lolcat.c')
-rwxr-xr-x | lolcat.c | 21 |
1 files changed, 18 insertions, 3 deletions
@@ -46,6 +46,7 @@ static char helpstr[] = "\n" " --24bit, -b: Output in 24-bit \"true\" RGB mode (slower and\n" " not supported by all terminals)\n" " --16color, -x: Output in 16-color mode for basic terminals\n" + " --invert, -i: Invert foreground and background\n" " --version: Print version and exit\n" " --help: Show this message\n" "\n" @@ -109,6 +110,7 @@ int main(int argc, char** argv) int start_color = 0; int rgb = 0; int ansi16 = 0; + int invert = 0; double freq_h = 0.23, freq_v = 0.1; struct timeval tv; @@ -160,6 +162,8 @@ int main(int argc, char** argv) rgb = 1; } else if (!strcmp(argv[i], "-x") || !strcmp(argv[i], "--16color")) { ansi16 = 1; + } else if (!strcmp(argv[i], "-i") || !strcmp(argv[i], "--invert")) { + invert = 1; } else if (!strcmp(argv[i], "--version")) { version(); } else { @@ -174,6 +178,14 @@ int main(int argc, char** argv) usage(); } + if (invert) { + if (ansi16) { + wprintf(L"\033[30m\n"); + } else { + wprintf(L"\033[38;5;16m\n"); + } + } + int rand_offset = 0; if (random) { srand(seed); @@ -227,6 +239,9 @@ int main(int argc, char** argv) if (c == '\n') { l++; i = 0; + if (invert) { + wprintf(L"\033[49m"); + } } else { if (rgb) { @@ -237,17 +252,17 @@ int main(int argc, char** argv) uint8_t red = lrintf((offset + (1.0f - offset) * (0.5f + 0.5f * sin(theta + 0 ))) * 255.0f); uint8_t green = lrintf((offset + (1.0f - offset) * (0.5f + 0.5f * sin(theta + 2 * M_PI / 3 ))) * 255.0f); uint8_t blue = lrintf((offset + (1.0f - offset) * (0.5f + 0.5f * sin(theta + 4 * M_PI / 3 ))) * 255.0f); - wprintf(L"\033[38;2;%d;%d;%dm", red, green, blue); + wprintf(L"\033[%d;2;%d;%d;%dm", (invert ? 48 : 38), red, green, blue); } else if (ansi16) { int ncc = offx * ARRAY_SIZE(codes16) + (int)((i += wcwidth(c)) * freq_h + l * freq_v); if (cc != ncc) - wprintf(L"\033[%hhum", codes16[(rand_offset + start_color + (cc = ncc)) % ARRAY_SIZE(codes16)]); + wprintf(L"\033[%hhum", (invert ? 10 : 0) + codes16[(rand_offset + start_color + (cc = ncc)) % ARRAY_SIZE(codes16)]); } else { int ncc = offx * ARRAY_SIZE(codes) + (int)((i += wcwidth(c)) * freq_h + l * freq_v); if (cc != ncc) - wprintf(L"\033[38;5;%hhum", codes[(rand_offset + start_color + (cc = ncc)) % ARRAY_SIZE(codes)]); + wprintf(L"\033[%d;5;%hhum", (invert ? 48 : 38), codes[(rand_offset + start_color + (cc = ncc)) % ARRAY_SIZE(codes)]); } } } |