gitstack

grindlemire/go-tui code browser

1.4 KB Go 45 lines 2026-03-15 · b5a15fd raw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package tui

import "time"

// EventReader reads events from the terminal.
// It is designed for polling-based event loops.
type EventReader interface {
	// PollEvent reads the next event with a timeout.
	// Returns (event, true) if an event was read, or (nil, false) on timeout.
	// A timeout of 0 performs a non-blocking check.
	// A negative timeout blocks indefinitely.
	PollEvent(timeout time.Duration) (Event, bool)

	// Close releases resources. Must be called when done.
	Close() error
}

// InterruptibleReader extends EventReader with the ability to be interrupted.
// This is used for blocking mode where PollEvent(-1) would otherwise block forever.
type InterruptibleReader interface {
	EventReader

	// EnableInterrupt sets up the interrupt mechanism (e.g., a self-pipe).
	// Must be called before using blocking mode.
	EnableInterrupt() error

	// Interrupt wakes up a blocking PollEvent call.
	// Safe to call even if not currently blocking.
	Interrupt() error
}

// PausableReader extends EventReader with the ability to temporarily pause
// stdin reads. While paused, PollEvent returns (nil, false) immediately.
// This is used to give exclusive stdin access to Kitty keyboard negotiation
// during suspend/resume.
type PausableReader interface {
	EventReader

	// Pause causes PollEvent to return immediately without reading stdin.
	// Interrupts any in-progress blocking read.
	Pause()

	// Resume allows PollEvent to read stdin again.
	Resume()
}