mirror of
https://github.com/bettercap/bettercap
synced 2025-08-21 05:53:20 -07:00
fix: checking whether colors are available in the current terminal
This commit is contained in:
parent
3bedfdb18b
commit
68d3af261f
1 changed files with 28 additions and 3 deletions
31
core/swag.go
31
core/swag.go
|
@ -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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue