Author Topic: again colored text output of commandline programs (MeShell)  (Read 5672 times)

Martin Vieregg

  • Sr. Member
  • ****
  • Posts: 278
  • Karma: +2/-0
    • View Profile
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

  • Hero Member
  • *****
  • Posts: 4786
  • Karma: +99/-1
    • View Profile
Re: again colored text output of commandline programs (MeShell)
« Reply #1 on: May 08, 2020, 04:10:32 am »
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: [Select]
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;
}

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

  • Full Member
  • ***
  • Posts: 169
  • Karma: +8/-6
    • View Profile
    • OS/2 API Research
Re: again colored text output of commandline programs (MeShell)
« Reply #2 on: May 08, 2020, 08:25:15 am »
Can someone explain please how this works?

It's "VioWrtNAttr()", an old, very old 16-bit function  :o

Martin Vieregg

  • Sr. Member
  • ****
  • Posts: 278
  • Karma: +2/-0
    • View Profile
Re: again colored text output of commandline programs (MeShell)
« Reply #3 on: May 08, 2020, 08:41:13 am »
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.
« Last Edit: May 08, 2020, 08:46:16 am by Martin Vieregg »

Dave Yeo

  • Hero Member
  • *****
  • Posts: 4786
  • Karma: +99/-1
    • View Profile
Re: again colored text output of commandline programs (MeShell)
« Reply #4 on: May 08, 2020, 04:32:23 pm »
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

Martin Vieregg

  • Sr. Member
  • ****
  • Posts: 278
  • Karma: +2/-0
    • View Profile
Re: again colored text output of commandline programs (MeShell)
« Reply #5 on: May 08, 2020, 06:33:09 pm »
OK, an interesting hint. So in GCC, a MeShell user has to use
-fdiagnostics-color=always

But by default, the stderr output is shown in red color in MeShell. So I have to turn this functionlity off in these circumstances. A checkbox is an option, perhaps in the Top Panel for fast access. Or I implement another more intelligent mechanism (?). Any ideas are appreciated. Turning off the color when ESC sequences are coming could be too late because the output already began in red color. Perhaps I could correct the output in the editor if an ESC sequence comes through the stderr pipe. An automatic solution would be preffered.

Dave Yeo

  • Hero Member
  • *****
  • Posts: 4786
  • Karma: +99/-1
    • View Profile
Re: again colored text output of commandline programs (MeShell)
« Reply #6 on: May 09, 2020, 04:22:01 am »
OK, an interesting hint. So in GCC, a MeShell user has to use
-fdiagnostics-color=always

It seems to be enabled here whether fdiagnostics-color=always is in the CFLAGS or not. I believe our port is built with it enabled so would need something like fdiagnostics-color=no to turn off.
Quote
But by default, the stderr output is shown in red color in MeShell. So I have to turn this functionlity off in these circumstances. A checkbox is an option, perhaps in the Top Panel for fast access. Or I implement another more intelligent mechanism (?). Any ideas are appreciated. Turning off the color when ESC sequences are coming could be too late because the output already began in red color. Perhaps I could correct the output in the editor if an ESC sequence comes through the stderr pipe. An automatic solution would be preffered.

I wonder how it is turned off when piping the output or redirecting? It seems automatic.

Martin Vieregg

  • Sr. Member
  • ****
  • Posts: 278
  • Karma: +2/-0
    • View Profile
Re: again colored text output of commandline programs (MeShell)
« Reply #7 on: May 09, 2020, 09:04:20 am »
Quote
I wonder how it is turned off when piping the output or redirecting? It seems automatic.

Yes, in the gcc docu, you can read that the default setting is "automatic".

Now, I have thaught about the color problem. The correct color handling with ESC sequences in stderr is not programmed yet, only for stdout. In MeShell 0.61, I will implement user settings for two different foreground (text) default colors for stdout and stderr output. If you use such compilers where a lot of (colored) output is running via stderr, the red color is definitely not the first choice. I will implement both default colors in the ini file and program parameters and I will implement a mechanism where you can easy transfer the current color settings to a string for the program parameters.

Do you use batch files for executing your compilers and tools?
Another idea for useful MeShell functionality would be to define unique shortcut strings which are simply replaced when sending the prompt string to cmd.exe. It would simplify this work. This would be more handy in some cases than writing tiny batch files.

Compilers from Unix often use Unix EOL encoded output. This is supported since MeShell 0.60 and was defective/not supported before.