Documentation ¶
Overview ¶
Package term provides colors and text formatting for the terminal.
Index ¶
- Constants
- Variables
- func Alert() string
- func Bool(b bool) string
- func Border(w io.Writer, s string)
- func Center(width int, s string) string
- func Comment(s string) string
- func Example(s string) string
- func Fuzzy(s string) string
- func GetEnv(key string) string
- func HR(w io.Writer, width int)
- func Head(w io.Writer, width int, s string)
- func Info(s string) string
- func Inform() string
- func Options(w io.Writer, s string, shorthand, flag bool, opts ...string)
- func Secondary(s string) string
- func Term(colorEnv, env string) string
- func UnderlineChar(s string) (string, error)
- func UnderlineKeys(keys ...string) string
- type Terminal
Examples ¶
Constants ¶
const (
// 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 returns the string "Problem:" using the error color.
Example ¶
package main import ( "fmt" "github.com/bengarrett/retrotxtgo/term" ) func main() { fmt.Print(term.Alert(), "something went wrong") }
Output: Problem: something went wrong
func Bool ¶
Bool returns a checkmark ✓ when true or a cross ✗ when false.
Example ¶
package main import ( "fmt" "github.com/bengarrett/retrotxtgo/term" ) func main() { fmt.Println(term.Bool(true), "yes") fmt.Println(term.Bool(false), "no") }
Output: ✓ yes ✗ no
func Border ¶
Border wraps the string around a single line border.
Example ¶
package main import ( "os" "github.com/bengarrett/retrotxtgo/term" ) func main() { term.Border(os.Stdout, "hi") }
Output: ┌────┐ │ hi │ └────┘
func Center ¶
Center align text to a the width of an area. If the width is less than the length of the string, the string is returned. There is no padding after the string.
Example ¶
package main import ( "fmt" "github.com/bengarrett/retrotxtgo/term" ) func main() { fmt.Print("[" + term.Center(10, "hi") + "]") }
Output: [ hi]
func Comment ¶
Comment returns a string in the comment color.
Example ¶
package main import ( "fmt" "github.com/bengarrett/retrotxtgo/term" ) func main() { fmt.Print(term.Comment("Hi")) }
Output: Hi
func HR ¶
HR returns a horizontal ruler and a line break.
Example ¶
package main import ( "os" "github.com/bengarrett/retrotxtgo/term" ) func main() { term.HR(os.Stdout, 8) }
Output: ────────
func Head ¶
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. The header is colored with the fuzzy color.
Example ¶
package main import ( "os" "github.com/bengarrett/retrotxtgo/term" ) func main() { term.Head(os.Stdout, 10, "heading") }
Output: ────────── heading
func Options ¶
Options writes the string and a sorted list of opts to the writer. If shorthand is true, the options are underlined. If flag is true, the string is prepended with "flag".
Example ¶
package main import ( "os" "github.com/bengarrett/retrotxtgo/term" ) func main() { term.Options(os.Stdout, "this is a list of options", false, false, "option3", "option2", "option1") }
Output: this is a list of options. Options: option1, option2, option3
func Term ¶
Term determines the terminal type based on the COLORTERM and TERM environment variables.
Possible reply values are: terminal, terminal16, terminal256, terminal16m.
The value terminal is a monochrome terminal.
The value terminal16 is a 4-bit, 16 color terminal.
The value terminal256 is a 8-bit, 256 color terminal.
The value terminal16m is a 24-bit, 16 million color terminal.
func UnderlineChar ¶
UnderlineChar uses ANSI to underline the first character of a string.
Example ¶
package main import ( "fmt" "github.com/bengarrett/retrotxtgo/term" "github.com/gookit/color" ) func main() { color.Enable = true defer func() { color.Enable = false }() s, _ := term.UnderlineChar("Z") fmt.Print(s) }
Output: �[0m�[4mZ�[0m
func UnderlineKeys ¶
UnderlineKeys uses ANSI to underline the first letter of each key.