go-colortext icon indicating copy to clipboard operation
go-colortext copied to clipboard

How to support cygwin terminal

Open ccpaging opened this issue 7 years ago • 6 comments

https://cygwin.com/install.html

It is mintty in windows.

ccpaging avatar Jun 23 '17 03:06 ccpaging

Doesn't it work now? cygwin should support ANSI

daviddengcn avatar Jun 23 '17 15:06 daviddengcn

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.

ccpaging avatar Jun 29 '17 08:06 ccpaging

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.

ccpaging avatar Jun 30 '17 09:06 ccpaging

https://github.com/mattn/go-isatty

NoColor = (os.Getenv("TERM") == "dumb")
WinColor = isatty.IsTerminal(os.Stdout.Fd())

ccpaging avatar Jun 30 '17 09:06 ccpaging

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!

daviddengcn avatar Jun 30 '17 17:06 daviddengcn

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:

  1. Use external package to get terminal type.

https://github.com/mattn/go-isatty

  1. Use interface to speed up.

ccpaging avatar Jul 01 '17 09:07 ccpaging