sysinfo: Try to be slightly smarter about printing logo

This commit is contained in:
K. Lange 2021-11-27 20:16:27 +09:00
parent 6662728202
commit b0c4980229

View File

@ -56,13 +56,28 @@ void print_thing(int j) {
}
}
static void reset(void) {
printf("\033[0m");
}
static int term_is_toaru = 0;
static void foreground_color(uint32_t color) {
printf(term_is_toaru ? "\033[38;6;%d;%d;%d;%dm" : "\033[38;2;%d;%d;%dm",
(int)_RED(color), (int)_GRE(color), (int)_BLU(color), (int)_ALP(color));
}
static void background_color(uint32_t color) {
printf(term_is_toaru ? "\033[48;6;%d;%d;%d;%dm" : "\033[48;2;%d;%d;%dm",
(int)_RED(color), (int)_GRE(color), (int)_BLU(color), (int)_ALP(color));
}
int main(int argc, char * argv[]) {
/* Prepare data */
char * user = getenv("USER");
char * wm_theme = getenv("WM_THEME");
char * term = getenv("TERM");
int term_is_toaru = term && strstr(term,"toaru");
term_is_toaru = term && strstr(term,"toaru");
int i = 0;
@ -128,18 +143,26 @@ int main(int argc, char * argv[]) {
rgba(0,0,0,TERM_DEFAULT_OPAC),
premultiply(rgba(r_b, g_b, b_b, a_b)));
if (term_is_toaru) {
/* Print half block */
printf("\033[38;6;%d;%d;%d;%dm\033[48;6;%d;%d;%d;%dm▄",
(int)_RED(back), (int)_GRE(back), (int)_BLU(back), (int)_ALP(back),
(int)_RED(out), (int)_GRE(out), (int)_BLU(out), (int)_ALP(out));
} else {
printf("\033[38;2;%d;%d;%dm\033[48;2;%d;%d;%dm▄",
(int)_RED(back), (int)_GRE(back), (int)_BLU(back),
(int)_RED(out), (int)_GRE(out), (int)_BLU(out));
/* Are both cells transparent? */
if (a_t == 0 && a_b == 0) {
reset();
printf(" ");
continue;
}
if (a_b == 0) {
reset();
foreground_color(out);
printf("");
} else if (a_t == 0) {
reset();
foreground_color(back);
printf("");
} else {
foreground_color(back);
background_color(out);
printf("");
}
}
if (j < i) {
print_thing(j);