Documentation
¶
Overview ¶
Package str manipulates strings and standard output text.
Index ¶
- Constants
- Variables
- func Alert() string
- func Bool(b bool) string
- func Border(s string) *bytes.Buffer
- func Center(width int, s string) string
- func ColCmt(s string) string
- func ColFuz(s string) string
- func ColInf(s string) string
- func ColPri(s string) string
- func ColSec(s string) string
- func ColSuc(s string) string
- func Confirm() string
- func Default(s, val string) string
- func Example(s string) string
- func GetEnv(key string) string
- func HR(width int) string
- func HRPad(width int) string
- func Head(width int, s string) string
- func HeadDark(width int, s string) string
- func Highlight(source, lexer, style string, ansi bool) error
- func HighlightWriter(w io.Writer, source, lexer, style string, ansi bool) error
- func Info() string
- func Italic(s string) string
- func JSONStyles(cmd string) string
- func NumberizeKeys(keys ...string) string
- func Options(s string, shorthand, flagHelp bool, opts ...string) string
- func Path(s string) string
- func Required(s string) string
- func Term(colorEnv, env string) string
- func UnderlineChar(c string) (string, 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 // HBar is a the Unicode horizontal bar character. HBar = "\u2500" )
Variables ¶
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 ¶
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 the string around a single line border.
Example ¶
fmt.Printf("%s", Border("hi"))
Output: ┌────┐ │ hi │ └────┘
func ColCmt ¶ added in v0.0.33
ColCmt returns a string in the comment color.
Example ¶
fmt.Print(ColCmt("Hi"))
Output: Hi
func ColFuz ¶ added in v0.0.33
ColFuz returns a string in the fuzzy color.
Example ¶
fmt.Print(ColFuz("Hi"))
Output: Hi
func ColInf ¶ added in v0.0.33
ColInf returns a string in the info color.
Example ¶
fmt.Print(ColInf("Hi"))
Output: Hi
func ColPri ¶ added in v0.0.33
ColPri returns a string in the primary color.
Example ¶
fmt.Print(ColPri("Hi"))
Output: Hi
func ColSec ¶ added in v0.0.33
ColSec returns a string in the secondary color.
Example ¶
fmt.Print(ColSec("Hi"))
Output: Hi
func ColSuc ¶ added in v0.0.33
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 ¶
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 Head ¶ added in v0.0.33
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 HighlightWriter ¶
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
Italic returns a string in the italic style.
Example ¶
fmt.Print(Italic("Hi"))
Output: Hi
func JSONStyles ¶
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, 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 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) string