PageRenderTime 64ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/Godeps/_workspace/src/github.com/onsi/ginkgo/reporters/stenographer/console_logging.go

https://github.com/ironcladlou/kubernetes
Go | 64 lines | 51 code | 13 blank | 0 comment | 8 complexity | bedd572b2d28a2d9326cc7e13f0ad36f MD5 | raw file
Possible License(s): BSD-3-Clause, MIT, LGPL-3.0, Apache-2.0, JSON, BSD-2-Clause
  1. package stenographer
  2. import (
  3. "fmt"
  4. "strings"
  5. )
  6. func (s *consoleStenographer) colorize(colorCode string, format string, args ...interface{}) string {
  7. var out string
  8. if len(args) > 0 {
  9. out = fmt.Sprintf(format, args...)
  10. } else {
  11. out = format
  12. }
  13. if s.color {
  14. return fmt.Sprintf("%s%s%s", colorCode, out, defaultStyle)
  15. } else {
  16. return out
  17. }
  18. }
  19. func (s *consoleStenographer) printBanner(text string, bannerCharacter string) {
  20. fmt.Println(text)
  21. fmt.Println(strings.Repeat(bannerCharacter, len(text)))
  22. }
  23. func (s *consoleStenographer) printNewLine() {
  24. fmt.Println("")
  25. }
  26. func (s *consoleStenographer) printDelimiter() {
  27. fmt.Println(s.colorize(grayColor, "%s", strings.Repeat("-", 30)))
  28. }
  29. func (s *consoleStenographer) print(indentation int, format string, args ...interface{}) {
  30. fmt.Print(s.indent(indentation, format, args...))
  31. }
  32. func (s *consoleStenographer) println(indentation int, format string, args ...interface{}) {
  33. fmt.Println(s.indent(indentation, format, args...))
  34. }
  35. func (s *consoleStenographer) indent(indentation int, format string, args ...interface{}) string {
  36. var text string
  37. if len(args) > 0 {
  38. text = fmt.Sprintf(format, args...)
  39. } else {
  40. text = format
  41. }
  42. stringArray := strings.Split(text, "\n")
  43. padding := ""
  44. if indentation >= 0 {
  45. padding = strings.Repeat(" ", indentation)
  46. }
  47. for i, s := range stringArray {
  48. stringArray[i] = fmt.Sprintf("%s%s", padding, s)
  49. }
  50. return strings.Join(stringArray, "\n")
  51. }