Documentation ¶
Overview ¶
Package escapes has a handful of useful functions for when you're wanting to send formatting escape sequences to the terminal while tracking the width of your output for alignment purposes.
The escape sequences always restore things back to 'normal' when done, which could be considered suboptimal when adding styles but keeps things sane.
This does not use terminfo, and just relies on ECMA-48 and related ANSI standards; see https://en.wikipedia.org/wiki/ANSI_escape_code for too much and yet too little detail.
Index ¶
- Constants
- func Bold(s string) width.StringWidther
- func Colorized(s string, fg, bg *color.Color) width.StringWidther
- func Dim(s string) width.StringWidther
- func Hyperlink(u, t string) width.StringWidther
- func Italic(s string) width.StringWidther
- func Reverse(s string) width.StringWidther
- func ReverseLine(s string) string
- func Underline(s string) width.StringWidther
Constants ¶
const ( BeginBold = CSI + "1m" BeginDim = CSI + "2m" BeginItalic = CSI + "3m" BeginUnderline = CSI + "4m" BeginReverse = CSI + "7m" SGR0 = CSI + "0m" ClrEOL = CSI + "K" )
Several constants that might be handy to have (and are used by us)
const CSI = "\x1b["
CSI or Control Sequence Introducer is the start of most things we deal with here
Variables ¶
This section is empty.
Functions ¶
func Bold ¶
func Bold(s string) width.StringWidther
Bold returns a string that turns on bold mode for the text given.
func Colorized ¶
func Colorized(s string, fg, bg *color.Color) width.StringWidther
Colorized returns a string with escape sequences that shows the text t with foreground and backgroun colours as given.
It assumes 24-bit colour support.
func Dim ¶
func Dim(s string) width.StringWidther
Dim returns a string that turns on dim mode for the text given.
func Hyperlink ¶
func Hyperlink(u, t string) width.StringWidther
Hyperlink returns an escape sequence that links to the url u with the text t.
func Italic ¶
func Italic(s string) width.StringWidther
Italic returns a string that turns on italic mode for the text given.
NOTE many terminals don't implement this (or have support for it
turned off by default).
func Reverse ¶
func Reverse(s string) width.StringWidther
Reverse returns a string that turns on reverse video mode for the text given.
func ReverseLine ¶
ReverseLine returns a string that uses reverse video and clears to the end of the line.
This includes a newline to avoid confusion (otherwise the cursor maybe be in an unexpected place).
Note that the width of the string is terminal-dependent and thus not knowable from here.
func Underline ¶
func Underline(s string) width.StringWidther
Underline returns a string that turns on underline mode for the text given.
Types ¶
This section is empty.