Documentation
¶
Index ¶
- Constants
- func Fprint(w io.Writer, a ...any)
- func Fprintf(w io.Writer, format string, a ...any)
- func Fprintln(w io.Writer, a ...any)
- func Parse[T StringOrBytes](input T) T
- func Print(a ...any)
- func Printf(format string, a ...any)
- func Println(a ...any)
- func Strip[T StringOrBytes](input T) T
- type StringOrBytes
Constants ¶
const ( RESET = 0 BOLD = 1 FAINT = 2 ITALIC = 3 UNDERLINE = 4 BLINK = 5 INVERT = 7 HIDDEN = 8 STRIKE = 9 BOLD_FAINT_RESET = 22 ITALIC_RESET = 23 UNDER_RESET = 24 BLINK_RESET = 25 INVERT_RESET = 27 HIDDEN_RESET = 28 STRIKE_RESET = 29 FG_BLACK = 30 FG_RED = 31 FG_GREEN = 32 FG_YELLOW = 33 FG_BLUE = 34 FG_MAGENTA = 35 FG_CYAN = 36 FG_WHITE = 37 FG_CUSTOM = 38 FG_DEFAULT = 39 BG_BLACK = 40 BG_RED = 41 BG_GREEN = 42 BG_YELLOW = 43 BG_BLUE = 44 BG_MAGENTA = 45 BG_CYAN = 46 BG_WHITE = 47 BG_CUSTOM = 48 BG_DEFAULT = 49 )
ANSI escape codes
Variables ¶
This section is empty.
Functions ¶
func Fprint ¶
Fprint is a wrapper around fmt.Fprint. It will call the standard library's Sprint function with the given arguments and then pass the result to ansi.Parse. The result of this is then sent to the given writer.
func Fprintf ¶
Fprintf is a wrapper around fmt.Fprintf. It will call the standard library's Sprintf function with the given arguments and then pass the result to ansi.Parse. The result of this is then sent to the given writer.
func Fprintln ¶
Fprintln is a wrapper around fmt.Fprintln. It will call the standard library's Sprintln function with the given arguments and then pass the result to ansi.Parse. The result of this is then sent to the given writer.
func Parse ¶
func Parse[T StringOrBytes](input T) T
Parse will search the given input for codes given in the [code] format and replace them with the equivalent ANSI escape sequence. For example, if the input string is "[red]hello[/]" the output will be "\x1b[31mhello\x1b[0m". When output to a terminal this would print the string "hello" in red. See the list of constants in this package for available codes. Multiple codes can be specified at once by using the [code1:code2] syntax. If any code in the set is not recognized, the entire set is returned as-is. If you want the literal string [red], you can escape the parsing by using \[red].
func Print ¶
func Print(a ...any)
Print is a wrapper around fmt.Print. It will call the standard library's Sprint function with the given arguments and then pass the result to ansi.Parse. The result of this is then printed to stdout.
func Printf ¶
Printf is a wrapper around fmt.Printf. It will call the standard library's Sprintf function with the given arguments and then pass the result to ansi.Parse. The result of this is then printed to stdout.
func Println ¶
func Println(a ...any)
Println is a wrapper around fmt.Println. It will call the standard library's Sprintln function with the given arguments and then pass the result to ansi.Parse. The result of this is then printed to stdout.
func Strip ¶
func Strip[T StringOrBytes](input T) T
Strip will search the given input for codes given in the [code] format and delete them. For example, if the input string is "[red]hello[/]" the output will be "hello". See the list of constants in this package for available codes. Multiple codes can be specified at once by using the [code1:code2] syntax. If any code in the set is not recognized, the entire set is returned as-is. If you want the literal string [red], you can escape the parsing by using \[red].