| 1 |
package format |
| 2 |
|
| 3 |
import "github.com/nicholas-fedor/shoutrrr/pkg/color" |
| 4 |
|
| 5 |
// ColorizeDesc colorizes the input string as "Description". |
| 6 |
var ColorizeDesc = color.New(color.FgHiBlack).SprintFunc() |
| 7 |
|
| 8 |
// ColorizeTrue colorizes the input string as "True". |
| 9 |
var ColorizeTrue = color.New(color.FgHiGreen).SprintFunc() |
| 10 |
|
| 11 |
// ColorizeFalse colorizes the input string as "False". |
| 12 |
var ColorizeFalse = color.New(color.FgHiRed).SprintFunc() |
| 13 |
|
| 14 |
// ColorizeNumber colorizes the input string as "Number". |
| 15 |
var ColorizeNumber = color.New(color.FgHiBlue).SprintFunc() |
| 16 |
|
| 17 |
// ColorizeString colorizes the input string as "String". |
| 18 |
var ColorizeString = color.New(color.FgHiYellow).SprintFunc() |
| 19 |
|
| 20 |
// ColorizeEnum colorizes the input string as "Enum". |
| 21 |
var ColorizeEnum = color.New(color.FgHiCyan).SprintFunc() |
| 22 |
|
| 23 |
// ColorizeProp colorizes the input string as "Prop". |
| 24 |
var ColorizeProp = color.New(color.FgHiMagenta).SprintFunc() |
| 25 |
|
| 26 |
// ColorizeError colorizes the input string as "Error". |
| 27 |
var ColorizeError = ColorizeFalse |
| 28 |
|
| 29 |
// ColorizeContainer colorizes the input string as "Container". |
| 30 |
var ColorizeContainer = ColorizeDesc |
| 31 |
|
| 32 |
// ColorizeLink colorizes the input string as "Link". |
| 33 |
var ColorizeLink = color.New(color.FgHiBlue).SprintFunc() |
| 34 |
|
| 35 |
// ColorizeValue colorizes the input string according to what type appears to be. |
| 36 |
func ColorizeValue(value string, isEnum bool) string { |
| 37 |
if isEnum { |
| 38 |
return ColorizeEnum(value) |
| 39 |
} |
| 40 |
|
| 41 |
if isTrue, isType := ParseBool(value, false); isType { |
| 42 |
if isTrue { |
| 43 |
return ColorizeTrue(value) |
| 44 |
} |
| 45 |
|
| 46 |
return ColorizeFalse(value) |
| 47 |
} |
| 48 |
|
| 49 |
if IsNumber(value) { |
| 50 |
return ColorizeNumber(value) |
| 51 |
} |
| 52 |
|
| 53 |
return ColorizeString(value) |
| 54 |
} |
| 55 |
|
| 56 |
// ColorizeToken colorizes the value according to the tokenType. |
| 57 |
func ColorizeToken(value string, tokenType NodeTokenType) string { |
| 58 |
switch tokenType { |
| 59 |
case NumberToken: |
| 60 |
return ColorizeNumber(value) |
| 61 |
case EnumToken: |
| 62 |
return ColorizeEnum(value) |
| 63 |
case TrueToken: |
| 64 |
return ColorizeTrue(value) |
| 65 |
case FalseToken: |
| 66 |
return ColorizeFalse(value) |
| 67 |
case PropToken: |
| 68 |
return ColorizeProp(value) |
| 69 |
case ErrorToken: |
| 70 |
return ColorizeError(value) |
| 71 |
case ContainerToken: |
| 72 |
return ColorizeContainer(value) |
| 73 |
case StringToken: |
| 74 |
return ColorizeString(value) |
| 75 |
case UnknownToken: |
| 76 |
default: |
| 77 |
} |
| 78 |
|
| 79 |
return value |
| 80 |
} |