This is an archive of the discontinued Mercurial Phabricator instance.

color: add autoterminfo option to prefer terminfo over ansi for non-windows
AbandonedPublic

Authored by spectral on Jul 17 2017, 11:15 PM.

Details

Reviewers
None
Group Reviewers
hg-reviewers
Summary

If color.mode=auto in the config (this is the default) then color.py currently
checks if using windows, and if not, uses 'ansi'. This means that to get
terminfo-based terminal support, one has to specify color.mode=terminfo
explicitly; this enables several warnings if a user's terminal does not actually
have support for terminfo (for example, we failed to load curses, or the
terminal does not have a 'setaf' entry).

If color.autoterminfo is True, we will attempt to use terminfo, and *silently*
fallback to 'ansi' if it is not viable.

This patch does nothing to change the ui.debug messages that are output if
terminfo is chosen but the terminal does not support one of the "default"
features, such as 'dim' or 'invis'. Therefore, the fallback to 'ansi' if
terminfo is not available will be silent, but if terminfo *is* available but
does not support every feature, invocations with --debug will still see/start
to see "no terminfo entry for <feature>" messages.

Diff Detail

Repository
rHG Mercurial
Lint
Lint Skipped
Unit
Unit Tests Skipped

Event Timeline

spectral created this revision.Jul 17 2017, 11:15 PM

Looks good to me, though.

mercurial/color.py
259–264

For the real reviewer - this combines with modewarn() above to do the silent fallback promised above.

I like this, but I'd rather not take it right before a freeze. Can we revisit this for 4.4?

I like this, but I'd rather not take it right before a freeze. Can we revisit this for 4.4?

I'm fine with waiting. I was on the fence with whether to send this now or not anyway, and I understand the concern about finalizing a config option name. Closing/abandoning now, will try to reopen after the freeze. :)

spectral abandoned this revision.Jul 18 2017, 5:07 PM

Can we refactor color.mode=auto to do something reasonable, like detect and use terminfo if it is available? It always struck me as strange that auto doesn't actually get you the best possible experience.

FWIW, I think the color code needs to be massively refactored to support "nice things" like native 256 color usage, different profiles for different background colors, color blind awareness, customization based on TERM, etc.