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

Re: ANSI sequences produced on non-ANSI terminal

From
Jeff King <peff@peff.net>
Date
Sep 23, 2021, 21:20 UTC
Message-ID
<YUzvhLUmvsdF5w+r@coredump.intra.peff.net>
In-Reply-To
<20210923052122.2F655CE@eddie.starwolf.com>
On Wed, Sep 22, 2021 at 10:21:22PM -0700, The Grey Wolf wrote:
Show 12 quoted lines
> Anything else you want to add:
> 	I searched google and the documentation as best I was able for
> 	this, but I am unable to find anywhere that will let me disable
> 	(or enable) colour for a particular term type.  Sometimes I'm on
> 	an xterm, for which this is GREAT.  Sometimes I'm on a Wyse WY60,
> 	for which this is sub-optimal.  My workaround is to disable colour
> 	completely, which is reluctantly acceptable, but it would be nice
> 	to say "If I'm on an xterm/aterm/urxvt/ansi terminal, enable
> 	colour or cursor-positioning, otherwise shut it off."  If this
> 	seems too much of a one-off to handle, fine, but most things that
> 	talk fancy to screens are kind enough to allow an opt-out based on
> 	terminal type. :)

Git doesn't have any kind of list of terminals, beyond knowing that "dumb" should disable auto-color. It's possible we could expand that if there are known terminals that don't understand ANSI colors. I'm a bit wary of having a laundry list of obscure terminals, though.

If we built against ncurses or some other terminfo-aware library we could outsource that, but that would be a new dependency. I'm hesitant to do that even as an optional dependency given the bang-for-the-buck (and certainly making it require would be right out).

Obviously you can wrap Git with a script to tweak the config based on the current setting of the $TERM variable. It would be nice if you could have conditional config for that. E.g., something like:

  [includeIf "env:TERM==xterm"]
  path = gitconfig-color

That doesn't exist, but would fit in reasonably well with our other conditional config options.

As far as generating non-ANSI codes, that's all Git knows how to do. I'm not sure what kind of color codes your terminal might support. It _might_ be possible to support multiple, but from my knowledge of Git's color code I suspect it would be quite ugly. You'd probably be better off post-processing the ANSI codes. You can do so automatically-ish with something like:

  git config pager.log 'convert-ansi-to-whatever | less'

I don't know offhand of anything that would do such conversion out of the box, but you could probably built it around tput or a terminfo library.

Note that we do similar post-processing on Windows, albeit internally by intercepting fprintf, etc (yuck). See compat/winansi.c, which might give you some logic which would be reused.

-Peff
Previous: The Grey WolfNext: Junio C Hamano
Message 2 of 23 in “ANSI sequences produced on non-ANSI terminal”
  1. The Grey WolfSep 23, 2021
  2. Jeff KingSep 23, 2021
  3. Junio C HamanoSep 23, 2021
  4. Randall S. BeckerSep 23, 2021
  5. Kevin DaudtSep 25, 2021
  6. config: add an includeIf.env{Exists,Bool,Is,Match}Ævar Arnfjörð Bjarmason, Sep 24, 2021
  7. Jeff KingSep 24, 2021
  8. Junio C HamanoSep 24, 2021
  9. Jeff KingSep 24, 2021
  10. Junio C HamanoSep 27, 2021
  11. Jeff KingSep 27, 2021
  12. Randall S. BeckerSep 27, 2021
  13. Jeff KingSep 27, 2021
  14. Randall S. BeckerSep 27, 2021
  15. Ævar Arnfjörð BjarmasonSep 27, 2021
  16. Jeff KingSep 28, 2021
  17. Ævar Arnfjörð BjarmasonSep 28, 2021
  18. Jeff KingSep 28, 2021
  19. Ævar Arnfjörð BjarmasonSep 28, 2021
  20. Junio C HamanoSep 28, 2021
  21. GreywolfSep 24, 2021
  22. Jeff KingSep 25, 2021
  23. GreywolfOct 1, 2021

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.