go-colortext
go-colortext copied to clipboard
How to support cygwin terminal
https://cygwin.com/install.html
It is mintty in windows.
Doesn't it work now? cygwin should support ANSI
No. It does not work. Since cygwin use ANSI and not windows console.
Checking environment variable "TERM=xterm-256color" or "TERM=cygwin" in ct_win.go may solve the problem.
After adding some ugly code,
import (
"syscall"
"unsafe"
"os"
"fmt"
)
var (
IsTerminal = os.Getenv("TERM") != "" &&
os.Getenv("TERM") != "cygwin"
)
Calling ANSI code if IsTerminal true.
Test color text OK in cygwin mintty / tmux, cygwin's bash, windows command prompt, ConEmu, Power Shell.
https://github.com/mattn/go-isatty
NoColor = (os.Getenv("TERM") == "dumb")
WinColor = isatty.IsTerminal(os.Stdout.Fd())
The chosing between ANSI and console API happens at compilation time. I supposed if you compile the binary under cygwin, Go should choose ct_ansi.go instead of ct_win.go. The magic lays on the first line of those two files. I do not have cygwin environment, can you help me by trying to fix that line if possible? Thanks!
https://github.com/ccpaging/go-colortext
I had tested it in linux console/term, windows console prompt / Power Shell / ConEmu / cygwin Bash, cygwin mintty/bash/tmux.
Changelog:
- Use external package to get terminal type.
https://github.com/mattn/go-isatty
- Use interface to speed up.