Mercurial > hg > CbC > CbC_gcc
comparison gcc/diagnostic-color.c @ 131:84e7813d76e9
gcc-8.2
author | mir3636 |
---|---|
date | Thu, 25 Oct 2018 07:37:49 +0900 |
parents | 04ced10e8804 |
children | 1830386684a0 |
comparison
equal
deleted
inserted
replaced
111:04ced10e8804 | 131:84e7813d76e9 |
---|---|
1 /* Output colorization. | 1 /* Output colorization. |
2 Copyright (C) 2011-2017 Free Software Foundation, Inc. | 2 Copyright (C) 2011-2018 Free Software Foundation, Inc. |
3 | 3 |
4 This program is free software; you can redistribute it and/or modify | 4 This program is free software; you can redistribute it and/or modify |
5 it under the terms of the GNU General Public License as published by | 5 it under the terms of the GNU General Public License as published by |
6 the Free Software Foundation; either version 3, or (at your option) | 6 the Free Software Foundation; either version 3, or (at your option) |
7 any later version. | 7 any later version. |
22 | 22 |
23 #ifdef __MINGW32__ | 23 #ifdef __MINGW32__ |
24 # include <windows.h> | 24 # include <windows.h> |
25 #endif | 25 #endif |
26 | 26 |
27 /* Select Graphic Rendition (SGR, "\33[...m") strings. */ | 27 #include "color-macros.h" |
28 /* Also Erase in Line (EL) to Right ("\33[K") by default. */ | |
29 /* Why have EL to Right after SGR? | |
30 -- The behavior of line-wrapping when at the bottom of the | |
31 terminal screen and at the end of the current line is often | |
32 such that a new line is introduced, entirely cleared with | |
33 the current background color which may be different from the | |
34 default one (see the boolean back_color_erase terminfo(5) | |
35 capability), thus scrolling the display by one line. | |
36 The end of this new line will stay in this background color | |
37 even after reverting to the default background color with | |
38 "\33[m', unless it is explicitly cleared again with "\33[K" | |
39 (which is the behavior the user would instinctively expect | |
40 from the whole thing). There may be some unavoidable | |
41 background-color flicker at the end of this new line because | |
42 of this (when timing with the monitor's redraw is just right). | |
43 -- The behavior of HT (tab, "\t") is usually the same as that of | |
44 Cursor Forward Tabulation (CHT) with a default parameter | |
45 of 1 ("\33[I"), i.e., it performs pure movement to the next | |
46 tab stop, without any clearing of either content or screen | |
47 attributes (including background color); try | |
48 printf 'asdfqwerzxcv\rASDF\tZXCV\n' | |
49 in a bash(1) shell to demonstrate this. This is not what the | |
50 user would instinctively expect of HT (but is ok for CHT). | |
51 The instinctive behavior would include clearing the terminal | |
52 cells that are skipped over by HT with blank cells in the | |
53 current screen attributes, including background color; | |
54 the boolean dest_tabs_magic_smso terminfo(5) capability | |
55 indicates this saner behavior for HT, but only some rare | |
56 terminals have it (although it also indicates a special | |
57 glitch with standout mode in the Teleray terminal for which | |
58 it was initially introduced). The remedy is to add "\33K" | |
59 after each SGR sequence, be it START (to fix the behavior | |
60 of any HT after that before another SGR) or END (to fix the | |
61 behavior of an HT in default background color that would | |
62 follow a line-wrapping at the bottom of the screen in another | |
63 background color, and to complement doing it after START). | |
64 Piping GCC's output through a pager such as less(1) avoids | |
65 any HT problems since the pager performs tab expansion. | |
66 | |
67 Generic disadvantages of this remedy are: | |
68 -- Some very rare terminals might support SGR but not EL (nobody | |
69 will use "gcc -fdiagnostics-color" on a terminal that does not | |
70 support SGR in the first place). | |
71 -- Having these extra control sequences might somewhat complicate | |
72 the task of any program trying to parse "gcc -fdiagnostics-color" | |
73 output in order to extract structuring information from it. | |
74 A specific disadvantage to doing it after SGR START is: | |
75 -- Even more possible background color flicker (when timing | |
76 with the monitor's redraw is just right), even when not at the | |
77 bottom of the screen. | |
78 There are no additional disadvantages specific to doing it after | |
79 SGR END. | |
80 | |
81 It would be impractical for GCC to become a full-fledged | |
82 terminal program linked against ncurses or the like, so it will | |
83 not detect terminfo(5) capabilities. */ | |
84 #define COLOR_SEPARATOR ";" | |
85 #define COLOR_NONE "00" | |
86 #define COLOR_BOLD "01" | |
87 #define COLOR_UNDERSCORE "04" | |
88 #define COLOR_BLINK "05" | |
89 #define COLOR_REVERSE "07" | |
90 #define COLOR_FG_BLACK "30" | |
91 #define COLOR_FG_RED "31" | |
92 #define COLOR_FG_GREEN "32" | |
93 #define COLOR_FG_YELLOW "33" | |
94 #define COLOR_FG_BLUE "34" | |
95 #define COLOR_FG_MAGENTA "35" | |
96 #define COLOR_FG_CYAN "36" | |
97 #define COLOR_FG_WHITE "37" | |
98 #define COLOR_BG_BLACK "40" | |
99 #define COLOR_BG_RED "41" | |
100 #define COLOR_BG_GREEN "42" | |
101 #define COLOR_BG_YELLOW "43" | |
102 #define COLOR_BG_BLUE "44" | |
103 #define COLOR_BG_MAGENTA "45" | |
104 #define COLOR_BG_CYAN "46" | |
105 #define COLOR_BG_WHITE "47" | |
106 #define SGR_START "\33[" | |
107 #define SGR_END "m\33[K" | |
108 #define SGR_SEQ(str) SGR_START str SGR_END | |
109 #define SGR_RESET SGR_SEQ("") | |
110 | |
111 | 28 |
112 /* The context and logic for choosing default --color screen attributes | 29 /* The context and logic for choosing default --color screen attributes |
113 (foreground and background colors, etc.) are the following. | 30 (foreground and background colors, etc.) are the following. |
114 -- There are eight basic colors available, each with its own | 31 -- There are eight basic colors available, each with its own |
115 nominal luminosity to the human eye and foreground/background | 32 nominal luminosity to the human eye and foreground/background |