util

package
v3.1.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2018 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
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

func AutoIndexColumnID(colIdx int) string

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

func FilterStrings(s []string, f func(string) bool) []string

FilterStrings filters the slice 's' to items which return truth when passed to 'f'.

func FixedLengthString

func FixedLengthString(s string, length int, snipIndicator string) string

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

func GetLongestLineLength(s string) int

GetLongestLineLength returns the length of the longest "line" within the argument string. For ex.:

GetLongestLineLength("Ghost!\nCome back here!\nRight now!") == 15

func InsertRuneEveryN

func InsertRuneEveryN(s string, r rune, n int) string

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

func RepeatAndTrim(s string, maxRunes int) string

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

func RuneCountWithoutEscapeSeq(s string) int

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

func TrimTextWithoutEscapeSeq(s string, n int) string

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

func WrapText(s string, n int) string

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'
)

func (Cursor) Sprint

func (c Cursor) Sprint() string

Sprint prints the Escape Sequence to move the Cursor once.

func (Cursor) Sprintn

func (c Cursor) Sprintn(n int) string

Sprintn prints the Escape Sequence to move the Cursor "n" times.

Jump to

Keyboard shortcuts

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