cli/pkg/cli/strings.go
Virgil aa537c89ca
Some checks are pending
Security Scan / security (push) Waiting to run
fix(cli): make styled helpers nil-safe
Co-Authored-By: Virgil <virgil@lethean.io>
2026-04-02 06:30:14 +00:00

54 lines
1.4 KiB
Go

package cli
import "fmt"
// Sprintf formats a string (fmt.Sprintf wrapper).
func Sprintf(format string, args ...any) string {
return fmt.Sprintf(format, args...)
}
// Sprint formats using default formats (fmt.Sprint wrapper).
func Sprint(args ...any) string {
return fmt.Sprint(args...)
}
// Styled returns text with a style applied.
func Styled(style *AnsiStyle, text string) string {
if style == nil {
return compileGlyphs(text)
}
return style.Render(compileGlyphs(text))
}
// Styledf returns formatted text with a style applied.
func Styledf(style *AnsiStyle, format string, args ...any) string {
if style == nil {
return compileGlyphs(fmt.Sprintf(format, args...))
}
return style.Render(compileGlyphs(fmt.Sprintf(format, args...)))
}
// SuccessStr returns success-styled string.
func SuccessStr(msg string) string {
return SuccessStyle.Render(Glyph(":check:") + " " + compileGlyphs(msg))
}
// ErrorStr returns error-styled string.
func ErrorStr(msg string) string {
return ErrorStyle.Render(Glyph(":cross:") + " " + compileGlyphs(msg))
}
// WarnStr returns warning-styled string.
func WarnStr(msg string) string {
return WarningStyle.Render(Glyph(":warn:") + " " + compileGlyphs(msg))
}
// InfoStr returns info-styled string.
func InfoStr(msg string) string {
return InfoStyle.Render(Glyph(":info:") + " " + compileGlyphs(msg))
}
// DimStr returns dim-styled string.
func DimStr(msg string) string {
return DimStyle.Render(compileGlyphs(msg))
}