colors!
parent
59ed0fc7da
commit
04b8cad832
@ -0,0 +1,13 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// IsTerminal returns true if the given file descriptor is a terminal.
|
||||
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
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
// +build darwin dragonfly freebsd netbsd openbsd
|
||||
|
||||
package main
|
||||
|
||||
import "syscall"
|
||||
|
||||
const ioctlReadTermios = syscall.TIOCGETA
|
@ -0,0 +1,6 @@
|
||||
package terminal
|
||||
|
||||
// These constants are declared here, rather than importing
|
||||
// them from the syscall package as some syscall packages, even
|
||||
// on linux, for example gccgo, do not declare them.
|
||||
const ioctlReadTermios = 0x5401 // syscall.TCGETS
|
@ -0,0 +1,22 @@
|
||||
package termcolors
|
||||
|
||||
type Color []byte
|
||||
|
||||
const keyEscape = 27
|
||||
|
||||
var (
|
||||
Black = Color{keyEscape, '[', '3', '0', 'm'}
|
||||
Red = Color{keyEscape, '[', '3', '1', 'm'}
|
||||
Green = Color{keyEscape, '[', '3', '2', 'm'}
|
||||
Yellow = Color{keyEscape, '[', '3', '3', 'm'}
|
||||
Blue = Color{keyEscape, '[', '3', '4', 'm'}
|
||||
Magenta = Color{keyEscape, '[', '3', '5', 'm'}
|
||||
Cyan = Color{keyEscape, '[', '3', '6', 'm'}
|
||||
White = Color{keyEscape, '[', '3', '7', 'm'}
|
||||
Reset = Color{keyEscape, '[', '0', 'm'}
|
||||
)
|
||||
|
||||
// not efficient.
|
||||
func WrapString(c Color, s string) string {
|
||||
return string(c) + s + string(Reset)
|
||||
}
|
Loading…
Reference in New Issue