Documentation
¶
Overview ¶
Package terminal provides low-level terminal state management.
It wraps golang.org/x/term to offer a clean lifecycle for raw mode, terminal size queries, and SIGWINCH resize handling. All terminal operations go through a single Terminal instance so that the rest of the TUI never touches raw ANSI escapes or os.Stdin.Fd() directly.
Index ¶
- type Terminal
- func (t *Terminal) Close()
- func (t *Terminal) EnterRawMode() error
- func (t *Terminal) Fd() int
- func (t *Terminal) Height() int
- func (t *Terminal) IsRaw() bool
- func (t *Terminal) ListenResize() (stop func())
- func (t *Terminal) OnResize(fn func(width, height int))
- func (t *Terminal) Restore()
- func (t *Terminal) Size() (width, height int)
- func (t *Terminal) Width() int
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Terminal ¶
type Terminal struct {
// contains filtered or unexported fields
}
Terminal manages the lifecycle of the controlling terminal.
It owns the file descriptor and the saved cooked-mode state, and provides goroutine-safe access to width/height. A single Terminal should be created at TUI startup and its [Close] method deferred.
func New ¶
New creates a Terminal for the given file (typically os.Stdin). It does NOT enter raw mode — call Terminal.EnterRawMode explicitly.
func (*Terminal) Close ¶
func (t *Terminal) Close()
Close is an alias for [Restore], suitable for use with defer.
func (*Terminal) EnterRawMode ¶
EnterRawMode switches the terminal to raw mode and saves the original state for later restoration. It is safe to call multiple times; only the first call takes effect.
func (*Terminal) ListenResize ¶
func (t *Terminal) ListenResize() (stop func())
ListenResize starts a goroutine that listens for SIGWINCH and refreshes the cached terminal size. Call the returned stop function to clean up the signal channel.
Typical usage:
stop := t.ListenResize() defer stop()
func (*Terminal) OnResize ¶
OnResize registers a callback that fires whenever the terminal size changes. Only one callback is supported — subsequent calls overwrite the previous one.
func (*Terminal) Restore ¶
func (t *Terminal) Restore()
Restore returns the terminal to its original (cooked) mode. It is safe to call multiple times or on an already-restored terminal.