mirror-to-gitea/vendor/github.com/onsi/ginkgo/reporters/stenographer/console_logging.go
vendor/github.com/onsi/ginkgo/reporters/stenographer/console_logging.goRaw
1package stenographer
2
3import (
4 "fmt"
5 "strings"
6)
7
8func (s *consoleStenographer) colorize(colorCode string, format string, args ...interface{}) string {
9 var out string
10
11 if len(args) > 0 {
12 out = fmt.Sprintf(format, args...)
13 } else {
14 out = format
15 }
16
17 if s.color {
18 return fmt.Sprintf("%s%s%s", colorCode, out, defaultStyle)
19 } else {
20 return out
21 }
22}
23
24func (s *consoleStenographer) printBanner(text string, bannerCharacter string) {
25 fmt.Fprintln(s.w, text)
26 fmt.Fprintln(s.w, strings.Repeat(bannerCharacter, len(text)))
27}
28
29func (s *consoleStenographer) printNewLine() {
30 fmt.Fprintln(s.w, "")
31}
32
33func (s *consoleStenographer) printDelimiter() {
34 fmt.Fprintln(s.w, s.colorize(grayColor, "%s", strings.Repeat("-", 30)))
35}
36
37func (s *consoleStenographer) print(indentation int, format string, args ...interface{}) {
38 fmt.Fprint(s.w, s.indent(indentation, format, args...))
39}
40
41func (s *consoleStenographer) println(indentation int, format string, args ...interface{}) {
42 fmt.Fprintln(s.w, s.indent(indentation, format, args...))
43}
44
45func (s *consoleStenographer) indent(indentation int, format string, args ...interface{}) string {
46 var text string
47
48 if len(args) > 0 {
49 text = fmt.Sprintf(format, args...)
50 } else {
51 text = format
52 }
53
54 stringArray := strings.Split(text, "\n")
55 padding := ""
56 if indentation >= 0 {
57 padding = strings.Repeat(" ", indentation)
58 }
59 for i, s := range stringArray {
60 stringArray[i] = fmt.Sprintf("%s%s", padding, s)
61 }
62
63 return strings.Join(stringArray, "\n")
64}