Documentation
¶
Index ¶
- Constants
- Variables
- func GetArgAs[T, E any](m *Base[E]) (T, bool)
- type ArgType
- type Base
- func (m *Base[T]) AddArgTypeError(arg any, expectedType string)
- func (m *Base[T]) AddError(err error)
- func (m *Base[T]) Exec(model T) T
- func (m Base[T]) GetAliases() []string
- func (m Base[T]) GetCmdPaths() (paths []string)
- func (m Base[T]) GetId() int
- func (m Base[T]) GetName() string
- func (m Base[T]) GetStatus() Status
- func (m Base[T]) GetViewSize() (int, int)
- func (m Base[T]) IsActivePath(cmdPath string) bool
- func (m Base[T]) IsInitialized() bool
- func (m Base[T]) ParseCommand(cmdInput string) Status
- func (m *Base[T]) SetStatus(s Status)
- func (bc *Base[T]) Update(model T, msg tea.Msg) (T, tea.Cmd)
- func (bc *Base[T]) View(model T) string
- type Command
- type CommandData
- type HomeMsg
- type InputModel
- type InputOption
- type Interface
- type Status
- type StatusBarMsg
- type StatusSeverity
- type UpdateCmdMsg
- type ViewportSizeMsg
- type WindowSizeMsg
Constants ¶
const ( MsgMissingArgFuncErr = `` /* 185-byte string literal not displayed */ MsgIsCmdItselfErr = `` /* 697-byte string literal not displayed */ MsgUsingAliasInCmdPathErr = `` /* 580-byte string literal not displayed */ MsgDuplicateAliasErr = `` /* 134-byte string literal not displayed */ MsgInvalidHomeCmdPathErr = `` /* 236-byte string literal not displayed */ )
const ( ArgNone = ArgType(iota) ArgOptional ArgRequired )
const ( LOW = StatusSeverity(iota) MED HIGH )
Variables ¶
var ( ErrNotCommand = fmt.Errorf("unrecognized command") // Command is valid, but entered incorrectly ErrIncompleteCmd = fmt.Errorf("improper command entry") ErrMissingArgument = fmt.Errorf("missing argument") ErrEmptyCommand = fmt.Errorf("empty command") // Command is missing an execution path ErrUnimplementedCmd = fmt.Errorf("unimplemented command") ErrMisconfiguredArgParser = fmt.Errorf("command arg parsing is misconfigured") )
Functions ¶
func GetArgAs ¶
GetArgAs will try to cast a command argument to the specified type. Returns the argument of the command, cast to the specified type, along with true to indicate type-cast success. False will be returned if the type-case fails.
🔴 Failed type-casts are assumed to be catastrophic and will propagate an arg-type-error to the base view.
🟠 Retrieving an argument from a command that does not support arguments, is considered catastrophic and will propagate an error to the base view.
🟡 False will be returned for nil arguments, without error propagation; optional arguments can be nil.
Types ¶
type Base ¶
type Base[T any] struct { // contains filtered or unexported fields }
func NewBaseModel ¶
func NewBaseModel[T any](cmdData CommandData[T]) *Base[T]
func (*Base[T]) AddArgTypeError ¶
func (*Base[T]) Exec ¶
func (m *Base[T]) Exec(model T) T
Exec executes the current command path in the context of the passed model. All detected errors are logged and stored.
func (Base[T]) GetAliases ¶
func (Base[T]) GetCmdPaths ¶
func (Base[T]) GetViewSize ¶
func (Base[T]) IsActivePath ¶
func (Base[T]) IsInitialized ¶
IsInitialized checks to make sure that various expected values are set.
func (Base[T]) ParseCommand ¶
type Command ¶
type Command[T any] struct { // A list of words that execute a specific // command function, when entered into the // command input. Empty paths refer to // the command alias itself as a command. Path string // Executes the logic of the command, which // updates the command model. Run func(T) T // The main display function for the command. View func(T) string // Hides the command input, which relinquishes // keyboard control to the command. This is // necessary for commands which control the // UI using the keyboard. CaptureInput bool // The type of arguments that the command // requires. ArgNone is the default. // // ArgNone // ArgOptional // ArgRequired ArgType ArgType // Parses the argument passed to the command. // It should return a user-readable error // if it fails to parse. // // This function is required if the arg type // is NOT ArgNone. ParseArg func(arg string) (any, error) // contains filtered or unexported fields }
type CommandData ¶
type InputModel ¶
type InputModel struct {
// contains filtered or unexported fields
}
func NewInputModel ¶
func NewInputModel(h *utils.InputHistory, homePath string, cmdModels ...Interface) InputModel
TODO - Use an interface to define input history methods
func (InputModel) Init ¶
func (m InputModel) Init() tea.Cmd
func (InputModel) Update ¶
func (m InputModel) Update(msg tea.Msg) (InputModel, tea.Cmd)
func (InputModel) View ¶
func (m InputModel) View() string
type InputOption ¶
type InputOption func(*InputModel)
type StatusBarMsg ¶
type StatusBarMsg struct {
String string
Severity StatusSeverity
}
type StatusSeverity ¶
type StatusSeverity int
type UpdateCmdMsg ¶
type UpdateCmdMsg struct {
Model Interface
}