-color more similar to grep
This commit is contained in:
parent
86243bf464
commit
ef4059c144
1 changed files with 36 additions and 9 deletions
|
@ -20,6 +20,39 @@ import (
|
|||
"gopkg.in/mgo.v2/bson"
|
||||
)
|
||||
|
||||
type BoolAuto uint
|
||||
|
||||
const (
|
||||
BoolAuto_NO BoolAuto = iota
|
||||
BoolAuto_YES BoolAuto = iota
|
||||
BoolAuto_AUTO BoolAuto = iota
|
||||
)
|
||||
|
||||
func (b *BoolAuto) String() string {
|
||||
switch *b {
|
||||
case BoolAuto_NO:
|
||||
return "no"
|
||||
case BoolAuto_YES:
|
||||
return "always"
|
||||
case BoolAuto_AUTO:
|
||||
return "auto"
|
||||
}
|
||||
return ""
|
||||
}
|
||||
func (b *BoolAuto) Set(s string) error {
|
||||
switch s {
|
||||
case "auto":
|
||||
*b = BoolAuto_AUTO
|
||||
case "always":
|
||||
*b = BoolAuto_YES
|
||||
case "no":
|
||||
*b = BoolAuto_NO
|
||||
default:
|
||||
return fmt.Errorf("Invalid value %s", s)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
addr := flag.String("addr", "localhost:9080", "http service address")
|
||||
querySocket := flag.String("socket", "", "Path to a unix domain socket for the HTTP server")
|
||||
|
@ -27,17 +60,11 @@ func main() {
|
|||
var filter filtering.ExprValue
|
||||
flag.Var(&filter, "where", "sql-like query to filter logs")
|
||||
// TODO: change to color-mode=auto/no/always
|
||||
noColor := flag.Bool("no-color", false, "disable colors")
|
||||
forceColor := flag.Bool("force-color", false, "force colors even on TTY")
|
||||
hasColor := BoolAuto_AUTO
|
||||
flag.Var(&hasColor, "color", "dis/enable colors")
|
||||
flag.Parse()
|
||||
|
||||
if *noColor && *forceColor {
|
||||
fmt.Fprintln(os.Stderr, "Can't use both -no-color and -force-color")
|
||||
flag.Usage()
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
if *noColor || (!isatty.IsTerminal(os.Stdout.Fd()) && !*forceColor) {
|
||||
if hasColor == BoolAuto_NO || (!isatty.IsTerminal(os.Stdout.Fd()) && hasColor != BoolAuto_YES) {
|
||||
ansi.DisableColors(true)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue