Documentation
¶
Overview ¶
Package str manipulates strings and standard output text.
Index ¶
- Constants
- Variables
- func Alert() string
- func Bool(b bool) string
- func Border(text string) *bytes.Buffer
- func Cb(t string) string
- func Cc(t string) string
- func Ce(t string) string
- func Center(width int, text string) string
- func Cf(t string) string
- func Ci(t string) string
- func Cinf(t string) string
- func Cp(t string) string
- func Cs(t string) string
- func Default(s, def string) string
- func Example(s string) string
- func GetEnv(key string) string
- func HR(width int) string
- func HRPadded(width int) string
- func Highlight(source, lexer, style string, ansi bool) (err error)
- func HighlightWriter(w io.Writer, source, lexer, style string, ansi bool) (err error)
- func Info() string
- func JSONStyles(cmd string)
- func NumberizeKeys(keys ...string) string
- func Options(s string, shorthand bool, opts ...string) (usage string)
- func Required(s string) (usage string)
- func Term(colorEnv, env string) string
- func UnderlineChar(c string) (s string, err error)
- func UnderlineKeys(keys ...string) string
- func Valid(style string) bool
- type JSONExample
Examples ¶
Constants ¶
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 ¶
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 ¶
Bool returns a checkmark ✓ when true or a cross ✗ when false.
Example ¶
fmt.Print(Bool(true)) fmt.Print(Bool(false))
Output: ✓✗
func Border ¶
Border wraps text around a single line border.
Example ¶
fmt.Printf("%s", Border("hi"))
Output: ┌────┐ │ hi │ └────┘
func Cb ¶
Cb returns a string in the color named secondary.
Example ¶
fmt.Print(Cb("Hi"))
Output: Hi
func Cinf ¶
Cinf returns a string in the color named info.
Example ¶
fmt.Print(Cinf("Hi"))
Output: Hi
func Default ¶
Default appends (default ...) to the usage string.
Example ¶
fmt.Print(Default("hi, bye", "hi"))
Output: hi, bye (default "hi")
func GetEnv ¶ added in v0.0.31
GetEnv gets and formats the value of the environment variable named in the key.
func HighlightWriter ¶
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 ¶
NumberizeKeys uses ANSI to underline and prefix a sequential number in front of each key.
func Options ¶
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 ¶
Required appends (required) to the usage string.
Example ¶
fmt.Print(Required("hi"))
Output: hi (required)
func Term ¶
Term determines the terminal type based on the COLORTERM and TERM environment variables.
func UnderlineChar ¶
UnderlineChar uses ANSI to underline the first character of a string.
func UnderlineKeys ¶
UnderlineKeys uses ANSI to underline the first letter of each key.
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)