Documentation
¶
Overview ¶
Package keyboard provides raw keyboard input handling with escape sequence parsing. It handles VT100/ANSI escape sequences, UTF-8 characters, bracketed paste, and line assembly for terminal input.
Index ¶
- Constants
- type Handler
- func (h *Handler) DecodeMacOSOption() bool
- func (h *Handler) IsLineMode() bool
- func (h *Handler) IsRunning() bool
- func (h *Handler) ManagesTerminal() bool
- func (h *Handler) SetDecodeMacOSOption(enabled bool)
- func (h *Handler) SetEchoWriter(w io.Writer)
- func (h *Handler) SetLineMode(enabled bool)
- func (h *Handler) Start() error
- func (h *Handler) Stop() error
- type Options
- type PasteChunk
Constants ¶
const DefaultPasteChunkSize = 1024
DefaultPasteChunkSize is the default size for paste chunks (1KB)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Handler ¶ added in v0.2.1
type Handler struct {
// Output channels (plain Go channels)
Keys chan string // Parsed key events ("a", "M-a", "F1", etc.)
Lines chan []byte // Assembled lines
// Callbacks (optional, called in addition to channel sends)
OnKey func(key string) // Called on each key event
OnLine func(line []byte) // Called on each completed line
OnPaste func(content []byte) // Called on bracketed paste content (complete)
OnPasteChunk func(chunk PasteChunk) // Called on incremental paste chunks
// contains filtered or unexported fields
}
Handler handles raw keyboard input, parsing escape sequences and providing both key events and line assembly.
func (*Handler) DecodeMacOSOption ¶ added in v0.3.2
DecodeMacOSOption returns true if macOS Option character decoding is enabled.
func (*Handler) IsLineMode ¶ added in v0.2.1
IsLineMode returns true if line assembly mode is active.
func (*Handler) IsRunning ¶ added in v0.2.1
IsRunning returns true if the handler is currently running.
func (*Handler) ManagesTerminal ¶ added in v0.2.1
ManagesTerminal returns true if this handler is managing terminal raw mode.
func (*Handler) SetDecodeMacOSOption ¶ added in v0.3.2
SetDecodeMacOSOption enables or disables decoding of macOS Option+key Unicode characters to M-key notation (e.g., ∂ → M-d).
func (*Handler) SetEchoWriter ¶ added in v0.2.1
SetEchoWriter sets the writer for echoing typed characters.
func (*Handler) SetLineMode ¶ added in v0.2.1
SetLineMode enables or disables line assembly mode. When enabled, keys go to line assembly and completed lines are sent to Lines channel. When disabled, all keys go directly to Keys channel.
type Options ¶ added in v0.2.1
type Options struct {
// InputReader is the source of raw bytes (required)
InputReader io.Reader
// EchoWriter is where to echo typed characters during line mode (optional)
EchoWriter io.Writer
// KeyBufferSize is the size of the Keys channel buffer (default: 64)
KeyBufferSize int
// LineBufferSize is the size of the Lines channel buffer (default: 16)
LineBufferSize int
// PasteChunkSize is the size of chunks emitted during bracketed paste (default: 1024)
// Only used when OnPasteChunk callback is set
PasteChunkSize int
// DecodeMacOSOption enables decoding of macOS Option+key Unicode characters
// to M-key notation (e.g., ∂ → M-d, Ø → M-O). Default: true on Darwin, false otherwise
DecodeMacOSOption *bool
// DebugFn is called with debug messages (optional)
DebugFn func(string)
// ManageTerminal controls whether to put stdin in raw mode.
// Only applies if InputReader is os.Stdin and is a terminal.
// Default: true
ManageTerminal *bool
}
Options configures the Handler
type PasteChunk ¶ added in v0.3.1
type PasteChunk struct {
Content []byte // The chunk content
IsFinal bool // True if this is the final chunk
}
PasteChunk represents an incremental chunk of bracketed paste content