OS/2, eCS & ArcaOS - Technical > Programming
again colored text output of commandline programs (MeShell)
Martin Vieregg:
We already discussed the question how commandline programs with colored text output are working. Meanwhile, I got feedback that several programs like the gcc compiler and other programs coming from Unix do not show colored output in MeShell. So they do not use ESC sequences which run through the pipe without problems. But the VIO window rests empty - in comparison to Laurence which programmed a sample for me (see here) where the output is shown without colors in MeShell and simultaneously colored in the VIO window.
So it seems that there is a third way of showing colored text besides a VIO output to the screen buffer and ESC sequences via Stdout. Can someone explain please how this works? The linked thread contains an attachment with a colored tree.exe. It seems to be an old 16 bit application. It shows colored directory names in the original commandline window, MeShell shows the output without color and the MeShell VIO window rests empty. This behaviour seems to happen often with utilities coming from Unix like gcc.
Dave Yeo:
I have noticed a lot of programs, especially *nix ports, turn off colours when output is redirected. eg, if building something, I often redirect the output like so, "make 2>&1 | tee build.log" which results in no colours in the window or escape sequences in the log and no escape sequences to be seen. Running just make results in GCC outputting colours for errors.
An example from FFmpeg's cmdutils.c for outputting colours,
--- Code: ---int show_colors(void *optctx, const char *opt, const char *arg)
{
const char *name;
const uint8_t *rgb;
int i;
printf("%-32s #RRGGBB\n", "name");
for (i = 0; name = av_get_known_color_name(i, &rgb); i++)
printf("%-32s #%02x%02x%02x\n", name, rgb[0], rgb[1], rgb[2]);
return 0;
}
--- End code ---
When this was introduced, it just worked on Linux and on OS/2 whereas Windows needed ANSI.SYS or such loaded to work.
Sergey Posokhov:
--- Quote from: Martin Vieregg on May 07, 2020, 07:47:36 pm ---Can someone explain please how this works?
--- End quote ---
It's "VioWrtNAttr()", an old, very old 16-bit function :o
Martin Vieregg:
Yes, that is a plausible explanation. I found a page where this setting is described for gcc:
https://reversed.top/2015-10-25/enable-colorization-of-gcc-output/
Another program with this behaviour seems to be qt5 git. So it seems to be common in current unix-ported tools.
I could collect these settings in the MeShell docu, chapter "Compatibility problems with existing programs". If anyone uses MeShell for these programs, it would be nice to get a collection of the correct parameters.
Dave Yeo:
Colours on GCC seems also to be a build option, which probably explains why it just works here with no GCC_COLORS set. The latest documentation on it is at https://gcc.gnu.org/onlinedocs/gcc-9.1.0/gcc/Diagnostic-Message-Formatting-Options.html
Navigation
[0] Message Index
[#] Next page
Go to full version