Documentation ¶
Index ¶
- Constants
- Variables
- func DisableColors()
- func EnableColors()
- func FilterStrings(s []string, f func(string) bool) []string
- func FixedLengthString(s string, length int, snipIndicator string) string
- func GetLongestLineLength(s string) int
- func InsertRuneEveryN(s string, r rune, n int) string
- func RepeatAndTrim(s string, maxRunes int) string
- func RuneCountWithoutEscapeSeq(s string) int
- func TrimTextWithoutEscapeSeq(s string, n int) string
- func WrapText(s string, n int) string
- type Align
- type Color
- type Colors
- type Cursor
- type Format
- type VAlign
Constants ¶
const ( EscapeReset = EscapeStart + "0" + EscapeStop EscapeStart = "\x1b[" EscapeStartRune = rune(27) // \x1b EscapeStop = "m" EscapeStopRune = 'm' )
Constants
Variables ¶
var ANSICodesSupported = areANSICodesSupported()
ANSICodesSupported will be true on consoles where ANSI Escape Codes/Sequences are supported.
Functions ¶
func DisableColors ¶
func DisableColors()
DisableColors (forcefully) disables color coding globally.
func FilterStrings ¶
FilterStrings filters the slice 's' to items which return truth when passed to 'f'.
func FixedLengthString ¶
FixedLengthString returns the given string with a fixed length. For ex.:
FixedLengthString("Ghost", 0, "~") == "Ghost" FixedLengthString("Ghost", 1, "~") == "~" FixedLengthString("Ghost", 3, "~") == "Gh~" FixedLengthString("Ghost", 5, "~") == "Ghost" FixedLengthString("Ghost", 7, "~") == "Ghost "
func GetLongestLineLength ¶
GetLongestLineLength returns the length of the longest "line" within the argument string. For ex.:
GetLongestLineLength("Ghost!\nCome back here!\nRight now!") == 15
func InsertRuneEveryN ¶
InsertRuneEveryN inserts the rune every N characters in the string. For ex.:
InsertRuneEveryN("Ghost", '-', 1) == "G-h-o-s-t" InsertRuneEveryN("Ghost", '-', 2) == "Gh-os-t" InsertRuneEveryN("Ghost", '-', 3) == "Gho-st" InsertRuneEveryN("Ghost", '-', 4) == "Ghos-t" InsertRuneEveryN("Ghost", '-', 5) == "Ghost"
func RepeatAndTrim ¶
RepeatAndTrim repeats the given string until it is as long as maxRunes. For ex.:
RepeatAndTrim("Ghost", 0) == "" RepeatAndTrim("Ghost", 5) == "Ghost" RepeatAndTrim("Ghost", 7) == "GhostGh" RepeatAndTrim("Ghost", 10) == "GhostGhost"
func RuneCountWithoutEscapeSeq ¶
RuneCountWithoutEscapeSeq is similar to utf8.RuneCountInString, except for the fact that it ignores escape sequences in the counting. For ex.:
RuneCountWithoutEscapeSeq("") == 0 RuneCountWithoutEscapeSeq("Ghost") == 5 RuneCountWithoutEscapeSeq("\x1b[33mGhost\x1b[0m") == 5 RuneCountWithoutEscapeSeq("\x1b[33mGhost\x1b[0") == 5
func TrimTextWithoutEscapeSeq ¶
TrimTextWithoutEscapeSeq trims a string to the given length accounting for escape sequences For ex.:
TrimTextWithoutEscapeSeq("Ghost", 3) == "Gho" TrimTextWithoutEscapeSeq("Ghost", 6) == "Ghost" TrimTextWithoutEscapeSeq("\x1b[33mGhost\x1b[0m", 3) == "\x1b[33mGho\x1b[0m" TrimTextWithoutEscapeSeq("\x1b[33mGhost\x1b[0m", 6) == "\x1b[33mGhost\x1b[0m"
func WrapText ¶
WrapText wraps a string to the given length using a newline. For ex.:
WrapText("Ghost", 1) == "G\nh\no\ns\nt" WrapText("Ghost", 2) == "Gh\nos\nt" WrapText("Ghost", 3) == "Gho\nst" WrapText("Ghost", 4) == "Ghos\nt" WrapText("Ghost", 5) == "Ghost" WrapText("Ghost", 6) == "Ghost" WrapText("Jon\nSnow", 2) == "Jo\nn\nSn\now" WrapText("Jon\nSnow\n", 2) == "Jo\nn\nSn\now\n"
Types ¶
type Align ¶
type Align int
Align denotes how text is to be aligned horizontally.
const ( AlignDefault Align = iota // same as AlignLeft AlignLeft // "left " AlignCenter // " center " AlignJustify // "justify it" AlignRight // " right" )
Align enumerations
func (Align) Apply ¶
Apply aligns the text as directed. Examples:
- AlignDefault.Apply("Jon Snow", 12) returns "Jon Snow "
- AlignLeft.Apply("Jon Snow", 12) returns "Jon Snow "
- AlignCenter.Apply("Jon Snow", 12) returns " Jon Snow "
- AlignJustify.Apply("Jon Snow", 12) returns "Jon Snow"
- AlignRight.Apply("Jon Snow", 12) returns " Jon Snow"
func (Align) HTMLProperty ¶
HTMLProperty returns the equivalent HTML horizontal-align tag property.
func (Align) MarkdownProperty ¶
MarkdownProperty returns the equivalent Markdown horizontal-align separator.
type Color ¶
type Color int
Color represents a single color to render with.
const ( Reset Color = iota Bold Faint Italic Underline BlinkSlow BlinkRapid ReverseVideo Concealed CrossedOut )
Base colors -- attributes in reality
Foreground colors
const ( FgHiBlack Color = iota + 90 FgHiRed FgHiGreen FgHiYellow FgHiBlue FgHiMagenta FgHiCyan FgHiWhite )
Foreground Hi-Intensity colors
Background colors
const ( BgHiBlack Color = iota + 100 BgHiRed BgHiGreen BgHiYellow BgHiBlue BgHiMagenta BgHiCyan BgHiWhite )
Background Hi-Intensity colors
func (Color) GetEscapeSeq ¶
GetEscapeSeq returns the ANSI escape sequence for the color.
type Colors ¶
type Colors []Color
Colors represents an array of Color objects to render with. Example: Colors{FgCyan, BgBlack}
func (Colors) GetEscapeSeq ¶
GetEscapeSeq returns the ANSI escape sequence for the colors set.
type Cursor ¶
type Cursor rune
Cursor helps move the cursor on the console in multiple directions.
const ( // CursorDown helps move the Cursor Down X lines CursorDown Cursor = 'B' // CursorLeft helps move the Cursor Left X characters CursorLeft Cursor = 'D' // CursorRight helps move the Cursor Right X characters CursorRight Cursor = 'C' // CursorUp helps move the Cursor Up X lines CursorUp Cursor = 'A' // EraseLine helps erase all characters to the Right of the Cursor in the // current line EraseLine Cursor = 'K' )
type Format ¶
type Format int
Format denotes the "case" to use for text.
type VAlign ¶
type VAlign int
VAlign denotes how text is to be aligned vertically.
const ( VAlignDefault VAlign = iota // same as VAlignTop VAlignTop // "top\n\n" VAlignMiddle // "\nmiddle\n" VAlignBottom // "\n\nbottom" )
VAlign enumerations
func (VAlign) Apply ¶
Apply aligns the lines vertically. Examples:
- VAlignTop.Apply({"Game", "Of", "Thrones"}, 5) returns {"Game", "Of", "Thrones", "", ""}
- VAlignMiddle.Apply({"Game", "Of", "Thrones"}, 5) returns {"", "Game", "Of", "Thrones", ""}
- VAlignBottom.Apply({"Game", "Of", "Thrones"}, 5) returns {"", "", "Game", "Of", "Thrones"}
func (VAlign) ApplyStr ¶
ApplyStr aligns the string (of 1 or more lines) vertically. Examples:
- VAlignTop.ApplyStr("Game\nOf\nThrones", 5) returns {"Game", "Of", "Thrones", "", ""}
- VAlignMiddle.ApplyStr("Game\nOf\nThrones", 5) returns {"", "Game", "Of", "Thrones", ""}
- VAlignBottom.ApplyStr("Game\nOf\nThrones", 5) returns {"", "", "Game", "Of", "Thrones"}
func (VAlign) HTMLProperty ¶
HTMLProperty returns the equivalent HTML vertical-align tag property.