muesli / termenv

Advanced ANSI style & color support for your terminal applications

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Better Windows 10 support

jwalton opened this issue · comments

I haven't tried your library on win10, so maybe you have some magic I don't know about, but I'm guessing this library works well in Windows Terminal, but not so much in cmd.com or powershell (where ANSI is disabled by default). But if I'm wrong and there's magic that makes this all work out, I'm very interested in what it is! :)

Over in gchalk, I first of all ported node.js's "supports-color" library which detects if the current Windows version supports 256 color or 16.7m color ANSI, and second I used this trick to enable ANSI color on non-Windows-Terminal terminals if it isn't enabled already. If you're interested in a PR that steals these, or which just uses supportscolor, I'm happy to supply one.

Hi! Termenv works well in the Windows command console (cmd.exe), however you do need some magic:

https://github.com/charmbracelet/lipgloss/blob/master/ansi_windows.go

We're using that implementation successfully in Lip Gloss and Glow, both of which employ Termenv for ANSI coloring.

Ahh, the magic is in Lip Gloss. 👍

Yeah, I'm basically already using the same trick:

https://github.com/jwalton/go-supportscolor/blob/8354fad5c72fe7d64106234170d3906d44bb5dc0/osutils_windows.go#L28

Just surprised this is in LipGloss and not down here in termenv.

Yeah, I can't speak to @muesli's intent, but I believe the idea with Termenv was to keep it from performing magic automatically. That said I do think some version of the functions we're using would be a nice utility function in Termenv.

My intent is indeed to not perform these kind of things auto-magically. I agree however that a convenient helper is better than copying this around everywhere, so I've just added it in #61.

Basic flow:

    mode, err := termenv.EnableWindowsANSIConsole()
    if err != nil {
        panic(err)
    }
    defer termenv.RestoreWindowsConsole(mode)

The defer termenv.RestoreWindowsConsole(mode) is a nice touch. I'm totally going to steal that for my library. ;)