text

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2017 License: BSD-2-Clause Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Reset     = "\033[0m"
	Bold      = "\033[1m"
	Normal    = "\033[22m"
	Black     = "\033[30m"
	Red       = "\033[31m"
	Green     = "\033[32m"
	Yellow    = "\033[33m"
	Blue      = "\033[34m"
	Magenta   = "\033[35m"
	Cyan      = "\033[36m"
	White     = "\033[37m"
	BGBlack   = "\033[40m"
	BGRed     = "\033[41m"
	BGGreen   = "\033[42m"
	BGYellow  = "\033[43m"
	BGBlue    = "\033[44m"
	BGMagenta = "\033[45m"
	BGCyan    = "\033[46m"
	BGWhite   = "\033[47m"

	// Setup brown as an alias for yellow
	Brown   = Yellow
	BGBrown = BGYellow

	// WolfMUD specific meta colors
	Good   = Green
	Info   = Yellow
	Bad    = Red
	Prompt = Magenta
)

ANSI escape sequences for setting colors. These sequences can be concatenated into strings or appended to slice directly. This is preferable to calling Colorize with embedded colour place holders due to the slower performance of Colorize.

Variables

This section is empty.

Functions

func Colorize

func Colorize(in []byte) []byte

Colorize returns a []byte with color place holders replaced with their ANSI escape sequence equivalent. Color place holders have the format [COLOR] where COLOR represents the name of the color (uppercased) to be used. For example:

Colorize([]byte("[RED]Hello [GREEN]World![DEFAULT]"))

Would return a []byte with [RED] and [GREEN] replaced with the ANSI escape sequences \033[31m and \033[32m respectively causing Hello to be displayed in red and World! to be displayed in green.

The returned slice is always a copy even it the original contains no colors.

Use of this function is discouraged due to relatively poor performance. It's main use is to render text from files, such as those loaded when the server is initially started. In code it is better to use the ANSI escape sequence constants directly.

func Dictionary

func Dictionary(s ...string) (d *dictionary)

Dictionary returns a new dictionary containing the specified strings. The dictionary can then be checked to see if it contains a specific string (case insensitive) by calling the Contains method.

NOTE: The strings in the dictionary are converted to uppercase.

func Fold

func Fold(in []byte, width int) (out []byte)

Fold takes a []byte and attempts to reformat it so lines have a maximum length of the passed width. Fold will only split lines on whitespace when reformatting. This may result in lines longer than the given width when a word is too long and cannot be split. A width of zero or less indicates no folding will be done but line endings will still be changed from Unix '\n' to network '\r\n' line endings and trailing whitespace, except line feeds '\n', will be removed.

Fold will handle multibyte runes. However it cannot handle 'wide' runes - those that are wider than a normal single character when displayed. This is because the required information is actually contained in the font files of the font in use at the 'client' end.

For example the Chinese for 9 is 九 (U+4E5D). Even in a monospaced font 九 will take up the space of two columns.

For combining characters Fold will assume combining marks are zero width. For example 'a' plus a combining grave accent U+0061 U+0300 will be counted as a single character. However it is better to use and actual latin small letter a with grave 'à' U+00E0. Either should work as expected.

It is expected that the end of line markers for incoming data are Unix line feeds (LF, '\n') and outgoing data will have network line endings, carriage return + line feed pairs (CR+LF, '\r\n').

func TitleFirst added in v0.0.4

func TitleFirst(s string) string

TitleFirst will return the passed string with the first rune in the string Titlecased.

Types

This section is empty.

Jump to

Keyboard shortcuts

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