Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CommandHandler ¶
type CommandHandler interface {
// HandleCommand is called when the user submits
// a command. It returns an iterator of responsive
// components to display as output.
HandleCommand(ctx context.Context, cmd Command) (
iterator.Iterator[component.Responsive], error,
)
// Complete returns tab completion candidates for
// the given command and arguments.
Complete(ctx context.Context, cmd string, args []string) (
iterator.Iterator[string], error,
)
}
CommandHandler dispatches commands and provides completions.
func FuncCommandHandler ¶
func FuncCommandHandler( fn func(context.Context, Command) (iterator.Iterator[component.Responsive], error), completer func(context.Context, string, []string) (iterator.Iterator[string], error), ) CommandHandler
FuncCommandHandler returns a CommandHandler that calls fn every time HandleCommand is invoked and completer when Complete is invoked.
func NopCommandCompleter ¶
func NopCommandCompleter( fn func(context.Context, Command) (iterator.Iterator[component.Responsive], error), ) CommandHandler
NopCommandCompleter returns a CommandHandler that calls fn every time HandleCommand is invoked, but does not have a completion function.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler is a read-eval-print loop handler that owns an output container (top) and an inputbox handler (bottom). It dispatches commands asynchronously via a CommandHandler and streams output into the container.
func New ¶
func New(cmd CommandHandler, opts ...Option) *Handler
New creates a new Handler with the given command handler and options.
func (*Handler) Cursor ¶
func (h *Handler) Cursor() (term.Coordinates, term.CursorStyle, bool)
Cursor satisfies tui.Handler.
type Option ¶
type Option func(*Handler)
Option configures a Handler.
func WithAttributes ¶
func WithAttributes(attr term.Attributes) Option
WithAttributes sets the display attributes.
func WithPrompt ¶
WithPrompt sets the prompt string displayed before each input line.
func WithStorage ¶
func WithStorage(key string, s storageapi.Service) Option
WithStorage sets the backing store for command history. Defaults to storagestub.NewInMemoryService().
func WithTabStyle ¶
WithTabStyle sets the tab completion style.