utils

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2021 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// Magenta outputs ANSI color if stdout is a tty
	Magenta = makeColorFunc("magenta")

	// Cyan outputs ANSI color if stdout is a tty
	Cyan = makeColorFunc("cyan")

	// Red outputs ANSI color if stdout is a tty
	Red = makeColorFunc("red")

	// Yellow outputs ANSI color if stdout is a tty
	Yellow = makeColorFunc("yellow")

	// Blue outputs ANSI color if stdout is a tty
	Blue = makeColorFunc("blue")

	// Green outputs ANSI color if stdout is a tty
	Green = makeColorFunc("green")

	// Gray outputs ANSI color if stdout is a tty
	Gray = makeColorFunc("black+h")

	// Bold outputs ANSI color if stdout is a tty
	Bold = makeColorFunc("default+b")
)
View Source
var IsTerminal = func(f *os.File) bool {
	return isatty.IsTerminal(f.Fd()) || IsCygwinTerminal(f)
}

IsTerminal reports whether the file descriptor is connected to a terminal

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 CommonElementsInStringSlice added in v1.14.0

func CommonElementsInStringSlice(s1 []string, s2 []string) (arr []string)

CommonElementsInStringSlice takes 2 Slices of Strings and returns a Third Slice that is the common elements between the first 2 Slices.

func DisplayURL

func DisplayURL(urlStr string) string

func Editor

func Editor(opts EditorOptions) string

func FailedIcon added in v1.14.0

func FailedIcon() string

func GreenCheck

func GreenCheck() string

func Humanize

func Humanize(s string) string

func Indent

func Indent(s, indent string) string

func IsCygwinTerminal added in v1.12.0

func IsCygwinTerminal(f *os.File) bool

func IsValidURL added in v1.14.0

func IsValidURL(toTest string) bool

isValidUrl tests a string to determine if it is a well-structured url or not.

func NewColorable

func NewColorable(out io.Writer) io.Writer

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

func OpenInBrowser

func OpenInBrowser(url, browserType 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 PresentInIntSlice added in v1.14.0

func PresentInIntSlice(hay []int, needle int) bool

PresentInIntSlice take a Hay (Slice of Ints) and a Needle (int) and returns true based on whether or not the Needle is present in the hay.

func PresentInStringSlice added in v1.14.0

func PresentInStringSlice(hay []string, needle string) bool

PresentInStringSlice take a Hay (Slice of Strings) and a Needle (string) and returns true based on whether or not the Needle is present in the hay.

func PrettyTimeAgo

func PrettyTimeAgo(ago time.Duration) string

func RedCheck

func RedCheck() string

func RenderMarkdown

func RenderMarkdown(text, glamourStyle string) (string, error)

func ReplaceNonAlphaNumericChars

func ReplaceNonAlphaNumericChars(words, replaceWith string) string

ReplaceNonAlphaNumericChars : Replaces non alpha-numeric values with provided char/string

func StringToInt

func StringToInt(str string) int

func TerminalWidth added in v1.12.0

func TerminalWidth(out io.Writer) int

func TimeToPrettyTimeAgo

func TimeToPrettyTimeAgo(d time.Time) string

func WarnIcon added in v1.14.0

func WarnIcon() string

Types

type EditorOptions

type EditorOptions struct {
	FileName      string
	Label         string
	Help          string
	Default       string
	AppendDefault bool
	HideDefault   bool
}

type IOStreams

type IOStreams struct {
	In     io.ReadCloser
	StdOut io.Writer
	StdErr io.Writer

	IsaTTY   bool //stdout is a tty
	IsErrTTY bool //stderr is a tty
	IsInTTY  bool //stdin is a tty
	// contains filtered or unexported fields
}

func IOTest

func IOTest() (*IOStreams, *bytes.Buffer, *bytes.Buffer, *bytes.Buffer)

func InitIOStream

func InitIOStream() *IOStreams

func (*IOStreams) ColorEnabled added in v1.12.0

func (s *IOStreams) ColorEnabled() bool

func (IOStreams) IsOutputTTY added in v1.13.0

func (s IOStreams) IsOutputTTY() bool

IsOutputTTY returns true if both stdout and stderr is TTY

func (*IOStreams) PromptEnabled

func (s *IOStreams) PromptEnabled() bool

func (*IOStreams) SetPager

func (s *IOStreams) SetPager(cmd string)

func (*IOStreams) SetPrompt

func (s *IOStreams) SetPrompt(promptDisabled string)

func (*IOStreams) StartPager

func (s *IOStreams) StartPager() error

func (*IOStreams) StopPager

func (s *IOStreams) StopPager()

func (*IOStreams) TerminalWidth added in v1.12.0

func (s *IOStreams) TerminalWidth() int

type ListTitleOptions

type ListTitleOptions struct {
	// Name of the List to be used in constructing Description and EmptyMessage if not provided.
	Name string
	// Page represents the page number of the current page
	Page int
	// CurrentPageTotal is the total number of items in current page
	CurrentPageTotal int
	// Total number of records. Default is the total number of rows.
	// Can be set to be greater than the total number of rows especially, if the list is paginated
	Total int
	// RepoName represents the name of the project or repository
	RepoName string
	// ListActionType should be either "search" or "list". Default is list
	ListActionType string
	// Optional. EmptyMessage to display when List is empty. If not provided, default one constructed from list Name.
	EmptyMessage string
}

func NewListTitle

func NewListTitle(listName string) ListTitleOptions

func (*ListTitleOptions) Describe

func (opts *ListTitleOptions) Describe() string

Jump to

Keyboard shortcuts

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