terminal

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CursorHide = "\x1b[?25l"
	CursorShow = "\x1b[?25h"
	ClearLine  = "\r\x1b[K"
	CursorUp   = "\x1b[A"
	EraseDown  = "\x1b[J"
	SaveCursor = "\x1b[s"
	RestCursor = "\x1b[u"
)

ANSI escape sequences for terminal control.

Variables

This section is empty.

Functions

func MoveUp added in v0.11.0

func MoveUp(n int) string

MoveUp returns ANSI sequence to move cursor up n lines.

Types

type Key added in v0.7.0

type Key struct {
	Name    string // "up", "down", "left", "right", "return", "escape", "backspace", "delete", "space", "tab", "paste", or lowercase letter
	Rune    rune   // The actual character (0 for special keys)
	Ctrl    bool   // True if Ctrl modifier was pressed
	Shift   bool   // True if Shift modifier was pressed
	Content string // Paste content when Name == "paste"
}

Key represents a parsed keyboard input event.

type Reader

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

Reader provides read-only access to the key channel.

func (*Reader) On

func (r *Reader) On(event string, handler func(string, Key))

On registers a callback for key events (compatibility adapter) If a previous handler was registered, its consumer goroutine is stopped first.

func (*Reader) Read

func (r *Reader) Read(_ []byte) (int, error)

Reader methods.

type Terminal

type Terminal struct {
	Reader *Reader
	Writer *Writer
	// contains filtered or unexported fields
}

Terminal manages terminal I/O operations with channel-based key input.

func New

func New() (*Terminal, error)

New creates a new terminal instance and starts key reading. Uses a singleton pattern: the first call creates the TTY and readKeys goroutine, subsequent calls reuse the same terminal but create new Reader/Writer wrappers.

func (*Terminal) Keys added in v0.11.0

func (t *Terminal) Keys() <-chan Key

Keys returns the read-only key channel.

func (*Terminal) Write added in v0.11.0

func (t *Terminal) Write(b []byte) (int, error)

Write implements io.Writer.

type Writer

type Writer struct{}

Writer wraps stdout.

func (*Writer) Emit

func (w *Writer) Emit(_ string)

Emit triggers an event (no-op for compatibility).

func (*Writer) On

func (w *Writer) On(event string, handler func())

On registers a callback for terminal events.

func (*Writer) Write

func (w *Writer) Write(b []byte) (int, error)

Writer methods.

Jump to

Keyboard shortcuts

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