1 /* Terminal color manipulation macros.
2 Copyright (C) 2005-2020 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #ifndef GCC_COLOR_MACROS_H
21 #define GCC_COLOR_MACROS_H
23 /* Select Graphic Rendition (SGR, "\33[...m") strings. */
24 /* Also Erase in Line (EL) to Right ("\33[K") by default. */
25 /* Why have EL to Right after SGR?
26 -- The behavior of line-wrapping when at the bottom of the
27 terminal screen and at the end of the current line is often
28 such that a new line is introduced, entirely cleared with
29 the current background color which may be different from the
30 default one (see the boolean back_color_erase terminfo(5)
31 capability), thus scrolling the display by one line.
32 The end of this new line will stay in this background color
33 even after reverting to the default background color with
34 "\33[m', unless it is explicitly cleared again with "\33[K"
35 (which is the behavior the user would instinctively expect
36 from the whole thing). There may be some unavoidable
37 background-color flicker at the end of this new line because
38 of this (when timing with the monitor's redraw is just right).
39 -- The behavior of HT (tab, "\t") is usually the same as that of
40 Cursor Forward Tabulation (CHT) with a default parameter
41 of 1 ("\33[I"), i.e., it performs pure movement to the next
42 tab stop, without any clearing of either content or screen
43 attributes (including background color); try
44 printf 'asdfqwerzxcv\rASDF\tZXCV\n'
45 in a bash(1) shell to demonstrate this. This is not what the
46 user would instinctively expect of HT (but is ok for CHT).
47 The instinctive behavior would include clearing the terminal
48 cells that are skipped over by HT with blank cells in the
49 current screen attributes, including background color;
50 the boolean dest_tabs_magic_smso terminfo(5) capability
51 indicates this saner behavior for HT, but only some rare
52 terminals have it (although it also indicates a special
53 glitch with standout mode in the Teleray terminal for which
54 it was initially introduced). The remedy is to add "\33K"
55 after each SGR sequence, be it START (to fix the behavior
56 of any HT after that before another SGR) or END (to fix the
57 behavior of an HT in default background color that would
58 follow a line-wrapping at the bottom of the screen in another
59 background color, and to complement doing it after START).
60 Piping GCC's output through a pager such as less(1) avoids
61 any HT problems since the pager performs tab expansion.
63 Generic disadvantages of this remedy are:
64 -- Some very rare terminals might support SGR but not EL (nobody
65 will use "gcc -fdiagnostics-color" on a terminal that does not
66 support SGR in the first place).
67 -- Having these extra control sequences might somewhat complicate
68 the task of any program trying to parse "gcc -fdiagnostics-color"
69 output in order to extract structuring information from it.
70 A specific disadvantage to doing it after SGR START is:
71 -- Even more possible background color flicker (when timing
72 with the monitor's redraw is just right), even when not at the
74 There are no additional disadvantages specific to doing it after
77 It would be impractical for GCC to become a full-fledged
78 terminal program linked against ncurses or the like, so it will
79 not detect terminfo(5) capabilities. */
81 #define COLOR_SEPARATOR ";"
82 #define COLOR_NONE "00"
83 #define COLOR_BOLD "01"
84 #define COLOR_UNDERSCORE "04"
85 #define COLOR_BLINK "05"
86 #define COLOR_REVERSE "07"
87 #define COLOR_FG_BLACK "30"
88 #define COLOR_FG_RED "31"
89 #define COLOR_FG_GREEN "32"
90 #define COLOR_FG_YELLOW "33"
91 #define COLOR_FG_BLUE "34"
92 #define COLOR_FG_MAGENTA "35"
93 #define COLOR_FG_CYAN "36"
94 #define COLOR_FG_WHITE "37"
95 #define COLOR_BG_BLACK "40"
96 #define COLOR_BG_RED "41"
97 #define COLOR_BG_GREEN "42"
98 #define COLOR_BG_YELLOW "43"
99 #define COLOR_BG_BLUE "44"
100 #define COLOR_BG_MAGENTA "45"
101 #define COLOR_BG_CYAN "46"
102 #define COLOR_BG_WHITE "47"
103 #define SGR_START "\33["
104 #define SGR_END "m\33[K"
105 #define SGR_SEQ(str) SGR_START str SGR_END
106 #define SGR_RESET SGR_SEQ("")
108 #endif /* GCC_COLOR_MACROS_H */