colorable_others.go 805 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. // +build !windows
  2. // +build !appengine
  3. package colorable
  4. import (
  5. "io"
  6. "os"
  7. _ "github.com/mattn/go-isatty"
  8. )
  9. // NewColorable returns new instance of Writer which handles escape sequence.
  10. func NewColorable(file *os.File) io.Writer {
  11. if file == nil {
  12. panic("nil passed instead of *os.File to NewColorable()")
  13. }
  14. return file
  15. }
  16. // NewColorableStdout returns new instance of Writer which handles escape sequence for stdout.
  17. func NewColorableStdout() io.Writer {
  18. return os.Stdout
  19. }
  20. // NewColorableStderr returns new instance of Writer which handles escape sequence for stderr.
  21. func NewColorableStderr() io.Writer {
  22. return os.Stderr
  23. }
  24. // EnableColorsStdout enable colors if possible.
  25. func EnableColorsStdout(enabled *bool) func() {
  26. if enabled != nil {
  27. *enabled = true
  28. }
  29. return func() {}
  30. }