Documentation
¶
Overview ¶
Package input reads lines from stdin and enqueues them as user prompts.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsTerminal ¶
IsTerminal reports whether f is connected to a terminal (TTY). Returns false for pipes, redirected input, or if Stat fails.
Types ¶
type Mode ¶
type Mode struct {
// contains filtered or unexported fields
}
Mode is a state machine that manages modal input. In idle state, output streams freely and keystrokes are invisible. On the first printable byte, it transitions to composing: output pauses (via SwitchWriter), a styled "❯ " prompt appears, and subsequent bytes echo visibly. Enter submits the line, Escape cancels it, and both flush buffered output and resume streaming.
Long lines that exceed terminal width are truncated for display with an ellipsis prefix (…) while the full text is kept in the buffer. Terminal width is tracked via SetTermWidth to handle SIGWINCH events.
Mode is NOT thread-safe; all methods must be called from a single goroutine (the rawReader goroutine).
func NewMode ¶
func NewMode(sw *ui.SwitchWriter) *Mode
NewMode creates a Mode that controls the given SwitchWriter.
func (*Mode) Cancel ¶
func (m *Mode) Cancel()
Cancel discards the current input, clears the prompt, resets to idle, and resumes output streaming. Shows a brief "cancelled" message before clearing.
func (*Mode) ClearLine ¶
func (m *Mode) ClearLine()
ClearLine removes all text from the input line (Ctrl+U). If the line is already empty, cancels composing mode. If not composing, this is a no-op.
func (*Mode) DeleteWord ¶
func (m *Mode) DeleteWord()
DeleteWord removes the last word from the input line (Ctrl+W). Skips trailing whitespace, then deletes back to the previous whitespace boundary. If the line becomes empty, cancels composing mode. If not composing, this is a no-op.
func (*Mode) HandleBackspace ¶
func (m *Mode) HandleBackspace()
HandleBackspace removes the last UTF-8 rune from the input line. If the line becomes empty, a second backspace cancels composing mode entirely.
func (*Mode) HandleByte ¶
HandleByte processes a single byte of input. If idle, the first printable byte activates composing mode. In composing mode, bytes are appended to the input line and echoed via Direct write on the SwitchWriter. Bytes beyond maxLineLen are silently dropped.
When a byte is added and the line would exceed the terminal width, the entire line is redrawn with proper truncation instead of just echoing the new byte.
func (*Mode) IsComposing ¶
IsComposing reports whether the user is actively typing input.
func (*Mode) SetTermWidth ¶
SetTermWidth updates the terminal width. This is called when SIGWINCH is received.
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader reads lines from an io.Reader and enqueues non-empty lines. When backed by a terminal (via WithTerminal), it uses raw mode to suppress echo and prevent garbled output during streaming. When a Mode is provided (via WithMode), typing activates modal input with output buffering for a clean composing experience.
func NewReader ¶
NewReader creates a Reader that reads from source and enqueues into q. If output or stepInfo is nil, queue UI feedback is disabled.
func (*Reader) Start ¶
func (r *Reader) Start()
Start begins reading lines in a background goroutine. Returns immediately.
func (*Reader) Stop ¶
func (r *Reader) Stop()
Stop signals the reader to stop. The goroutine will exit after the current blocking read completes (e.g., on next newline or EOF). For os.Stdin, the goroutine may not exit until the process ends because Scan blocks on input. When using raw terminal mode, Stop restores terminal settings immediately even if the goroutine remains blocked on the current read.
type ReaderOption ¶
type ReaderOption func(*Reader)
ReaderOption configures optional Reader behavior.
func WithMode ¶
func WithMode(m *Mode) ReaderOption
WithMode enables modal input. When set, the first printable keystroke pauses output and shows an input prompt; Enter submits, Escape cancels.
func WithOutput ¶
func WithOutput(w io.Writer) ReaderOption
WithOutput sets the writer for queue UI display.
func WithStepInfo ¶
func WithStepInfo(info StepInfo) ReaderOption
WithStepInfo provides current step context for queue display.
func WithTerminal ¶
func WithTerminal(f *os.File) ReaderOption
WithTerminal enables raw terminal mode for the given file. When set, the reader suppresses terminal echo and reads character-by-character, preventing garbled output during streaming.