github.com/xiaq/elvish@v0.12.0/util/pprinter.go (about) 1 package util 2 3 import ( 4 "fmt" 5 "os" 6 ) 7 8 // Pprinter wraps the Pprint function. 9 type Pprinter interface { 10 // Pprint takes an indentation string and pretty-prints. 11 Pprint(indent string) string 12 } 13 14 // PprintError pretty-prints an error if it implements Pprinter, and prints it 15 // in bold and red otherwise. 16 func PprintError(err error) { 17 if pprinter, ok := err.(Pprinter); ok { 18 fmt.Fprintln(os.Stderr, pprinter.Pprint("")) 19 } else { 20 fmt.Fprintf(os.Stderr, "\033[31;1m%s\033[m", err.Error()) 21 } 22 }