str

package
v0.0.32 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 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
)

Variables

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

Functions

func Alert

func Alert() string

Alert prints "problem:" in 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(text string) *bytes.Buffer

Border wraps text around a single line border.

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

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

func Cb

func Cb(t string) string

Cb returns a string in the color named secondary.

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

Hi

func Cc

func Cc(t string) string

Cc returns a string in the color named comment.

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

Hi

func Ce

func Ce(t string) string

Ce returns a string in the color named warn.

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

Hi

func Center

func Center(width int, text string) string

Center align text to the width.

func Cf

func Cf(t string) string

Cf returns a string in the style named fuzzy.

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

Hi

func Ci

func Ci(t string) string

Ci returns a string in the style named italic.

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

Hi

func Cinf

func Cinf(t string) string

Cinf returns a string in the color named info.

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

Hi

func Cp

func Cp(t string) string

Cp returns a string in the color named primary.

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

Hi

func Cs

func Cs(t string) string

Cs returns a string in the color named success.

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

Hi

func Default

func Default(s, def 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 is intended for the cobra.Command Example fields.

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 HRPadded added in v0.0.31

func HRPadded(width int) string

func Highlight

func Highlight(source, lexer, style string, ansi bool) (err 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) (err error)

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

func Info

func Info() string

Info prints "info:" in Info color.

Example
fmt.Print(Info())
Output:

info:

func JSONStyles

func JSONStyles(cmd 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 bool, opts ...string) (usage string)

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

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

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

func Required

func Required(s string) (usage string)

Required appends (required) to the usage 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) (s string, err 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)

Jump to

Keyboard shortcuts

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