input

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package input provides the user input subsystem for the TUI.

It integrates reeflective/readline as the line-editing backend and exposes a clean Reader API for the TUI main loop. Completion, multiline editing, and persistent history are all configured here.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CommandInfo

type CommandInfo struct {
	Name        string
	Aliases     []string
	Description string
}

CommandInfo describes a slash command for completion purposes.

type Completer

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

Completer provides tab-completion for the readline shell. It supports slash command completion and can be extended with additional completion sources.

func NewCompleter

func NewCompleter(commands []CommandInfo) *Completer

NewCompleter creates a new completer with the given command list.

func (*Completer) Complete

func (c *Completer) Complete(line []rune, cursor int) readline.Completions

Complete is the readline Completer function. It examines the current line and cursor position to produce relevant completions.

func (*Completer) SetCommands

func (c *Completer) SetCommands(commands []CommandInfo)

SetCommands updates the command list used for completion. This allows the command registry to be updated after the completer is created.

type Config

type Config struct {
	// Prompt is the primary prompt string (default: "> ").
	Prompt string

	// MultilinePrompt is shown on continuation lines (default: "· ").
	MultilinePrompt string

	// History configures persistent command history.
	History HistoryConfig
}

Config holds all configuration for the input Reader.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a Config with sensible defaults.

type HistoryConfig

type HistoryConfig struct {
	// FilePath overrides the default history file location.
	// If empty, defaults to $HOME/.echoctl_history.
	FilePath string

	// MaxEntries is the maximum number of history entries to keep.
	// Zero means unlimited.
	MaxEntries int
}

HistoryConfig holds options for the persistent command history.

type Reader

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

Reader wraps a reeflective/readline Shell to provide a high-level line-reading API for the TUI main loop.

It handles prompt rendering, multiline editing (Shift+Enter or trailing backslash), tab completion, and persistent history — all through a single [ReadLine] call.

func NewReader

func NewReader(cfg Config, commands []CommandInfo) (*Reader, error)

NewReader creates a new input Reader with the given configuration. The caller should call Reader.Close when done.

func (*Reader) Close

func (r *Reader) Close()

Close performs any cleanup needed by the Reader.

func (*Reader) ReadLine

func (r *Reader) ReadLine() (string, error)

ReadLine displays the prompt and reads one (possibly multi-line) user input. It returns the trimmed input string.

Errors:

func (*Reader) SetCommands

func (r *Reader) SetCommands(commands []CommandInfo)

SetCommands updates the slash-command list used by the completer.

func (*Reader) Shell

func (r *Reader) Shell() *readline.Shell

Shell returns the underlying readline shell for advanced configuration. Most callers should not need this.

Jump to

Keyboard shortcuts

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