tty8

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: May 9, 2026 License: MIT Imports: 3 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Tty

type Tty struct {
	*tty.TTY
	// contains filtered or unexported fields
}

Tty is a wrapper around github.com/mattn/go-tty. While go-tty reads input per rune, control keys may be sent as multiple runes. To handle this, Tty buffers input and provides the GetKey method to retrieve keys per physical key press. It also replaces the terminal size notification mechanism from a channel of go-tty's WINSIZE to a callback function, making it easier to abstract single-character input handling.

func (*Tty) Close

func (tt *Tty) Close() (err error)

Close calls go-tty's `Close` method to shut down the Tty instance. It clears internal references (by overwriting them with nil) to prevent reuse. Since go-tty closes the SIGWINCH channel, the goroutine started by Open detects the channel closure and terminates automatically.

func (*Tty) GetKey

func (tt *Tty) GetKey() (key string, err error)

GetKey switches the terminal to raw mode and reads a single key input. Since control keys may consist of multiple runes, the result is returned as a string. Any unread input is buffered internally and returned on subsequent calls. After processing, the terminal is restored to cooked mode.

func (*Tty) IsOpen added in v0.7.0

func (tt *Tty) IsOpen() bool

func (*Tty) Open

func (tt *Tty) Open(onResize func(width, height int)) (err error)

Open calls go-tty's Open method to initialize the Tty instance. It also starts a goroutine that listens for terminal resize notifications. The goroutine receives events from go-tty's SIGWINCH channel and, if onResize is not nil, invokes the provided callback function.

Jump to

Keyboard shortcuts

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