Hi Bruno, > Le 27 janv. 2019 à 18:39, Bruno Haible <br...@clisp.org> a écrit : > > Hi Akim, > >> I'd like to have colored diagnostics in Bison, I do feel on occasion it would >> make it easier to spot errors and warnings for instance. >> >> AFAICT, gnulib does not feature any module to help do this. Coreutils (ls) >> and GCC (maybe diffutils too) are probably good sources of inspiration, but >> am I missing something? Should I look elsewhere first? Would a gnulib >> module >> make sense? > > ---------------------------------------------------------------------------- > > There are two approaches to decide which colors to produce: > (A) In a first step, produce output without colors. In a second step, > add the colors, usually through regular expressions. > (B) Add the colors directly when you produce the output, through interleaved > statements that turn on or off specific attributes. > > I believe that (A) is good for log files, whereas (B) is preferrable for > more complex syntax, such as JSON, XML, or programming language text.
Yes, I was clearly aiming at (B). > There are three approaches to defining the colors and attributes for specific > syntactic roles: > (I) Hard code the escape sequences in the program. > (II) Let the user specify terminal-dependent escape sequences, e.g. through > an environment variable using an obscure syntax, or through a > configuration file. > (III) Let the user specify colors and attributes through a CSS file, and > let the program translate these colors and attribute specifications > to the terminal-dependent escape sequences. I was thinking about (II), and would never have thought about (III) unless I was aware of the existence of a library providing supports for CSS on a terminal output. > The advantages of (III), compared to (II), are: > - The specification is terminal independent. > - Easier to change for the user. > > (II) is the approach used by the coreutils for 'ls', with a helper program > called 'dircolors'. [1][2][3] > Likewise for 'diff' ([4], option '--palette'). > (III) is the approach used by GNU gettext for 'msgcat' and friends [5], and > by GNU source-highlight [6]. No helper program is needed. Amazing... > If you want the combination of (B) and (III): Well, I was going for B.II, but now that you teased me with B.III, I can't wait for it! > I'm in the process of extracting > the color and style code from GNU gettext into a library 'libtextstyle'. You > can get an impression of it and how it can be used by looking at these links: > https://www.gnu.org/software/gettext/manual/html_node/The-_002d_002dcolor-option.html > https://www.gnu.org/software/gettext/manual/html_node/The-TERM-variable.html > https://www.gnu.org/software/gettext/manual/html_node/The-_002d_002dstyle-option.html > https://git.savannah.gnu.org/gitweb/?p=gettext.git;a=blob_plain;f=gettext-tools/styles/po-default.css;hb=HEAD > https://git.savannah.gnu.org/gitweb/?p=gettext.git;a=blob_plain;f=gettext-tools/styles/po-vim.css;hb=HEAD > https://git.savannah.gnu.org/gitweb/?p=gettext.git;a=blob;f=gettext-tools/src/color.h > https://git.savannah.gnu.org/gitweb/?p=gettext.git;a=blob;f=gettext-tools/src/write-po.c > lines 156..226, 449..514. > But it's not ready yet. It looks very promising! Thanks!