str

package
v0.0.37 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2021 License: LGPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

Package str manipulates strings and standard output text.

Index

Examples

Constants

View Source
const (
	// TermMono no color.
	TermMono terminal = iota
	// Term16 ANSI standard 16 color.
	Term16
	// Term88 XTerm 88 color.
	Term88
	// Term256 XTerm 256 color.
	Term256
	// Term16M ANSI high-color.
	Term16M
	// HBar is a the Unicode horizontal bar character.
	HBar = "\u2500"
)

Variables

View Source
var ErrRune = errors.New("invalid encoded rune")

Functions

func Alert

func Alert() string

Alert prints "Problem" using the Error color.

Example
fmt.Print(Alert())
Output:

Problem:

func Bool

func Bool(b bool) string

Bool returns a checkmark ✓ when true or a cross ✗ when false.

Example
fmt.Print(Bool(true))
fmt.Print(Bool(false))
Output:

✓✗

func Border

func Border(s string) *bytes.Buffer

Border wraps the string around a single line border.

Example
fmt.Printf("%s", Border("hi"))
Output:

┌────┐
│ hi │
└────┘

func Center

func Center(width int, s string) string

Center align text to a the width of an area.

func ColCmt added in v0.0.33

func ColCmt(s string) string

ColCmt returns a string in the comment color.

Example
fmt.Print(ColCmt("Hi"))
Output:

Hi

func ColFuz added in v0.0.33

func ColFuz(s string) string

ColFuz returns a string in the fuzzy color.

Example
fmt.Print(ColFuz("Hi"))
Output:

Hi

func ColInf added in v0.0.33

func ColInf(s string) string

ColInf returns a string in the info color.

Example
fmt.Print(ColInf("Hi"))
Output:

Hi

func ColPri added in v0.0.33

func ColPri(s string) string

ColPri returns a string in the primary color.

Example
fmt.Print(ColPri("Hi"))
Output:

Hi

func ColSec added in v0.0.33

func ColSec(s string) string

ColSec returns a string in the secondary color.

Example
fmt.Print(ColSec("Hi"))
Output:

Hi

func ColSuc added in v0.0.33

func ColSuc(s string) string

ColSuc returns a string in the success color.

Example
fmt.Print(ColSuc("Hi"))
Output:

Hi

func Confirm added in v0.0.33

func Confirm() string

Confirm prints the "Confirm" string using the Question color.

func Default

func Default(s, val string) string

Default appends (default ...) to the usage string.

Example
fmt.Print(Default("hi, bye", "hi"))
Output:

hi, bye (default "hi")

func Example

func Example(s string) string

Example prints the string using the Debug color.

func GetEnv added in v0.0.31

func GetEnv(key string) string

GetEnv gets and formats the value of the environment variable named in the key.

func HR added in v0.0.31

func HR(width int) string

HR returns a horizontal ruler or line break.

func HRPad added in v0.0.33

func HRPad(width int) string
func Head(width int, s string) string

Head returns a colored and underlined string for use as a header. Provide a fixed width value for the underline border or set to zero.

func HeadDark added in v0.0.33

func HeadDark(width int, s string) string

func Highlight

func Highlight(source, lexer, style string, ansi bool) error

Highlight and print the syntax of the source string except when piped to stdout.

func HighlightWriter

func HighlightWriter(w io.Writer, source, lexer, style string, ansi bool) error

HighlightWriter writes the highlight syntax of the source string except when piped to stdout.

func Info

func Info() string

Info prints "Information" using the Info color.

Example
fmt.Print(Info())
Output:

Information:

func Italic added in v0.0.33

func Italic(s string) string

Italic returns a string in the italic style.

Example
fmt.Print(Italic("Hi"))
Output:

Hi

func JSONStyles

func JSONStyles(cmd string) string

JSONStyles prints out a list of available YAML color styles.

func NumberizeKeys

func NumberizeKeys(keys ...string) string

NumberizeKeys uses ANSI to underline and prefix a sequential number in front of each key.

func Options

func Options(s string, shorthand, flagHelp bool, opts ...string) string

Options appends options: ... to the usage string.

Example
fmt.Print(Options("this is an example of a list of options",
	false, false, "option3", "option2", "option1"))
Output:

this is an example of a list of options.
  Options: option1, option2, option3

func Path added in v0.0.33

func Path(s string) string

func Required

func Required(s string) string

Required appends (required) to the string.

Example
fmt.Print(Required("hi"))
Output:

hi (required)

func Term

func Term(colorEnv, env string) string

Term determines the terminal type based on the COLORTERM and TERM environment variables.

func UnderlineChar

func UnderlineChar(c string) (string, error)

UnderlineChar uses ANSI to underline the first character of a string.

func UnderlineKeys

func UnderlineKeys(keys ...string) string

UnderlineKeys uses ANSI to underline the first letter of each key.

func Valid added in v0.0.31

func Valid(style string) bool

Valid checks style name validity.

Types

type JSONExample

type JSONExample struct {
	Style struct {
		Name    string `json:"name"`
		Count   int    `json:"count"`
		Default bool   `json:"default"`
	}
}

JSONExample is used to preview theme colors.

func (JSONExample) String

func (s JSONExample) String(flag string) string

Jump to

Keyboard shortcuts

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