key

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Enable  = "\x1b[>1u\x1b[?2004h"
	Disable = "\x1b[?2004l\x1b[<u"
)

Enable turns the protocol and bracketed paste on, and Disable puts the terminal back.

Variables

This section is empty.

Functions

This section is empty.

Types

type Code

type Code int

Code is which key was pressed.

const (
	Rune Code = iota
	Enter
	Backspace
	Delete
	Left
	Right
	Up
	Down
	Home
	End
	Escape
	PasteStart
	PasteEnd
	Unknown
)

The keys a decoder reports.

type Decoder

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

Decoder reads keypresses off a terminal.

func NewDecoder

func NewDecoder(reader *bufio.Reader) *Decoder

NewDecoder builds a decoder over a buffered terminal.

func (*Decoder) Next

func (self *Decoder) Next() (Key, error)

Next blocks until a key is pressed.

type Key

type Key struct {
	Code  Code     // which key was pressed
	Value rune     // the typed character
	Mod   Modifier // which modifiers were held
}

Key is one keypress.

type Modifier

type Modifier int

Modifier is what was held down with the key.

const (
	Shift Modifier = 1 << iota
	Alt
	Ctrl
)

The modifiers a key can carry.

func (Modifier) Has

func (self Modifier) Has(mask Modifier) bool

Has says whether every modifier in the mask was held.

Jump to

Keyboard shortcuts

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