-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Add (optional) color to make output of --help easier to read #340
Comments
Optional probably means a config flag (like color.ui in Git). And generaly speaking, colors in the output should be removed when the output is not a tty, otherwise it can create problems when output is piped into a command. As --help would probably be piped to a pager, we could avoid checking if the output is a tty and instead tell people to use a pager that can accept colors (like Also the output of --help could be quite nice already if it was really a man page, or if there was a flag (like git help -w) to open an HTML version of the help text in a web browser. |
https://github.com/mattn/go-isatty/ can be used to know if the output is on a terminal. |
@chriscool go-isatty looks great, but maybe going throuth the trouble of vendoring one more package that just wraps one system call is a little too much for our purposes? Checking if the stdout is on a terminal goes through this system call for stdoutput tty parameters on both linux and BSD (Mac OS): func isTerminal() {
const stdoutFD = 1
var dimensions [4]uint16
if _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(stdoutFD), uintptr(syscall.TIOCGWINSZ), uintptr(unsafe.Pointer(&dimensions)), 0, 0, 0); err != 0 {
return 'Not a terminal'
}
terminalWidth = int(dimensions[1])
return "Is a terminal with " + string(terminalWidth) + " symbol width";
} Only on Windows it is different, but Powershell does not understand the standard escape symbol coloring anyway, if I understand it correctly. I have been using this system call in my and it also yeilds other useful parameters like dimensions of the terminal (symbol width) which you can use to format nice things (like hr lines). I am going to work on this issue, if everyone is cool with this approach of just using that system call for Unix systems. |
@dborzov I like this, vendoring is great, but an entire package for a single call is a bit much. On windows i think we can just always return false (windows doesnt have ttys!!) and not have colors in windows. |
To be fair, there are only three functions in the package. (bsd, linux, windows) func IsTerminal(fd uintptr) bool {
var st uint32
r, _, e := syscall.Syscall(procGetConsoleMode.Addr(), 2, fd, uintptr(unsafe.Pointer(&st)), 0)
return r != 0 && e == 0
}
func IsTerminal(fd uintptr) bool {
var termios syscall.Termios
_, _, err := syscall.Syscall6(syscall.SYS_IOCTL, fd, ioctlReadTermios, uintptr(unsafe.Pointer(&termios)), 0, 0, 0)
return err == 0
}
func IsTerminal(fd uintptr) bool {
var termios syscall.Termios
_, _, err := syscall.Syscall6(syscall.SYS_IOCTL, fd, ioctlReadTermios, uintptr(unsafe.Pointer(&termios)), 0, 0, 0)
return err == 0
} |
haha, just that? okay then |
This is one of the really stupid things about how Go packaging is done today. That current vendoring overhead encourages this kind of thinking. to those of us that have had the lovely experience of working with npm and proper packaging, packages tend to be only one function. Whenever possible, reuse code. vendoring is not a huge deal. I know godep is not the nicest/easiest thing in the world, but using packages is TRTTD. |
@jbenet , yeah, fair enough, we should vendor this out. |
Plus, it turned out there is already an |
I've started working on this (see screenshot). If you guys still prefer the config file, I need some help in how to restructure the starting process. |
I like |
Perhaps, when no config exists, the program can be treated as though the color option is not specified. |
reduce background goroutines
No description provided.
The text was updated successfully, but these errors were encountered: