From a5efbf468c96190c9562bc8121eda32310dfd112 Mon Sep 17 00:00:00 2001 From: Sonali Srivastava Date: Thu, 21 Apr 2022 00:58:02 +0530 Subject: [PATCH] terminal-util: get_color_mode checks COLORTERM --- src/basic/terminal-util.c | 5 +++++ src/basic/terminal-util.h | 11 +++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/basic/terminal-util.c b/src/basic/terminal-util.c index 7cf74e97d0a..8ddcfe23230 100644 --- a/src/basic/terminal-util.c +++ b/src/basic/terminal-util.c @@ -1278,6 +1278,11 @@ ColorMode get_color_mode(void) { /* We only check for the presence of the variable; value is ignored. */ cached_color_mode = COLOR_OFF; + else if (STRPTR_IN_SET(getenv("COLORTERM"), + "truecolor", + "24bit")) + cached_color_mode = COLOR_24BIT; + else if (getpid_cached() == 1) /* PID1 outputs to the console without holding it open all the time. * diff --git a/src/basic/terminal-util.h b/src/basic/terminal-util.h index ce454bc1aef..59c868a2a53 100644 --- a/src/basic/terminal-util.h +++ b/src/basic/terminal-util.h @@ -100,16 +100,19 @@ typedef enum AcquireTerminalFlags { /* Limits the use of ANSI colors to a subset. */ typedef enum ColorMode { /* No colors, monochrome output. */ - COLOR_OFF = 0, + COLOR_OFF, /* All colors, no restrictions. */ - COLOR_ON = 1, + COLOR_ON, /* Only the base 16 colors. */ - COLOR_16 = 16, + COLOR_16, /* Only 256 colors. */ - COLOR_256 = 256, + COLOR_256, + + /* For truecolor or 24bit color support.*/ + COLOR_24BIT, _COLOR_INVALID = -EINVAL, } ColorMode;