utils

package
v0.0.1-beta.1 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2020 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Outputs ANSI color if stdout is a tty
	Magenta = makeColorFunc("magenta")
	Cyan    = makeColorFunc("cyan")
	Red     = makeColorFunc("red")
	Yellow  = makeColorFunc("yellow")
	Blue    = makeColorFunc("blue")
	Green   = makeColorFunc("green")
	Gray    = makeColorFunc("black+h")
	Bold    = makeColorFunc("default+b")
)
View Source
var IsTerminal = func(w interface{}) bool {
	if f, isFile := w.(*os.File); isFile {
		return isatty.IsTerminal(f.Fd()) || IsCygwinTerminal(f)
	}

	return false
}
View Source
var StartSpinner = func(s *spinner.Spinner) {
	s.Start()
}

We do this so we can stub out the spinner in tests -- it made things really flakey. this is not an elegant solution.

View Source
var StopSpinner = func(s *spinner.Spinner) {
	s.Stop()
}
View Source
var TerminalSize = func(w interface{}) (int, int, error) {
	if f, isFile := w.(*os.File); isFile {
		return terminal.GetSize(int(f.Fd()))
	}

	return 0, 0, fmt.Errorf("%v is not a file", w)
}

Functions

func Compress

func Compress(zipFilename string, filename string) error

func CompressDir

func CompressDir(w *zip.Writer, dirName string) error

func CompressFile

func CompressFile(w *zip.Writer, filename string) error

func DisplayURL

func DisplayURL(urlStr string) string

func ExpandUser

func ExpandUser(pathname string) string

func FileExists

func FileExists(filename string) bool

FileExists checks if a file exists and is not a directory before we try using it to prevent further errors.

func FuzzyAgo

func FuzzyAgo(ago time.Duration) string

func GreenCheck

func GreenCheck() string

func Humanize

func Humanize(s string) string

func IsCygwinTerminal

func IsCygwinTerminal(w interface{}) bool

func IsURL

func IsURL(s string) bool

func NewColorable

func NewColorable(w io.Writer) io.Writer

NewColorable returns an output stream that handles ANSI color sequences on Windows

func OpenInBrowser

func OpenInBrowser(url string) error

OpenInBrowser opens the url in a web browser based on OS and $BROWSER environment variable

func Pluralize

func Pluralize(num int, thing string) string

func RandStringRunes

func RandStringRunes(n int) string

func RenderMarkdown

func RenderMarkdown(text string) (string, error)

func Spinner

func Spinner(w io.Writer) *spinner.Spinner

Types

type TablePrinter

type TablePrinter interface {
	IsTTY() bool
	AddField(string, func(int, string) string, func(string) string)
	EndRow()
	Render() error
}

func NewTablePrinter

func NewTablePrinter(io *iostreams.IOStreams) TablePrinter

Jump to

Keyboard shortcuts

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