github.com/andrewsun2898/u-root@v6.0.1-0.20200616011413-4b2895c1b815+incompatible/cmds/core/elvish/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 }