Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better Windows 10 support #36

Closed
jwalton opened this issue Apr 5, 2021 · 6 comments
Closed

Better Windows 10 support #36

jwalton opened this issue Apr 5, 2021 · 6 comments

Comments

@jwalton
Copy link

jwalton commented Apr 5, 2021

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.

@meowgorithm
Copy link
Collaborator

meowgorithm commented May 24, 2021

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.

@jwalton
Copy link
Author

jwalton commented May 24, 2021

Ahh, the magic is in Lip Gloss. 👍

@jwalton jwalton closed this as completed May 24, 2021
@jwalton
Copy link
Author

jwalton commented May 24, 2021

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.

@meowgorithm
Copy link
Collaborator

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.

@muesli
Copy link
Owner

muesli commented Jan 31, 2022

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)

@jwalton
Copy link
Author

jwalton commented Jan 31, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants