diff options
author | Sonny Sasaka <sonnysasaka@chromium.org> | 2021-03-16 15:16:48 -0700 |
---|---|---|
committer | Luiz Augusto von Dentz <luiz.von.dentz@intel.com> | 2021-03-18 15:41:32 -0700 |
commit | a4a615c7fba22ef88beae761cbf722cea21fc8d4 (patch) | |
tree | fc595c927d9b81f503ba928aeaf389c8e2711947 /monitor/display.c | |
parent | 2af9ef2fa0a3aee7bbeb7fd2c10205dd5fcfd2d3 (diff) | |
download | bluez-a4a615c7fba22ef88beae761cbf722cea21fc8d4.tar.gz |
monitor: Add option to force output color
Sometimes we want to force output color even when stdout is not a
terminal, for example when piping the output to a filter script and then
piping it further to a pager which can display colors.
This patch provides a general option to force whether color is on or off
(always and never), or leave btmon to decide (auto).
Reviewed-by: Daniel Winkler <danielwinkler@google.com>
Diffstat (limited to 'monitor/display.c')
-rw-r--r-- | monitor/display.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/monitor/display.c b/monitor/display.c index 4e5693b04..d61a79a38 100644 --- a/monitor/display.c +++ b/monitor/display.c @@ -29,12 +29,22 @@ static pid_t pager_pid = 0; int default_pager_num_columns = FALLBACK_TERMINAL_WIDTH; +enum monitor_color setting_monitor_color = COLOR_AUTO; + +void set_monitor_color(enum monitor_color color) +{ + setting_monitor_color = color; +} bool use_color(void) { static int cached_use_color = -1; - if (__builtin_expect(!!(cached_use_color < 0), 0)) + if (setting_monitor_color == COLOR_ALWAYS) + cached_use_color = 1; + else if (setting_monitor_color == COLOR_NEVER) + cached_use_color = 0; + else if (__builtin_expect(!!(cached_use_color < 0), 0)) cached_use_color = isatty(STDOUT_FILENO) > 0 || pager_pid > 0; return cached_use_color; |