| 1 | // This source inspired by https://github.com/fatih/color. |
| 2 | package printerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ |
| 3 | |
| 4 | import ( |
| 5 | "fmtscip-go gomod github.com/golang/go/src go1.21.0 fmt/" |
| 6 | "stringsscip-go gomod github.com/golang/go/src go1.21.0 strings/" |
| 7 | ) |
| 8 | |
| 9 | type ColorAttributescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorAttribute# int |
| 10 | |
| 11 | const ( |
| 12 | ColorResetscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorReset. ColorAttributescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorAttribute# = iota |
| 13 | ColorBoldscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorBold. |
| 14 | ColorFaintscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorFaint. |
| 15 | ColorItalicscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorItalic. |
| 16 | ColorUnderlinescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorUnderline. |
| 17 | ColorBlinkSlowscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorBlinkSlow. |
| 18 | ColorBlinkRapidscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorBlinkRapid. |
| 19 | ColorReverseVideoscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorReverseVideo. |
| 20 | ColorConcealedscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorConcealed. |
| 21 | ColorCrossedOutscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorCrossedOut. |
| 22 | ) |
| 23 | |
| 24 | const ( |
| 25 | ColorFgHiBlackscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorFgHiBlack. ColorAttributescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorAttribute# = iota + 90 |
| 26 | ColorFgHiRedscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorFgHiRed. |
| 27 | ColorFgHiGreenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorFgHiGreen. |
| 28 | ColorFgHiYellowscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorFgHiYellow. |
| 29 | ColorFgHiBluescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorFgHiBlue. |
| 30 | ColorFgHiMagentascip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorFgHiMagenta. |
| 31 | ColorFgHiCyanscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorFgHiCyan. |
| 32 | ColorFgHiWhitescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorFgHiWhite. |
| 33 | ) |
| 34 | |
| 35 | const ( |
| 36 | ColorResetBoldscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorResetBold. ColorAttributescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorAttribute# = iota + 22 |
| 37 | ColorResetItalicscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorResetItalic. |
| 38 | ColorResetUnderlinescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorResetUnderline. |
| 39 | ColorResetBlinkingscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorResetBlinking. |
| 40 | |
| 41 | ColorResetReversedscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorResetReversed. |
| 42 | ColorResetConcealedscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorResetConcealed. |
| 43 | ColorResetCrossedOutscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorResetCrossedOut. |
| 44 | ) |
| 45 | |
| 46 | const escapescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/escape. = "\x1b" |
| 47 | |
| 48 | var colorResetMapscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/colorResetMap. = map[ColorAttributescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorAttribute#]ColorAttributescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorAttribute#{ |
| 49 | ColorBoldscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorBold.: ColorResetBoldscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorResetBold., |
| 50 | ColorFaintscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorFaint.: ColorResetBoldscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorResetBold., |
| 51 | ColorItalicscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorItalic.: ColorResetItalicscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorResetItalic., |
| 52 | ColorUnderlinescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorUnderline.: ColorResetUnderlinescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorResetUnderline., |
| 53 | ColorBlinkSlowscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorBlinkSlow.: ColorResetBlinkingscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorResetBlinking., |
| 54 | ColorBlinkRapidscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorBlinkRapid.: ColorResetBlinkingscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorResetBlinking., |
| 55 | ColorReverseVideoscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorReverseVideo.: ColorResetReversedscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorResetReversed., |
| 56 | ColorConcealedscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorConcealed.: ColorResetConcealedscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorResetConcealed., |
| 57 | ColorCrossedOutscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorCrossedOut.: ColorResetCrossedOutscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorResetCrossedOut., |
| 58 | } |
| 59 | |
| 60 | func formatscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/format().(attrs ...ColorAttributescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorAttribute#) string { |
| 61 | format := make([]string, 0, len(attrs)) |
| 62 | for _, attr := range attrs { |
| 63 | format = append(format, fmtscip-go gomod github.com/golang/go/src go1.21.0 fmt/.Sprintscip-go gomod github.com/golang/go/src go1.21.0 fmt/Sprint().(attr)) |
| 64 | } |
| 65 | return fmtscip-go gomod github.com/golang/go/src go1.21.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.21.0 fmt/Sprintf().("%s[%sm", escapescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/escape., stringsscip-go gomod github.com/golang/go/src go1.21.0 strings/.Joinscip-go gomod github.com/golang/go/src go1.21.0 strings/Join().(format, ";")) |
| 66 | } |
| 67 | |
| 68 | func unformatscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/unformat().(attrs ...ColorAttributescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorAttribute#) string { |
| 69 | format := make([]string, len(attrs)) |
| 70 | for _, attr := range attrs { |
| 71 | v := fmtscip-go gomod github.com/golang/go/src go1.21.0 fmt/.Sprintscip-go gomod github.com/golang/go/src go1.21.0 fmt/Sprint().(ColorResetscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorReset.) |
| 72 | reset, exists := colorResetMapscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/colorResetMap.[attr] |
| 73 | if exists { |
| 74 | v = fmtscip-go gomod github.com/golang/go/src go1.21.0 fmt/.Sprintscip-go gomod github.com/golang/go/src go1.21.0 fmt/Sprint().(reset) |
| 75 | } |
| 76 | format = append(format, v) |
| 77 | } |
| 78 | return fmtscip-go gomod github.com/golang/go/src go1.21.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.21.0 fmt/Sprintf().("%s[%sm", escapescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/escape., stringsscip-go gomod github.com/golang/go/src go1.21.0 strings/.Joinscip-go gomod github.com/golang/go/src go1.21.0 strings/Join().(format, ";")) |
| 79 | } |
| 80 | |
| 81 | func colorizescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/colorize().(msg string, attrs ...ColorAttributescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorAttribute#) string { |
| 82 | return formatscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/format().(attrs...) + msg + unformatscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/unformat().(attrs...) |
| 83 | } |