term

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Listen

func Listen(keys []string, ch chan<- KeyEvent, done <-chan struct{})

Listen reads single bytes from stdin and sends KeyEvents for recognized keys. It returns when done is closed, ctrl+c/ctrl+d is received, or stdin reaches EOF.

Note: the internal readLoop goroutine may outlive Listen because os.Stdin.Read is a blocking syscall with no cancellation mechanism. This is acceptable for a CLI tool where process exit reclaims all resources.

Types

type KeyEvent

type KeyEvent struct {
	Key string // non-empty if a recognized key was pressed
	EOF bool   // true on ctrl+d (stdin closed)
}

KeyEvent represents a keyboard input event.

type RawMode

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

RawMode manages terminal raw mode state.

func NewRawMode

func NewRawMode(fd int) *RawMode

NewRawMode creates a RawMode for the given file descriptor.

func (*RawMode) Enter

func (r *RawMode) Enter() error

Enter puts the terminal into raw mode.

func (*RawMode) Exit

func (r *RawMode) Exit() error

Exit restores the terminal to its previous state.

Jump to

Keyboard shortcuts

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