common

package
v0.0.0-...-d0e6ce9 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ColorFuncMap = template.FuncMap{
	"black":     color.New(color.FgHiBlack).SprintFunc(),
	"red":       color.New(color.FgHiRed).SprintFunc(),
	"green":     color.New(color.FgHiGreen).SprintFunc(),
	"yellow":    color.New(color.FgHiYellow).SprintFunc(),
	"blue":      color.New(color.FgHiBlue).SprintFunc(),
	"magenta":   color.New(color.FgHiMagenta).SprintFunc(),
	"cyan":      color.New(color.FgHiCyan).SprintFunc(),
	"white":     color.New(color.FgHiWhite).SprintFunc(),
	"bgBlack":   color.New(color.BgHiBlack).SprintFunc(),
	"bgRed":     color.New(color.BgHiRed).SprintFunc(),
	"bgGreen":   color.New(color.BgHiGreen).SprintFunc(),
	"bgYellow":  color.New(color.BgHiYellow).SprintFunc(),
	"bgBlue":    color.New(color.BgHiBlue).SprintFunc(),
	"bgMagenta": color.New(color.BgHiMagenta).SprintFunc(),
	"bgCyan":    color.New(color.BgHiCyan).SprintFunc(),
	"bgWhite":   color.New(color.BgHiWhite).SprintFunc(),
	"bold":      color.New(color.Bold).SprintFunc(),
	"faint":     color.New(color.Faint).SprintFunc(),
	"italic":    color.New(color.Italic).SprintFunc(),
	"underline": color.New(color.Underline).SprintFunc(),
	"reset":     color.New(color.Reset).SprintFunc(),
}
View Source
var ErrAborted = fmt.Errorf("prompt aborted")

ErrAborted is returned when the prompt was aborted.

Functions

func GenSpaces

func GenSpaces(l int) string

GenSpaces generate a space string of specified length

func GenStr

func GenStr(l int, s string) string

GenStr generate a string of the specified length, the string is composed of the given characters

func HardWrap

func HardWrap(input string, width int) string

HardWrap performs a hard wrap at the given width.

func RenderedText

func RenderedText(str, strcolor string) string

func Truncate

func Truncate(input string, width int) string

Truncate cuts the string after the given width.

func UtilFuncMap

func UtilFuncMap() template.FuncMap

UtilFuncMap returns a template.FuncMap with handy utility functions for prompt templates.

  • Repeat(string, int) string: Identical to strings.Repeat.
  • Len(string): reflow/ansi.PrintableRuneWidth, Len works like len but is aware of ansi codes and returns the length of the string as it appears on the screen.
  • Min(int, int) int: The minimum of two ints.
  • Max(int, int) int: The maximum of two ints.
  • Add(int, int) int: The sum of two ints.
  • Sub(int, int) int: The difference of two ints.
  • Mul(int, int) int: The product of two ints.

func WordWrap

func WordWrap(input string, width int) string

WordWrap performs a word wrap on the input and forces a wrap at width if a word is still larger that width after soft wrapping. This is known to cause issues with coloring in some terminals depending on the prompt style.

Types

type WrapMode

type WrapMode func(string, int) string

WrapMode decides in which way text is wrapped.

Jump to

Keyboard shortcuts

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