Emit dedicated bright terminal color codes if supported
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Mon, 4 Nov 2019 18:49:04 +0000 (13:49 -0500)
committerSimon Marchi <simon.marchi@efficios.com>
Tue, 12 Nov 2019 14:33:04 +0000 (09:33 -0500)
commit046094875e3f03883c14ee084f9582c0c15f3c50
tree16d5d1ca517fefdc52b14659ebf4f80c68d72682
parent17f3083a0b4d318d3303c8a5bfa63db6a874ec73
Emit dedicated bright terminal color codes if supported

Some terminals support having a bold normal foreground color which is
_not_ bright. kitty is one of them, as well as GNOME Terminal with the
fairly recent "Show bold text in bright colors" option turned off (or
when calling the underlying vte_terminal_set_bold_is_bright() function
with the appropriate value).

An easy test is to execute:

    $ echo -e "\033[31mTHIS\n\033[1mTHAT\033[0m"

and compare the colors of both lines: if they are the same, then the
terminal supports non-bright bold foreground colors.

For those terminals, the way to have a non-bold bright color is to emit
the dedicated SGR codes 90 to 97:

    $ echo -e "\033[91mHELLO\033[0m"

Some terminals can print non-bold bright colors, but cannot print
non-bright bold colors.

This patch makes the Babeltrace project emit different color codes
depending on the connected terminal and the new
`BABELTRACE_TERM_COLOR_BRIGHT_MEANS_BOLD` environment variable's value:

kitty or `BABELTRACE_TERM_COLOR_BRIGHT_MEANS_BOLD` is `0`:
    Output bright colors using dedicated SGR codes 90 to 97.

Otherwise:
    Output bright colors with bold + SGR codes 30 to 37.

This patch effectively makes the Babeltrace modules emit correct bright
color codes for kitty.

To change as little as possible, I updated all the sites which emit a
bold code followed by a foreground color code to emit instead a bold
color code followed by a bright foreground color code. The only drawback
with the current approach is that, for non-kitty terminals, two bold
color codes are emitted for those cases (the real bold and the
brightening bold).

This means all bold colored text is also bright currently. Eventually we
can start decoupling the bold attribute from bright colors if need be,
although this means users must have a supporting terminal.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I3e0124942294fbe833d33aa59506c67e6ca85700
Reviewed-on: https://review.lttng.org/c/babeltrace/+/2328
CI-Build: Simon Marchi <simon.marchi@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
doc/man/common-common-env.txt
src/cli/babeltrace2.c
src/common/assert.c
src/common/common.c
src/common/common.h
src/plugins/text/details/colors.h
src/plugins/text/details/write.c
src/plugins/text/pretty/pretty.c
src/plugins/text/pretty/pretty.h
src/plugins/text/pretty/print.c
This page took 0.026234 seconds and 4 git commands to generate.