terminalinput

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: Apache-2.0 Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package terminalinput configures byte-oriented local console input and observes terminal dimensions without owning remote terminal behavior.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MakeRaw

func MakeRaw(input io.Reader) (io.Reader, func() error, error)

MakeRaw disables local line editing, echo, and signal processing for an interactive input terminal. It returns the reader to use while raw mode is active and a function that restores the exact prior state.

The returned restore function must run exactly once on every exit path after MakeRaw succeeds. Non-terminal readers are unchanged and receive a no-op restore function.

func ReadLine added in v0.2.0

func ReadLine(ctx context.Context, input *os.File, output io.Writer, prompt string, secret bool) (value []byte, err error)

ReadLine reads one local terminal response, with optional echo suppression. It requires an actual terminal, restores its original mode on every exit, and supports Ctrl+C, EOF, backspace, and context cancellation. It starts no background input reader and does not consume bytes beyond the response. The caller owns and should clear the returned bytes when they are secret.

func WatchSize added in v0.2.0

func WatchSize(ctx context.Context, file *os.File, initial Size, resize func(cols, rows uint16) error) error

WatchSize synchronously forwards valid changes relative to the local initial measurement. It rechecks after subscribing to catch changes during connection setup. An unchanged local size preserves explicit initial remote dimensions. Linux/macOS use SIGWINCH; Windows polls without consuming console input events. Invalid or unavailable measurements are ignored until the next notification. ctx stops watching, but cannot interrupt an in-flight resize callback: callers must release its underlying I/O before joining WatchSize during shutdown.

Types

type Size added in v0.2.0

type Size struct {
	Columns uint16
	Rows    uint16
}

Size is a validated terminal width and height in character cells. Its zero value represents an unavailable initial measurement.

func ReadSize added in v0.2.0

func ReadSize(file *os.File) (Size, error)

ReadSize reads a terminal's visible dimensions without changing console mode. It rejects unavailable, zero, or oversized measurements before conversion to uint16. The caller retains ownership of file.

Jump to

Keyboard shortcuts

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