Documentation
¶
Index ¶
- Constants
- func AsString(x interface{}) string
- func AutoIndexColumnID(colIdx int) string
- 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 IsNumber(x interface{}) bool
- func IsString(x interface{}) bool
- 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 Cursor
Constants ¶
const ( EscapeReset = EscapeStart + "0" + EscapeStop EscapeStart = "\x1b[" EscapeStartRune = rune(27) // \x1b EscapeStop = "m" EscapeStopRune = 'm' )
Constants
Variables ¶
This section is empty.
Functions ¶
func AsString ¶
func AsString(x interface{}) string
AsString returns the argument in a 'string' form no matter what type it is.
func AutoIndexColumnID ¶
AutoIndexColumnID returns a unique Column ID/Name for the given Column Number. The functionality is similar to what you get in an Excel spreadsheet w.r.t. the Column ID/Name.
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 IsNumber ¶
func IsNumber(x interface{}) bool
IsNumber returns true if the argument is a numeric type; false otherwise.
func IsString ¶
func IsString(x interface{}) bool
IsString returns true if the argument is a string; false otherwise.
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 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' )