utils

package
v0.0.0-...-9c029b6 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2017 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs

func Abs(x int) int

func Argify

func Argify(data string) (string, string)

func Atoir

func Atoir(str string, min, max int) (int, error)

func Atois

func Atois(strings []string) ([]int, error)

func BestMatch

func BestMatch(pattern string, searchList []string) int

BestMatch searches the given list for the given pattern, the index of the longest match that starts with the given pattern is returned. Returns -1 if no match was found, -2 if the result is ambiguous. The search is case insensitive

func Bound

func Bound(x, lower, upper int) int

func ClearLine

func ClearLine(conn io.Writer)

ClearLine sends the VT100 code for erasing the line followed by a carriage return to move the cursor back to the beginning of the line

func Compare

func Compare(str1, str2 string) bool

Case-insensitive string comparison

func DirectionToExitString

func DirectionToExitString(direction types.Direction) string

func ExecMenu

func ExecMenu(title string, comm types.Communicable, build func(*Menu))

func Filter

func Filter(list []string, pattern string) []string

func FilterItem

func FilterItem(item, pattern string) bool

func FormatName

func FormatName(name string) string

func GetRawUserInput

func GetRawUserInput(conn io.ReadWriter, prompt string, cm types.ColorMode) string

func GetRawUserInputP

func GetRawUserInputP(conn io.ReadWriter, prompter Prompter, cm types.ColorMode) string

func GetRawUserInputSuffix

func GetRawUserInputSuffix(conn io.ReadWriter, prompt string, suffix string, cm types.ColorMode) string

func GetRawUserInputSuffixP

func GetRawUserInputSuffixP(conn io.ReadWriter, prompter Prompter, suffix string, cm types.ColorMode) string

func GetUserInput

func GetUserInput(conn io.ReadWriter, prompt string, cm types.ColorMode) string

func GetUserInputP

func GetUserInputP(conn io.ReadWriter, prompter Prompter, cm types.ColorMode) string

func HandleError

func HandleError(err error)

func Max

func Max(x, y int) int

func Min

func Min(x, y int) int

func MonitorChannel

func MonitorChannel()

func Paginate

func Paginate(list []string, width, height int) []string

func Random

func Random(low, high int) int

Random returns a random integer between low and high, inclusive

func Simplify

func Simplify(str string) string

func TrimEmptyRows

func TrimEmptyRows(str string) string

func TrimLowerRows

func TrimLowerRows(rows []string) []string

func TrimUpperRows

func TrimUpperRows(rows []string) []string

func ValidateName

func ValidateName(name string) error

func Write

func Write(conn io.Writer, text string, cm types.ColorMode)

func WriteLine

func WriteLine(conn io.Writer, line string, cm types.ColorMode)

Types

type Menu struct {
	// contains filtered or unexported fields
}
func (self *Menu) AddAction(key string, text string, handler func())
func (self *Menu) AddActionI(index int, text string, handler func())
func (self *Menu) Exit()
func (self *Menu) GetData(choice string) types.Id
func (self *Menu) HasAction(key string) bool
func (self *Menu) OnExit(handler func())
func (self *Menu) Print(comm types.Communicable, page int, filter string) int
func (self *Menu) SetTitle(title string)

type Prompter

type Prompter interface {
	GetPrompt() string
}

func SimplePrompter

func SimplePrompter(prompt string) Prompter

SimpleRompter returns a Prompter that always returns the given string as its prompt

type Set

type Set map[string]bool

func (Set) Contains

func (self Set) Contains(key string) bool

func (Set) Insert

func (self Set) Insert(key string)

func (Set) Remove

func (self Set) Remove(key string)

func (Set) Size

func (self Set) Size() int

type Throttler

type Throttler struct {
	// contains filtered or unexported fields
}

Throttler is a simple utility class that allows events to occur on a deterministic recurring basis. Every call to Sync() will block until the duration of the Throttler's interval has passed since the last call to Sync()

func NewThrottler

func NewThrottler(interval time.Duration) *Throttler

func (*Throttler) Sync

func (self *Throttler) Sync()

type WatchableReadWriter

type WatchableReadWriter struct {
	// contains filtered or unexported fields
}

func NewWatchableReadWriter

func NewWatchableReadWriter(rw io.ReadWriter) *WatchableReadWriter

func (*WatchableReadWriter) AddWatcher

func (w *WatchableReadWriter) AddWatcher(rw io.ReadWriter)

func (*WatchableReadWriter) Read

func (w *WatchableReadWriter) Read(p []byte) (int, error)

func (*WatchableReadWriter) RemoveWatcher

func (w *WatchableReadWriter) RemoveWatcher(rw io.ReadWriter)

func (*WatchableReadWriter) Write

func (w *WatchableReadWriter) Write(p []byte) (int, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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