| 1 | package colorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/ |
| 2 | |
| 3 | import ( |
| 4 | "fmtscip-go gomod github.com/golang/go/src . fmt/" |
| 5 | "ioscip-go gomod github.com/golang/go/src . io/" |
| 6 | "osscip-go gomod github.com/golang/go/src . os/" |
| 7 | "slicesscip-go gomod github.com/golang/go/src . slices/" |
| 8 | "strconvscip-go gomod github.com/golang/go/src . strconv/" |
| 9 | "stringsscip-go gomod github.com/golang/go/src . strings/" |
| 10 | |
| 11 | "github.com/mattn/go-colorablescip-go gomod github.com/mattn/go-colorable v0.1.15 `github.com/mattn/go-colorable`/" |
| 12 | "golang.org/x/termscip-go gomod golang.org/x/term v0.45.0 `golang.org/x/term`/" |
| 13 | ) |
| 14 | |
| 15 | // Config holds configuration settings for color output. |
| 16 | type Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Config# struct { |
| 17 | // NoColor controls whether color output is disabled. |
| 18 | // When true, all color formatting is stripped from output. |
| 19 | NoColorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Config#NoColor. bool |
| 20 | |
| 21 | // Output is the default io.Writer used by print functions for colorized output. |
| 22 | Outputscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Config#Output. ioscip-go gomod github.com/golang/go/src . io/.Writerscip-go gomod github.com/golang/go/src . io/Writer# |
| 23 | |
| 24 | // Error is the default io.Writer used for error output with color support. |
| 25 | Errorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Config#Error. ioscip-go gomod github.com/golang/go/src . io/.Writerscip-go gomod github.com/golang/go/src . io/Writer# |
| 26 | } |
| 27 | |
| 28 | // Color represents a color with ANSI SGR parameters. |
| 29 | type Colorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color# struct { |
| 30 | paramsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#params. []Attributescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Attribute# |
| 31 | noColorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#noColor. *bool // Instance-level override |
| 32 | configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#config. *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Config# // Reference to config (can be shared) |
| 33 | } |
| 34 | |
| 35 | // stdoutFd is the file descriptor for stdout, safely converted. |
| 36 | var stdoutFdscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/stdoutFd. = int(osscip-go gomod github.com/golang/go/src . os/.Stdoutscip-go gomod github.com/golang/go/src . os/Stdout..Fdscip-go gomod github.com/golang/go/src . os/File#Fd().()) |
| 37 | |
| 38 | // mapResetAttributes maps color attributes to their corresponding reset |
| 39 | // attributes for proper cleanup of terminal formatting. |
| 40 | var mapResetAttributesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/mapResetAttributes. = map[Attributescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Attribute#]Attributescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Attribute#{ |
| 41 | Boldscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Bold.: ResetBoldscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/ResetBold., |
| 42 | Faintscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Faint.: ResetBoldscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/ResetBold., |
| 43 | Italicscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Italic.: ResetItalicscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/ResetItalic., |
| 44 | Underlinescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Underline.: ResetUnderlinescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/ResetUnderline., |
| 45 | BlinkSlowscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/BlinkSlow.: ResetBlinkingscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/ResetBlinking., |
| 46 | BlinkRapidscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/BlinkRapid.: ResetBlinkingscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/ResetBlinking., |
| 47 | ReverseVideoscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/ReverseVideo.: ResetReversedscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/ResetReversed., |
| 48 | Concealedscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Concealed.: ResetConcealedscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/ResetConcealed., |
| 49 | CrossedOutscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/CrossedOut.: ResetCrossedOutscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/ResetCrossedOut., |
| 50 | } |
| 51 | |
| 52 | // noColorFromEnv returns whether colors should be disabled based on environment. |
| 53 | func noColorFromEnvscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/noColorFromEnv().() bool { |
| 54 | return osscip-go gomod github.com/golang/go/src . os/.Getenvscip-go gomod github.com/golang/go/src . os/Getenv().("NO_COLOR") != "" || |
| 55 | osscip-go gomod github.com/golang/go/src . os/.Getenvscip-go gomod github.com/golang/go/src . os/Getenv().("TERM") == "dumb" || |
| 56 | !termscip-go gomod golang.org/x/term v0.45.0 `golang.org/x/term`/.IsTerminalscip-go gomod golang.org/x/term v0.45.0 `golang.org/x/term`/IsTerminal().(stdoutFdscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/stdoutFd.) |
| 57 | } |
| 58 | |
| 59 | // DefaultConfig returns a Config with sensible defaults. |
| 60 | // The NoColor setting is detected from the environment: |
| 61 | // - If NO_COLOR environment variable is set, colors are disabled |
| 62 | // - If TERM environment variable is "dumb", colors are disabled |
| 63 | // - If stdout is not a terminal, colors are disabled |
| 64 | // |
| 65 | // Output and Error are set to colorable writers that support ANSI escape codes |
| 66 | // on Windows. |
| 67 | func DefaultConfigscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/DefaultConfig().() *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Config# { |
| 68 | return &Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Config#{ |
| 69 | NoColorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Config#NoColor.: noColorFromEnvscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/noColorFromEnv().(), |
| 70 | Outputscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Config#Output.: colorablescip-go gomod github.com/mattn/go-colorable v0.1.15 `github.com/mattn/go-colorable`/.NewColorableStdoutscip-go gomod github.com/mattn/go-colorable v0.1.15 `github.com/mattn/go-colorable`/NewColorableStdout().(), |
| 71 | Errorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Config#Error.: colorablescip-go gomod github.com/mattn/go-colorable v0.1.15 `github.com/mattn/go-colorable`/.NewColorableStderrscip-go gomod github.com/mattn/go-colorable v0.1.15 `github.com/mattn/go-colorable`/NewColorableStderr().(), |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | // New returns a newly created color object using the default configuration. |
| 76 | func Newscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/New().(value ...Attributescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Attribute#) *Colorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color# { |
| 77 | return NewWithConfigscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/NewWithConfig().(DefaultConfigscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/DefaultConfig().(), value...) |
| 78 | } |
| 79 | |
| 80 | // NewWithConfig returns a newly created color object with the specified configuration. |
| 81 | // |
| 82 | // Example: |
| 83 | // |
| 84 | // cfg := &color.Config{ |
| 85 | // NoColor: true, |
| 86 | // Output: os.Stdout, |
| 87 | // Error: os.Stderr, |
| 88 | // } |
| 89 | // c := color.NewWithConfig(cfg, color.FgRed) |
| 90 | // c.Println("This is red text") |
| 91 | func NewWithConfigscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/NewWithConfig().(cfg *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Config#, value ...Attributescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Attribute#) *Colorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color# { |
| 92 | c := &Colorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#{ |
| 93 | paramsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#params.: make([]Attributescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Attribute#, 0, len(value)), |
| 94 | noColorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#noColor.: nil, // Will use config.NoColor by default |
| 95 | configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#config.: cfg, |
| 96 | } |
| 97 | |
| 98 | if cfg.NoColorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Config#NoColor. { |
| 99 | c.noColorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#noColor. = boolPtrscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/boolPtr().(true) |
| 100 | } |
| 101 | |
| 102 | c.Addscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#Add().(value...) |
| 103 | |
| 104 | return c |
| 105 | } |
| 106 | |
| 107 | // Add is used to chain SGR parameters. |
| 108 | // Use as many as parameters to combine and create custom color objects. |
| 109 | // Example: Add(color.FgRed, color.Underline). |
| 110 | func (c *Colorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#) Addscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#Add().(value ...Attributescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Attribute#) *Colorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color# { |
| 111 | c.paramsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#params. = append(c.paramsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#params., value...) |
| 112 | |
| 113 | return c |
| 114 | } |
| 115 | |
| 116 | // AddBgRGB is used to chain background RGB SGR parameters. |
| 117 | // Use as many as parameters to combine and create custom color objects. |
| 118 | // Example: .Add(34, 0, 12).Add(255, 128, 0). |
| 119 | func (c *Colorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#) AddBgRGBscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#AddBgRGB().(r, green, blue int) *Colorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color# { |
| 120 | c.paramsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#params. = append( |
| 121 | c.paramsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#params., |
| 122 | backgroundscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/background., |
| 123 | rgbColorFormatSpecifierscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/rgbColorFormatSpecifier., |
| 124 | Attributescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Attribute#(r), |
| 125 | Attributescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Attribute#(green), |
| 126 | Attributescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Attribute#(blue), |
| 127 | ) |
| 128 | |
| 129 | return c |
| 130 | } |
| 131 | |
| 132 | // AddRGB is used to chain foreground RGB SGR parameters. |
| 133 | // Use as many as parameters to combine and create custom color objects. |
| 134 | // Example: .Add(34, 0, 12).Add(255, 128, 0). |
| 135 | func (c *Colorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#) AddRGBscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#AddRGB().(r, green, blue int) *Colorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color# { |
| 136 | c.paramsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#params. = append( |
| 137 | c.paramsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#params., |
| 138 | foregroundscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/foreground., |
| 139 | rgbColorFormatSpecifierscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/rgbColorFormatSpecifier., |
| 140 | Attributescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Attribute#(r), |
| 141 | Attributescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Attribute#(green), |
| 142 | Attributescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Attribute#(blue), |
| 143 | ) |
| 144 | |
| 145 | return c |
| 146 | } |
| 147 | |
| 148 | // DisableColor disables the color output. |
| 149 | // Useful to not change any existing code and still being able to output. |
| 150 | // Can be used for flags like "--no-color". |
| 151 | // To enable back use EnableColor() method. |
| 152 | func (c *Colorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#) DisableColorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#DisableColor().() { |
| 153 | c.noColorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#noColor. = boolPtrscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/boolPtr().(true) |
| 154 | } |
| 155 | |
| 156 | // EnableColor enables the color output. |
| 157 | // Use it in conjunction with DisableColor(). |
| 158 | // Otherwise, this method has no side effects. |
| 159 | func (c *Colorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#) EnableColorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#EnableColor().() { |
| 160 | c.noColorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#noColor. = boolPtrscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/boolPtr().(false) |
| 161 | } |
| 162 | |
| 163 | // Equals returns a boolean value indicating whether two colors are equal. |
| 164 | func (c *Colorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#) Equalsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#Equals().(colorToCompare *Colorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#) bool { |
| 165 | if c == nil && colorToCompare == nil { |
| 166 | return true |
| 167 | } |
| 168 | |
| 169 | if c == nil || colorToCompare == nil { |
| 170 | return false |
| 171 | } |
| 172 | |
| 173 | if len(c.paramsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#params.) != len(colorToCompare.paramsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#params.) { |
| 174 | return false |
| 175 | } |
| 176 | |
| 177 | for _, attr := range c.paramsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#params. { |
| 178 | if !colorToCompare.attrExistsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#attrExists().(attr) { |
| 179 | return false |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | return true |
| 184 | } |
| 185 | |
| 186 | // Fprint formats using the default formats for its operands and writes to w. |
| 187 | // Spaces are added between operands when neither is a string. |
| 188 | // It returns the number of bytes written and any write error encountered. |
| 189 | // On Windows, users should wrap w with colorable.NewColorable() if w is of |
| 190 | // type *os.File. |
| 191 | // |
| 192 | //nolint:wrapcheck // fmt.Fprintln errors are passed through as-is for API compatibility |
| 193 | func (c *Colorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#) Fprintscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#Fprint().(writer ioscip-go gomod github.com/golang/go/src . io/.Writerscip-go gomod github.com/golang/go/src . io/Writer#, args ...any) (int, error) { |
| 194 | if c.isNoColorSetscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#isNoColorSet().() { |
| 195 | return fmtscip-go gomod github.com/golang/go/src . fmt/.Fprintscip-go gomod github.com/golang/go/src . fmt/Fprint().(writer, args...) |
| 196 | } |
| 197 | |
| 198 | c.SetWriterscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#SetWriter().(writer) |
| 199 | defer c.UnsetWriterscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#UnsetWriter().(writer) |
| 200 | |
| 201 | return fmtscip-go gomod github.com/golang/go/src . fmt/.Fprintscip-go gomod github.com/golang/go/src . fmt/Fprint().(writer, args...) |
| 202 | } |
| 203 | |
| 204 | // FprintFunc returns a new function that prints the passed arguments as |
| 205 | // colorized with color.Fprint(). |
| 206 | func (c *Colorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#) FprintFuncscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#FprintFunc().() func(w ioscip-go gomod github.com/golang/go/src . io/.Writerscip-go gomod github.com/golang/go/src . io/Writer#, a ...any) { |
| 207 | return func(w ioscip-go gomod github.com/golang/go/src . io/.Writerscip-go gomod github.com/golang/go/src . io/Writer#, a ...any) { |
| 208 | _, _ = c.Fprintscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#Fprint().(w, a...) |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | // Fprintf formats according to a format specifier and writes to w. |
| 213 | // It returns the number of bytes written and any write error encountered. |
| 214 | // On Windows, users should wrap w with colorable.NewColorable() if w is of |
| 215 | // type *os.File. |
| 216 | // |
| 217 | //nolint:wrapcheck // fmt.Fprintln errors are passed through as-is for API compatibility |
| 218 | func (c *Colorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#) Fprintfscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#Fprintf().(writer ioscip-go gomod github.com/golang/go/src . io/.Writerscip-go gomod github.com/golang/go/src . io/Writer#, format string, args ...any) (int, error) { |
| 219 | if c.isNoColorSetscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#isNoColorSet().() { |
| 220 | return fmtscip-go gomod github.com/golang/go/src . fmt/.Fprintfscip-go gomod github.com/golang/go/src . fmt/Fprintf().(writer, format, args...) |
| 221 | } |
| 222 | |
| 223 | c.SetWriterscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#SetWriter().(writer) |
| 224 | defer c.UnsetWriterscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#UnsetWriter().(writer) |
| 225 | |
| 226 | return fmtscip-go gomod github.com/golang/go/src . fmt/.Fprintfscip-go gomod github.com/golang/go/src . fmt/Fprintf().(writer, format, args...) |
| 227 | } |
| 228 | |
| 229 | // FprintfFunc returns a new function that prints the passed arguments as |
| 230 | // colorized with color.Fprintf(). |
| 231 | func (c *Colorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#) FprintfFuncscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#FprintfFunc().() func(w ioscip-go gomod github.com/golang/go/src . io/.Writerscip-go gomod github.com/golang/go/src . io/Writer#, format string, a ...any) { |
| 232 | return func(w ioscip-go gomod github.com/golang/go/src . io/.Writerscip-go gomod github.com/golang/go/src . io/Writer#, format string, a ...any) { |
| 233 | _, _ = c.Fprintfscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#Fprintf().(w, format, a...) |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | // Fprintln formats using the default formats for its operands and writes to w. |
| 238 | // Spaces are always added between operands and a newline is appended. |
| 239 | // On Windows, users should wrap w with colorable.NewColorable() if w is of |
| 240 | // type *os.File. |
| 241 | // |
| 242 | //nolint:wrapcheck // fmt.Fprintln errors are passed through as-is for API compatibility |
| 243 | func (c *Colorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#) Fprintlnscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#Fprintln().(writer ioscip-go gomod github.com/golang/go/src . io/.Writerscip-go gomod github.com/golang/go/src . io/Writer#, args ...any) (int, error) { |
| 244 | if c.isNoColorSetscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#isNoColorSet().() { |
| 245 | return fmtscip-go gomod github.com/golang/go/src . fmt/.Fprintlnscip-go gomod github.com/golang/go/src . fmt/Fprintln().(writer, args...) |
| 246 | } |
| 247 | |
| 248 | return fmtscip-go gomod github.com/golang/go/src . fmt/.Fprintlnscip-go gomod github.com/golang/go/src . fmt/Fprintln().(writer, c.formatscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#format().()+sprintlnscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/sprintln().(args...)+c.unformatscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#unformat().()) |
| 249 | } |
| 250 | |
| 251 | // FprintlnFunc returns a new function that prints the passed arguments as |
| 252 | // colorized with color.Fprintln(). |
| 253 | func (c *Colorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#) FprintlnFuncscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#FprintlnFunc().() func(w ioscip-go gomod github.com/golang/go/src . io/.Writerscip-go gomod github.com/golang/go/src . io/Writer#, a ...any) { |
| 254 | return func(w ioscip-go gomod github.com/golang/go/src . io/.Writerscip-go gomod github.com/golang/go/src . io/Writer#, a ...any) { |
| 255 | _, _ = c.Fprintlnscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#Fprintln().(w, a...) |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | // Print formats using the default formats for its operands and writes to |
| 260 | // standard output. Spaces are added between operands when neither is a |
| 261 | // string. It returns the number of bytes written and any write error |
| 262 | // encountered. This is the standard fmt.Print() method wrapped with the given |
| 263 | // color. |
| 264 | // |
| 265 | //nolint:wrapcheck // fmt.Fprintln errors are passed through as-is for API compatibility |
| 266 | func (c *Colorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#) Printscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#Print().(args ...any) (int, error) { |
| 267 | if c.isNoColorSetscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#isNoColorSet().() { |
| 268 | return fmtscip-go gomod github.com/golang/go/src . fmt/.Fprintscip-go gomod github.com/golang/go/src . fmt/Fprint().(c.configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#config..Outputscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Config#Output., args...) |
| 269 | } |
| 270 | |
| 271 | c.Setscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#Set().() |
| 272 | defer c.Unsetscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#Unset().() |
| 273 | |
| 274 | return fmtscip-go gomod github.com/golang/go/src . fmt/.Fprintscip-go gomod github.com/golang/go/src . fmt/Fprint().(c.configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#config..Outputscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Config#Output., args...) |
| 275 | } |
| 276 | |
| 277 | // PrintFunc returns a new function that prints the passed arguments as |
| 278 | // colorized with color.Print(). |
| 279 | func (c *Colorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#) PrintFuncscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#PrintFunc().() func(a ...any) { |
| 280 | return func(a ...any) { |
| 281 | _, _ = c.Printscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#Print().(a...) |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | // Printf formats according to a format specifier and writes to standard output. |
| 286 | // It returns the number of bytes written and any write error encountered. |
| 287 | // This is the standard fmt.Printf() method wrapped with the given color. |
| 288 | // |
| 289 | //nolint:wrapcheck // fmt.Fprintln errors are passed through as-is for API compatibility |
| 290 | func (c *Colorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#) Printfscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#Printf().(format string, args ...any) (int, error) { |
| 291 | if c.isNoColorSetscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#isNoColorSet().() { |
| 292 | return fmtscip-go gomod github.com/golang/go/src . fmt/.Fprintfscip-go gomod github.com/golang/go/src . fmt/Fprintf().(c.configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#config..Outputscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Config#Output., format, args...) |
| 293 | } |
| 294 | |
| 295 | c.Setscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#Set().() |
| 296 | defer c.Unsetscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#Unset().() |
| 297 | |
| 298 | return fmtscip-go gomod github.com/golang/go/src . fmt/.Fprintfscip-go gomod github.com/golang/go/src . fmt/Fprintf().(c.configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#config..Outputscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Config#Output., format, args...) |
| 299 | } |
| 300 | |
| 301 | // PrintfFunc returns a new function that prints the passed arguments as |
| 302 | // colorized with color.Printf(). |
| 303 | func (c *Colorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#) PrintfFuncscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#PrintfFunc().() func(format string, a ...any) { |
| 304 | return func(format string, a ...any) { |
| 305 | _, _ = c.Printfscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#Printf().(format, a...) |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | // Println formats using the default formats for its operands and writes to |
| 310 | // standard output. Spaces are always added between operands and a newline is |
| 311 | // appended. It returns the number of bytes written and any write error |
| 312 | // encountered. This is the standard fmt.Print() method wrapped with the given |
| 313 | // color. |
| 314 | // |
| 315 | //nolint:wrapcheck // fmt.Fprintln errors are passed through as-is for API compatibility |
| 316 | func (c *Colorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#) Printlnscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#Println().(args ...any) (int, error) { |
| 317 | if c.isNoColorSetscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#isNoColorSet().() { |
| 318 | return fmtscip-go gomod github.com/golang/go/src . fmt/.Fprintlnscip-go gomod github.com/golang/go/src . fmt/Fprintln().(c.configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#config..Outputscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Config#Output., args...) |
| 319 | } |
| 320 | |
| 321 | return fmtscip-go gomod github.com/golang/go/src . fmt/.Fprintlnscip-go gomod github.com/golang/go/src . fmt/Fprintln().(c.configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#config..Outputscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Config#Output., c.formatscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#format().()+sprintlnscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/sprintln().(args...)+c.unformatscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#unformat().()) |
| 322 | } |
| 323 | |
| 324 | // PrintlnFunc returns a new function that prints the passed arguments as |
| 325 | // colorized with color.Println(). |
| 326 | func (c *Colorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#) PrintlnFuncscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#PrintlnFunc().() func(a ...any) { |
| 327 | return func(a ...any) { |
| 328 | _, _ = c.Printlnscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#Println().(a...) |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | // Set sets the SGR sequence. |
| 333 | func (c *Colorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#) Setscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#Set().() *Colorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color# { |
| 334 | if c.isNoColorSetscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#isNoColorSet().() || c.configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#config..NoColorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Config#NoColor. { |
| 335 | return c |
| 336 | } |
| 337 | |
| 338 | _, _ = fmtscip-go gomod github.com/golang/go/src . fmt/.Fprintscip-go gomod github.com/golang/go/src . fmt/Fprint().(c.configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#config..Outputscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Config#Output., c.formatscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#format().()) |
| 339 | |
| 340 | return c |
| 341 | } |
| 342 | |
| 343 | // SetWriter is used to set the SGR sequence with the given io.Writer. |
| 344 | // This is a low-level function, and users should use the higher-level |
| 345 | // functions, such as color.Fprint, color.Print, etc. |
| 346 | func (c *Colorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#) SetWriterscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#SetWriter().(w ioscip-go gomod github.com/golang/go/src . io/.Writerscip-go gomod github.com/golang/go/src . io/Writer#) *Colorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color# { |
| 347 | if c.isNoColorSetscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#isNoColorSet().() || c.configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#config..NoColorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Config#NoColor. { |
| 348 | return c |
| 349 | } |
| 350 | |
| 351 | _, _ = fmtscip-go gomod github.com/golang/go/src . fmt/.Fprintscip-go gomod github.com/golang/go/src . fmt/Fprint().(w, c.formatscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#format().()) |
| 352 | |
| 353 | return c |
| 354 | } |
| 355 | |
| 356 | // Sprint is just like Print, but returns a string instead of printing it. |
| 357 | func (c *Colorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#) Sprintscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#Sprint().(a ...any) string { |
| 358 | return c.wrapscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#wrap().(fmtscip-go gomod github.com/golang/go/src . fmt/.Sprintscip-go gomod github.com/golang/go/src . fmt/Sprint().(a...)) |
| 359 | } |
| 360 | |
| 361 | // SprintFunc returns a new function that returns colorized strings for the |
| 362 | // given arguments with fmt.Sprint(). |
| 363 | // Useful to put into or mix into other string. |
| 364 | // Windows users should use this in conjunction with color.Output |
| 365 | // Example: |
| 366 | // |
| 367 | // put := New(FgYellow).SprintFunc() |
| 368 | // fmt.Fprintf(color.Output, "This is a %s", put("warning")) |
| 369 | func (c *Colorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#) SprintFuncscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#SprintFunc().() func(a ...any) string { |
| 370 | return func(a ...any) string { |
| 371 | return c.wrapscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#wrap().(fmtscip-go gomod github.com/golang/go/src . fmt/.Sprintscip-go gomod github.com/golang/go/src . fmt/Sprint().(a...)) |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | // Sprintf is just like Printf, but returns a string instead of printing it. |
| 376 | func (c *Colorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#) Sprintfscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#Sprintf().(format string, a ...any) string { |
| 377 | return c.wrapscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#wrap().(fmtscip-go gomod github.com/golang/go/src . fmt/.Sprintfscip-go gomod github.com/golang/go/src . fmt/Sprintf().(format, a...)) |
| 378 | } |
| 379 | |
| 380 | // SprintfFunc returns a new function that returns colorized strings for the |
| 381 | // given arguments with fmt.Sprintf(). |
| 382 | // Useful to put into or mix into other string. |
| 383 | // Windows users should use this in conjunction with color.Output. |
| 384 | // |
| 385 | // Note: The returned function is memoized for performance. |
| 386 | func (c *Colorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#) SprintfFuncscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#SprintfFunc().() func(format string, args ...any) string { |
| 387 | if c.isNoColorSetscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#isNoColorSet().() { |
| 388 | return fmtscip-go gomod github.com/golang/go/src . fmt/.Sprintfscip-go gomod github.com/golang/go/src . fmt/Sprintf(). |
| 389 | } |
| 390 | |
| 391 | return func(format string, args ...any) string { |
| 392 | return c.wrapscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#wrap().(fmtscip-go gomod github.com/golang/go/src . fmt/.Sprintfscip-go gomod github.com/golang/go/src . fmt/Sprintf().(format, args...)) |
| 393 | } |
| 394 | } |
| 395 | |
| 396 | // Sprintln is just like Println, but returns a string instead of printing it. |
| 397 | func (c *Colorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#) Sprintlnscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#Sprintln().(a ...any) string { |
| 398 | return c.wrapscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#wrap().(sprintlnscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/sprintln().(a...)) + "\n" |
| 399 | } |
| 400 | |
| 401 | // SprintlnFunc returns a new function that returns colorized strings for the |
| 402 | // given arguments with fmt.Sprintln(). |
| 403 | // Useful to put into or mix into other string. |
| 404 | // Windows users should use this in conjunction with color.Output. |
| 405 | // |
| 406 | // Note: The returned function is memoized for performance. |
| 407 | func (c *Colorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#) SprintlnFuncscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#SprintlnFunc().() func(a ...any) string { |
| 408 | if c.isNoColorSetscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#isNoColorSet().() { |
| 409 | return func(a ...any) string { return sprintlnscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/sprintln().(a...) + "\n" } |
| 410 | } |
| 411 | |
| 412 | return func(a ...any) string { |
| 413 | return c.wrapscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#wrap().(sprintlnscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/sprintln().(a...)) + "\n" |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | // Unset resets the color output to default. |
| 418 | // It clears the escape attributes and restores normal terminal formatting. |
| 419 | // This should be called after Set() to clean up the terminal state. |
| 420 | func (c *Colorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#) Unsetscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#Unset().() { |
| 421 | if c.isNoColorSetscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#isNoColorSet().() || c.configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#config..NoColorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Config#NoColor. { |
| 422 | return |
| 423 | } |
| 424 | |
| 425 | c.configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#config..unsetscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Config#unset().() |
| 426 | } |
| 427 | |
| 428 | // UnsetWriter resets all escape attributes and clears the output with the give |
| 429 | // io.Writer. Usually should be called after SetWriter(). |
| 430 | func (c *Colorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#) UnsetWriterscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#UnsetWriter().(w ioscip-go gomod github.com/golang/go/src . io/.Writerscip-go gomod github.com/golang/go/src . io/Writer#) { |
| 431 | if c.isNoColorSetscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#isNoColorSet().() || c.configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#config..NoColorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Config#NoColor. { |
| 432 | return |
| 433 | } |
| 434 | |
| 435 | _, _ = fmtscip-go gomod github.com/golang/go/src . fmt/.Fprintfscip-go gomod github.com/golang/go/src . fmt/Fprintf().(w, "%s[%dm", escapescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/escape., Resetscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Reset.) |
| 436 | } |
| 437 | |
| 438 | func (c *Colorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#) attrExistsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#attrExists().(a Attributescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Attribute#) bool { |
| 439 | return slicesscip-go gomod github.com/golang/go/src . slices/.Containsscip-go gomod github.com/golang/go/src . slices/Contains().(c.paramsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#params., a) |
| 440 | } |
| 441 | |
| 442 | func (c *Colorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#) formatscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#format().() string { |
| 443 | return fmtscip-go gomod github.com/golang/go/src . fmt/.Sprintfscip-go gomod github.com/golang/go/src . fmt/Sprintf().("%s[%sm", escapescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/escape., c.sequencescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#sequence().()) |
| 444 | } |
| 445 | |
| 446 | func (c *Colorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#) isNoColorSetscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#isNoColorSet().() bool { |
| 447 | // check first if we have user set action |
| 448 | if c.noColorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#noColor. != nil { |
| 449 | return *c.noColorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#noColor. |
| 450 | } |
| 451 | |
| 452 | // if not return the config option |
| 453 | return c.configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#config..NoColorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Config#NoColor. |
| 454 | } |
| 455 | |
| 456 | // sequence returns a formatted SGR sequence to be plugged into a "\x1b[...m". |
| 457 | // An example output might be: "1;36" -> bold cyan. |
| 458 | func (c *Colorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#) sequencescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#sequence().() string { |
| 459 | if len(c.paramsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#params.) == 0 { |
| 460 | return "" |
| 461 | } |
| 462 | |
| 463 | var b stringsscip-go gomod github.com/golang/go/src . strings/.Builderscip-go gomod github.com/golang/go/src . strings/Builder# |
| 464 | b.Growscip-go gomod github.com/golang/go/src . strings/Builder#Grow().(len(c.paramsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#params.) * builderGrowthFactorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/builderGrowthFactor.) // Pre-allocate for typical cases |
| 465 | |
| 466 | for i, v := range c.paramsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#params. { |
| 467 | if i > 0 { |
| 468 | b.WriteBytescip-go gomod github.com/golang/go/src . strings/Builder#WriteByte().(';') |
| 469 | } |
| 470 | |
| 471 | b.WriteStringscip-go gomod github.com/golang/go/src . strings/Builder#WriteString().(strconvscip-go gomod github.com/golang/go/src . strconv/.Itoascip-go gomod github.com/golang/go/src . strconv/Itoa().(int(v))) |
| 472 | } |
| 473 | |
| 474 | return b.Stringscip-go gomod github.com/golang/go/src . strings/Builder#String().() |
| 475 | } |
| 476 | |
| 477 | // unformat returns the ANSI escape sequence to reset the color formatting. |
| 478 | // For each parameter in the color, it uses the specific reset attribute |
| 479 | // if available, or the generic Reset attribute otherwise. |
| 480 | func (c *Colorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#) unformatscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#unformat().() string { |
| 481 | if len(c.paramsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#params.) == 0 { |
| 482 | return "" |
| 483 | } |
| 484 | |
| 485 | var b stringsscip-go gomod github.com/golang/go/src . strings/.Builderscip-go gomod github.com/golang/go/src . strings/Builder# |
| 486 | b.Growscip-go gomod github.com/golang/go/src . strings/Builder#Grow().(len(c.paramsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#params.) * builderGrowthFactorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/builderGrowthFactor.) |
| 487 | b.WriteStringscip-go gomod github.com/golang/go/src . strings/Builder#WriteString().(escapescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/escape.) |
| 488 | b.WriteBytescip-go gomod github.com/golang/go/src . strings/Builder#WriteByte().('[') |
| 489 | |
| 490 | for i, attr := range c.paramsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#params. { |
| 491 | if i > 0 { |
| 492 | b.WriteBytescip-go gomod github.com/golang/go/src . strings/Builder#WriteByte().(';') |
| 493 | } |
| 494 | |
| 495 | // Default to generic reset |
| 496 | resetAttr := Resetscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Reset. |
| 497 | |
| 498 | // Use specific reset if available |
| 499 | if specificReset, ok := mapResetAttributesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/mapResetAttributes.[attr]; ok { |
| 500 | resetAttr = specificReset |
| 501 | } |
| 502 | |
| 503 | b.WriteStringscip-go gomod github.com/golang/go/src . strings/Builder#WriteString().(strconvscip-go gomod github.com/golang/go/src . strconv/.Itoascip-go gomod github.com/golang/go/src . strconv/Itoa().(int(resetAttr))) |
| 504 | } |
| 505 | |
| 506 | b.WriteBytescip-go gomod github.com/golang/go/src . strings/Builder#WriteByte().('m') |
| 507 | |
| 508 | return b.Stringscip-go gomod github.com/golang/go/src . strings/Builder#String().() |
| 509 | } |
| 510 | |
| 511 | // wrap wraps the s string with the colors attributes. |
| 512 | // The string is ready to be printed. |
| 513 | func (c *Colorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#) wrapscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#wrap().(s string) string { |
| 514 | if c.isNoColorSetscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#isNoColorSet().() || c.configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#config..NoColorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Config#NoColor. { |
| 515 | return s |
| 516 | } |
| 517 | |
| 518 | return c.formatscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#format().() + s + c.unformatscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color#unformat().() |
| 519 | } |
| 520 | |
| 521 | // unset resets all escape attributes and clears the output. |
| 522 | func (c *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Config#) unsetscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Config#unset().() { |
| 523 | if c.NoColorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Config#NoColor. { |
| 524 | return |
| 525 | } |
| 526 | |
| 527 | _, _ = fmtscip-go gomod github.com/golang/go/src . fmt/.Fprintfscip-go gomod github.com/golang/go/src . fmt/Fprintf().(c.Outputscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Config#Output., "%s[%dm", escapescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/escape., Resetscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Reset.) |
| 528 | } |
| 529 | |
| 530 | // BgRGB returns a new background color in 24-bit RGB. |
| 531 | func BgRGBscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/BgRGB().(r, g, b int) *Colorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color# { |
| 532 | return Newscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/New().( |
| 533 | backgroundscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/background., |
| 534 | rgbColorFormatSpecifierscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/rgbColorFormatSpecifier., |
| 535 | Attributescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Attribute#(r), |
| 536 | Attributescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Attribute#(g), |
| 537 | Attributescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Attribute#(b), |
| 538 | ) |
| 539 | } |
| 540 | |
| 541 | // RGB returns a new foreground color in 24-bit RGB. |
| 542 | func RGBscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/RGB().(r, g, b int) *Colorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Color# { |
| 543 | return Newscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/New().( |
| 544 | foregroundscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/foreground., |
| 545 | rgbColorFormatSpecifierscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/rgbColorFormatSpecifier., |
| 546 | Attributescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Attribute#(r), |
| 547 | Attributescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Attribute#(g), |
| 548 | Attributescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/color`/Attribute#(b), |
| 549 | ) |
| 550 | } |