fmtx

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 27, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ColorBlack           = NewColorAnsi(30)
	ColorRed             = NewColorAnsi(31)
	ColorGreen           = NewColorAnsi(32)
	ColorYellow          = NewColorAnsi(33)
	ColorBlue            = NewColorAnsi(34)
	ColorMagenta         = NewColorAnsi(35)
	ColorCyan            = NewColorAnsi(36)
	ColorWhite           = NewColorAnsi(37)
	ColorDefault         = NewColorAnsi(39)
	ColorBgBlack         = NewColorAnsi(40)
	ColorBgRed           = NewColorAnsi(41)
	ColorBgGreen         = NewColorAnsi(42)
	ColorBgYellow        = NewColorAnsi(43)
	ColorBgBlue          = NewColorAnsi(44)
	ColorBgMagenta       = NewColorAnsi(45)
	ColorBgCyan          = NewColorAnsi(46)
	ColorBgWhite         = NewColorAnsi(47)
	ColorBgDefault       = NewColorAnsi(49)
	ColorBrightBlack     = NewColorAnsi(90)
	ColorBrightRed       = NewColorAnsi(91)
	ColorBrightGreen     = NewColorAnsi(92)
	ColorBrightYellow    = NewColorAnsi(93)
	ColorBrightBlue      = NewColorAnsi(94)
	ColorBrightMagenta   = NewColorAnsi(95)
	ColorBrightCyan      = NewColorAnsi(96)
	ColorBrightWhite     = NewColorAnsi(97)
	ColorBgBrightBlack   = NewColorAnsi(100)
	ColorBgBrightRed     = NewColorAnsi(101)
	ColorBgBrightGreen   = NewColorAnsi(102)
	ColorBgBrightYellow  = NewColorAnsi(103)
	ColorBgBrightBlue    = NewColorAnsi(104)
	ColorBgBrightMagenta = NewColorAnsi(105)
	ColorBgBrightCyan    = NewColorAnsi(106)
	ColorBgBrightWhite   = NewColorAnsi(107)
)

Functions

func BgBlack

func BgBlack(s string) string

func BgBlue

func BgBlue(s string) string

func BgBrightBlack

func BgBrightBlack(s string) string

func BgBrightBlue

func BgBrightBlue(s string) string

func BgBrightCyan

func BgBrightCyan(s string) string

func BgBrightGreen

func BgBrightGreen(s string) string

func BgBrightMagenta

func BgBrightMagenta(s string) string

func BgBrightRed

func BgBrightRed(s string) string

func BgBrightWhite

func BgBrightWhite(s string) string

func BgBrightYellow

func BgBrightYellow(s string) string

func BgCyan

func BgCyan(s string) string

func BgDefault

func BgDefault(s string) string

func BgGreen

func BgGreen(s string) string

func BgMagenta

func BgMagenta(s string) string

func BgRed

func BgRed(s string) string

func BgWhite

func BgWhite(s string) string

func BgYellow

func BgYellow(s string) string

func Black

func Black(s string) string

func Blue

func Blue(s string) string

func Bold

func Bold(s string) string

func BrightBlack

func BrightBlack(s string) string

func BrightBlue

func BrightBlue(s string) string

func BrightCyan

func BrightCyan(s string) string

func BrightGreen

func BrightGreen(s string) string

func BrightMagenta

func BrightMagenta(s string) string

func BrightRed

func BrightRed(s string) string

func BrightWhite

func BrightWhite(s string) string

func BrightYellow

func BrightYellow(s string) string

func Cyan

func Cyan(s string) string

func Default

func Default(s string) string

func Dim

func Dim(s string) string

func DisableColors

func DisableColors()

DisableColors disables the use of colors globally in the package.

func DoubleUnderline

func DoubleUnderline(s string) string

func EnableColors

func EnableColors()

EnableColors enables the use of colors globally in the package. By default, colors are enabled.

func Encircled

func Encircled(s string) string

func Error

func Error(msg string, v ...any) error

Error is an alias to fmt.Errorf.

func FPrint

func FPrint(w io.Writer, msg string, v ...any) (n int, err error)

FPrint is an alias to fmt.Fprintf, using the given writer.

func FPrintln

func FPrintln(w io.Writer, msg string, v ...any) (n int, err error)

FPrintln is an alias to fmt.Fprintf using the given writer with a newline at the end.

func Fatal

func Fatal(msg string, v ...any)

Fatal prints a formatted message to stdout and exits the program with status code 1.

func FatalIf added in v0.3.0

func FatalIf(err error)

Fatal prints a formatted message to stdout and exits the program with status code 1 IF the err is not nil.

func FatalIfWith added in v0.3.0

func FatalIfWith(err error, msg string, v ...any)

Fatal prints a formatted message to stdout and exits the program with status code 1 IF the err is not nil.

func Fraktur

func Fraktur(s string) string

func Framed

func Framed(s string) string

func Fscan

func Fscan(r io.Reader, format string, v ...any) (n int, err error)

Fscan is an alias to fmt.Fscanf, using the given reader.

func Fscanln

func Fscanln(r io.Reader, v ...any) (n int, err error)

Fscanln is an alias to fmt.Fscanln, using the given reader.

func Green

func Green(s string) string

func Hidden

func Hidden(s string) string

func Italic

func Italic(s string) string

func Magenta

func Magenta(s string) string

func Overline

func Overline(s string) string

func Panic added in v0.1.0

func Panic(msg string, v ...any)

Panic is an alias to panic with a formatted message.

func Print

func Print(msg string, v ...any)

Print is an alias to fmt.Printf.

func Println

func Println(msg string, v ...any)

Println is an alias to fmt.Printf with a newline at the end.

func RapidBlink(s string) string

func Red

func Red(s string) string

func Reverse

func Reverse(s string) string

func Scan

func Scan(format string, v ...any) (n int, err error)

Scan is an alias to fmt.Scanf.

func Scanln

func Scanln(v ...any) (n int, err error)

Scanln is an alias to fmt.Scanln.

func SlowBlink(s string) string

func Sprint

func Sprint(msg string, v ...any) string

Sprintf is an alias to fmt.Sprintf.

func Sprintln

func Sprintln(msg string, v ...any) string

Sprintln is an alias to fmt.Sprintf with a newline at the end.

func Sscan

func Sscan(str, format string, v ...any) (n int, err error)

Sscan is an alias to fmt.Sscanf.

func Sscanln

func Sscanln(str string, v ...any) (n int, err error)

Sscanln is an alias to fmt.Sscanln.

func StrikeThrough

func StrikeThrough(s string) string

func Stylize

func Stylize(s string, v ...func(s string) string) string

Stylize applies multiple style application functions to a string. The styles are applied in the order they are given.

func Underline

func Underline(s string) string

func White

func White(s string) string

func Yellow

func Yellow(s string) string

Types

type ColorMode

type ColorMode uint8
const (
	ColorModeAnsi ColorMode = iota
	ColorMode256
	ColorModeTrue
)

type Style

type Style struct {
	// contains filtered or unexported fields
}

Style represents a combination of text modifiers and colors that can be applied to a string.

func NewStyle

func NewStyle() *Style

NewStyle creates a new empty Style.

func (*Style) Apply

func (s *Style) Apply(text string) string

func (*Style) WithBold

func (s *Style) WithBold() *Style

WithBold adds the bold modifier to the style.

func (*Style) WithColor

func (s *Style) WithColor(color StyleColor) *Style

WithColor sets the foreground color of the style. Be careful to use

func (*Style) WithDim

func (s *Style) WithDim() *Style

WithDim adds the dim modifier to the style.

func (*Style) WithDoubleUnderline

func (s *Style) WithDoubleUnderline() *Style

WithDoubleUnderline adds the double underline modifier to the style, which adds two lines under the text. This is rarely supported by terminals.

func (*Style) WithEncircled

func (s *Style) WithEncircled() *Style

WithEncircled adds the encircled modifier to the style, which adds a circle around the text. This is rarely supported by terminals.

func (*Style) WithFraktur

func (s *Style) WithFraktur() *Style

WithFraktur adds the fraktur modifier to the style, which changes the font to a fraktur style. This is rarely supported by terminals.

func (*Style) WithFramed

func (s *Style) WithFramed() *Style

WithFramed adds the framed modifier to the style, which adds a frame around the text. This is rarely supported by terminals.

func (*Style) WithHidden

func (s *Style) WithHidden() *Style

WithHidden adds the hidden modifier to the style, which hides the text.

func (*Style) WithInverse

func (s *Style) WithInverse() *Style

WithInverse adds the inverse modifier to the style, which swaps the foreground and background colors.

func (*Style) WithItalic

func (s *Style) WithItalic() *Style

WithItalic adds the italic modifier to the style.

func (*Style) WithOverline

func (s *Style) WithOverline() *Style

WithOverline adds the overline modifier to the style, which adds a line above the text.

func (s *Style) WithRapidBlink() *Style

WithRapidBlink adds the rapid blink modifier to the style. This is rarely supported by terminals.

func (s *Style) WithSlowBlink() *Style

WithSlowBlink adds the slow blink modifier to the style. This is rarely supported by terminals.

func (*Style) WithStrikeThrough

func (s *Style) WithStrikeThrough() *Style

WithStrikeThrough adds the strike through modifier to the style, which adds a line through the text.

func (*Style) WithUnderline

func (s *Style) WithUnderline() *Style

WithUnderline adds the underline modifier to the style.

type StyleColor

type StyleColor struct {
	// contains filtered or unexported fields
}

StyleColor represents a color that can be used in a Style. It can be an ANSI color, a 256 color or a true color.

func NewColor

func NewColor(r, g, b uint8) StyleColor

NewColor creates a new **FOREGROUND** true color with the given RGB values. Use `NewColorBg` to create a background color.

func NewColor256

func NewColor256(code uint8) StyleColor

NewColor256 creates a new 256 **FOREGROUND** color with the given code. Use `NewColor256Bg` to create a background color.

func NewColor256Bg

func NewColor256Bg(code uint8) StyleColor

NewColor256Bg creates a new 256 **BACKGROUND** color with the given code. Use `NewColor256` to create a foreground color.

func NewColorAnsi

func NewColorAnsi(code uint8) StyleColor

NewColorAnsi creates a new ANSI color with the given code. All ansi colors are mapped to constants defined in this package, you may use them instead of creating new ones with this function.

Examples: `ColorRed`, `ColorBgBrightBlue`, ...

func NewColorBg

func NewColorBg(r, g, b uint8) StyleColor

NewColorBg creates a new **BACKGROUND** true color with the given RGB values. Use `NewColor` to create a foreground color.

func (*StyleColor) Code

func (c *StyleColor) Code() string

Code returns the ANSI code for the color, depending on its mode.

func (*StyleColor) ToAnsi

func (c *StyleColor) ToAnsi() StyleColor

ToAnsi converts the color to an ANSI color. If the color is already an ANSI color, it returns the same color.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL