package logs import ( "github.com/mattn/go-isatty" "os" ) type Color string var ( //fgBlack Color = "\x1b[30m" //fgWhiteItalic Color = "\x1b[37;3m" FgRed Color = "\x1b[31m" FgGreen Color = "\x1b[32m" FgYellow Color = "\x1b[33m" FgBlue Color = "\x1b[34m" FgMagenta Color = "\x1b[35m" FgCyan Color = "\x1b[36m" FgWhite Color = "\x1b[37m" FgHiBlack Color = "\x1b[90m" fgGreenItalic Color = "\x1b[32;3m" // NoColor defines if the output is colorized or not. It's dynamically set to // false or true based on the stdout's file descriptor referring to a terminal // or not. It's also set to true if the NO_COLOR environment variable is // set (regardless of its value). This is a global option and affects all // colors. For more control over each Color block use the methods // DisableColor() individually. noColor = noColorIsSet() || os.Getenv("TERM") == "dumb" || (!isatty.IsTerminal(os.Stdout.Fd()) && !isatty.IsCygwinTerminal(os.Stdout.Fd())) ) // noColorIsSet returns true if the environment variable NO_COLOR is set to a non-empty string. func noColorIsSet() bool { return os.Getenv("NO_COLOR") != "" } func (c Color) Wrap(msg string) string { if noColorIsSet() || noColor { return msg } return string(c) + msg + "\x1b[0m" }