fix: checking whether colors are available in the current terminal

This commit is contained in:
evilsocket 2018-02-08 07:36:48 +01:00
commit 68d3af261f

View file

@ -1,7 +1,12 @@
package core package core
import (
"github.com/mattn/go-isatty"
"os"
)
// https://misc.flogisoft.com/bash/tip_colors_and_formatting // https://misc.flogisoft.com/bash/tip_colors_and_formatting
const ( var (
BOLD = "\033[1m" BOLD = "\033[1m"
DIM = "\033[2m" DIM = "\033[2m"
@ -20,10 +25,30 @@ const (
BG_LBLUE = "\033[104m" BG_LBLUE = "\033[104m"
RESET = "\033[0m" RESET = "\033[0m"
NoColors = false
) )
const ON = GREEN + "✔" + RESET func init() {
const OFF = RED + "✘" + RESET NoColors := os.Getenv("TERM") == "dumb" ||
(!isatty.IsTerminal(os.Stdout.Fd()) && !isatty.IsCygwinTerminal(os.Stdout.Fd()))
if NoColors {
BOLD = ""
DIM = ""
RED = ""
GREEN = ""
BLUE = ""
YELLOW = ""
FG_BLACK = ""
FG_WHITE = ""
BG_DGRAY = ""
BG_RED = ""
BG_GREEN = ""
BG_YELLOW = ""
BG_LBLUE = ""
RESET = ""
}
}
const ( const (
DEBUG = iota DEBUG = iota