lib

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

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

Go to latest
Published: Jul 10, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const PARTIAL_CHAR = '>'

Variables

View Source
var UnfinishedValueErr = errors.New("unfinished quoted value")
View Source
var UnknownKeyStroke = errors.New("unknown keystroke")

Functions

func InsertRune

func InsertRune(input []rune, cursorpos int, newchr rune) []rune

func IsCountEqual

func IsCountEqual(a []string, b []string) bool

test if a and b are equal, whatever the order note that this function will sort a and b inplace

func IsSliceIntEqual

func IsSliceIntEqual(a, b []int) bool

func KeyStrokesToString

func KeyStrokesToString(ks []*KeyStroke) string

func Recover

func Recover(logger *Logger, cb func())

func RemoveRuneBackward

func RemoveRuneBackward(input []rune, cursorpos int) []rune

func RemoveRuneWordBackward

func RemoveRuneWordBackward(input []rune, cursorpos int) ([]rune, int)

Types

type Action

type Action func(machineContext interface{}, tr *Event)

type CmdArgs

type CmdArgs map[string]string

type Command

type Command struct {
	Partial bool
	Name    string
	Args    CmdArgs
}

func ParseCmd

func ParseCmd(userinput string) (*Command, error)

func (*Command) ToTrType

func (c *Command) ToTrType() TransitionType

type ConcurrentList

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

func NewConcurrentList

func NewConcurrentList(c []interface{}) *ConcurrentList

func (*ConcurrentList) Last

func (c *ConcurrentList) Last() interface{}

func (*ConcurrentList) Length

func (c *ConcurrentList) Length() int

func (*ConcurrentList) Push

func (c *ConcurrentList) Push(item interface{})

func (*ConcurrentList) Remove

func (c *ConcurrentList) Remove(toremove interface{})

type Event

type Event struct {
	Transition TransitionType
	Payload    interface{}
}

type KeyStroke

type KeyStroke struct {
	Key  tcell.Key
	Rune rune
	Tev  tcell.Event
}

func KeyStrokeFromEvent

func KeyStrokeFromEvent(ev tcell.Event) *KeyStroke

func ParseKeyStroke

func ParseKeyStroke(userinput string) ([]*KeyStroke, error)

func (*KeyStroke) String

func (k *KeyStroke) String() string

type Level

type Level int
const (
	DEBUG Level = iota + 1
	LOG
	WARN
	ERROR
)

func LogParseLevel

func LogParseLevel(lvl string) (Level, error)

func (Level) ToString

func (l Level) ToString() string

type Logger

type Logger struct {
	*log.Logger
	// contains filtered or unexported fields
}

func NewLogger

func NewLogger(level, output string) (*Logger, error)

func (*Logger) Debug

func (l *Logger) Debug(msg string, args ...interface{})

func (*Logger) Debugf

func (l *Logger) Debugf(msg string, args ...interface{})

func (*Logger) Error

func (l *Logger) Error(msg string, args ...interface{})

func (*Logger) Errorf

func (l *Logger) Errorf(msg string, args ...interface{})

func (*Logger) Log

func (l *Logger) Log(msg string, args ...interface{})

func (*Logger) Logf

func (l *Logger) Logf(msg string, args ...interface{})

func (*Logger) Warn

func (l *Logger) Warn(msg string, args ...interface{})

func (*Logger) Warnf

func (l *Logger) Warnf(msg string, args ...interface{})

type Machine

type Machine struct {
	// the extended state
	Context interface{}
	States  States

	Current StateType
	// contains filtered or unexported fields
}

func NewMachine

func NewMachine(ctx interface{}, initial StateType, states States) *Machine

func (*Machine) BuildEvent

func (m *Machine) BuildEvent(cmd string) (*Event, error)

func (*Machine) OffTransition

func (m *Machine) OffTransition(listenerId int)

func (*Machine) OnTransition

func (m *Machine) OnTransition(f StateListener) int

func (*Machine) Send

func (m *Machine) Send(ev *Event) bool

type State

type State struct {
	Entry       Action
	Exit        Action
	Transitions Transitions
}

type StateListener

type StateListener func(s StateType, machineContext interface{}, ev *Event)

type StateType

type StateType string

func (StateType) Matches

func (s StateType) Matches(other StateType) bool

type States

type States map[StateType]*State

type Transition

type Transition struct {
	Target StateType
	Action Action
}

type TransitionType

type TransitionType string

func (TransitionType) ToCmd

func (t TransitionType) ToCmd() string

type Transitions

type Transitions map[TransitionType]*Transition

Jump to

Keyboard shortcuts

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