/
device.go
52 lines (40 loc) · 1.33 KB
/
device.go
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
46
47
48
49
50
51
52
package tty
import (
"gopheros/device/video/console"
"io"
)
const (
// DefaultScrollback defines the terminal scrollback in lines.
DefaultScrollback = 80
// DefaultTabWidth defines the number of spaces that tabs expand to.
DefaultTabWidth = 4
)
// State defines the supported terminal state values.
type State uint8
const (
// StateInactive marks the terminal as inactive. Any writes will be
// buffered and not synced to the attached console.
StateInactive State = iota
// StateActive marks the terminal as active. Any writes will be
// buffered and also synced to the attached console.
StateActive
)
// Device is implemented by objects that can be used as a terminal device.
type Device interface {
io.Writer
io.ByteWriter
// AttachTo connects a TTY to a console instance.
AttachTo(console.Device)
// State returns the TTY's state.
State() State
// SetState updates the TTY's state.
SetState(State)
// CursorPosition returns the current cursor x,y coordinates. Both
// coordinates are 1-based (top-left corner has coordinates 1,1).
CursorPosition() (uint32, uint32)
// SetCursorPosition sets the current cursor position to (x,y). Both
// coordinates are 1-based (top-left corner has coordinates 1,1).
// Implementations are expected to clip the cursor position to their
// viewport.
SetCursorPosition(x, y uint32)
}