git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [msysGit] Re: Need your help with MinGW Issue 17: --color options don't work (produce garbage)

From
RDReece Dunn <msclrhd@googlemail.com>
Date
Aug 15, 2007, 08:31 UTC
Message-ID
<3f4fd2640708150131o7578c2efy806891fc3def7429@mail.gmail.com>
In-Reply-To
<a1bbc6950708150103v35330b47o781fb5d74e3d9aef@mail.gmail.com>
On 15/08/07, Dmitry Kakurin <dmitry.kakurin@gmail.com> wrote:
Show 30 quoted lines
> On 8/15/07, Reece Dunn <msclrhd@googlemail.com> wrote:
> >
> > On 15/08/07, Dmitry Kakurin wrote:
> > > Here are the facts:
> > >
> > > 'git branch --color' produces garbage:
> > > $ git branch --color
> > >   devel←[m
> > >   dima←[m
> > >   dmitryk←[m
> > > * ←[32mmaster←[m
> > >   mob←[m
> > >   next←[m
> > >
> > > 'git branch --color | cat' produces expected colored output.
> > >
> > > I've traced it down to printf statement in gdb and it sends the right
> > > esc-sequence.
> > > Where should I look next?
> >
> > Windows doesn't recognise the *nix printf colour codes.
> >
> > Piping through cat will be going through cygwin/mingw emulation,
> > translating the colour codes to the correct API calls.
>
> That's my question. If there is a way to build cat.exe to do this kind
> of emulation under MinGW then I should be able to do the same for
> git.exe.
> I hope I just need to #define something while building Git.
> But what is it?

You will need to implement cat (or something similar) on MinGW that will process the *nix colour codes and then pass that to SetConsoleTextAttributes. For example:

    int ch = 0;
    while(( ch = getch()) != EOF )
    {
        if( /*ch is part of a colour sequence*/ )
        {
            SetConsoleTextAttribute( GetStdHandle(...),
win_color_from_color_sequence(...));
        }
        else putc( ch );
    }

I don't believe that MinGW has got this working for cat, that is why one that supports colours on Windows needs to be written.

- Reece
Previous: Dmitry KakurinNext: Dmitry Kakurin
Message 4 of 10 in “Need your help with MinGW Issue 17: --color options don't work (produce garbage)”
  1. Dmitry KakurinAug 15, 2007
  2. Reece DunnAug 15, 2007
  3. Dmitry KakurinAug 15, 2007
  4. Reece DunnAug 15, 2007
  5. Dmitry KakurinAug 15, 2007
  6. Johannes SchindelinAug 15, 2007
  7. Rogan DawesAug 15, 2007
  8. Junio C HamanoAug 15, 2007
  9. Rogan DawesAug 15, 2007
  10. Rogan DawesAug 21, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.