utils

package
v0.0.0-...-1a052b4 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2015 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Argify

func Argify(data string) (string, []string)

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 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 Colorize

func Colorize(color Color, text string) string

Wraps the given text in the given color, followed by a color reset

func Compare

func Compare(str1, str2 string) bool

Case-insensitive string comparison

func FindAndCallMethod

func FindAndCallMethod(object interface{}, name string, a ...interface{}) bool

func FindMethod

func FindMethod(object interface{}, name string) (reflect.Value, bool)

FindMethod uses reflection to find an exported method with the given name on the given object. The reflect.Value is the value of the method that was found, such that Call be be invoked on it directly. The matching is case-inensitive. In order to be able to find methods that operate on the object pointer type, a pointer to an instance of an object should be given, rather than the object itself

func FormatName

func FormatName(name string) string

func GetRawUserInput

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

func GetRawUserInputP

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

func GetRawUserInputSuffix

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

func GetRawUserInputSuffixP

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

func GetUserInput

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

func GetUserInputP

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

func HandleError

func HandleError(err error)

func MonitorChannel

func MonitorChannel()

func NaturalLessThan

func NaturalLessThan(str1, str2 string) bool

func PanicIfError

func PanicIfError(err error)

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 ColorMode) (int, error)

func WriteLine

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

Types

type Color

type Color string
const (
	ColorRed     Color = "@0"
	ColorGreen   Color = "@1"
	ColorYellow  Color = "@2"
	ColorBlue    Color = "@3"
	ColorMagenta Color = "@4"
	ColorCyan    Color = "@5"
	ColorWhite   Color = "@6"

	ColorDarkRed     Color = "#0"
	ColorDarkGreen   Color = "#1"
	ColorDarkYellow  Color = "#2"
	ColorDarkBlue    Color = "#3"
	ColorDarkMagenta Color = "#4"
	ColorDarkCyan    Color = "#5"
	ColorBlack       Color = "#6"

	ColorGray   Color = "@@"
	ColorNormal Color = "##"
)

type ColorMode

type ColorMode int
const (
	ColorModeLight ColorMode = iota
	ColorModeDark  ColorMode = iota
	ColorModeNone  ColorMode = iota
)
type Menu struct {
	// contains filtered or unexported fields
}

func NewMenu

func NewMenu(text string) *Menu
func (self *Menu) AddAction(key string, text string)
func (self *Menu) AddActionData(key int, text string, data bson.ObjectId)
func (self *Menu) Exec(conn io.ReadWriter, cm ColorMode) (string, bson.ObjectId)
func (self *Menu) GetData(choice string) bson.ObjectId
func (self *Menu) GetPrompt() string
func (self *Menu) HasAction(key string) bool
func (self *Menu) Print(conn io.Writer, cm ColorMode)

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 SortableStrings

type SortableStrings []string

SortableStrings implements the sort.Interface for a []string. It uses "natural" sort order rather than asciibetical sort order.

func (SortableStrings) Len

func (s SortableStrings) Len() int

func (SortableStrings) Less

func (s SortableStrings) Less(i, j int) bool

func (SortableStrings) Swap

func (s SortableStrings) Swap(i, j 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)

Jump to

Keyboard shortcuts

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