1// termbox is a library for creating cross-platform text-based interfaces
2package termbox
3
4// public API, common OS agnostic part
5
6type (
7	InputMode  int
8	OutputMode int
9	EventType  uint8
10	Modifier   uint8
11	Key        uint16
12	Attribute  uint16
13)
14
15// This type represents a termbox event. The 'Mod', 'Key' and 'Ch' fields are
16// valid if 'Type' is EventKey. The 'Width' and 'Height' fields are valid if
17// 'Type' is EventResize. The 'Err' field is valid if 'Type' is EventError.
18type Event struct {
19	Type   EventType // one of Event* constants
20	Mod    Modifier  // one of Mod* constants or 0
21	Key    Key       // one of Key* constants, invalid if 'Ch' is not 0
22	Ch     rune      // a unicode character
23	Width  int       // width of the screen
24	Height int       // height of the screen
25	Err    error     // error in case if input failed
26	MouseX int       // x coord of mouse
27	MouseY int       // y coord of mouse
28	N      int       // number of bytes written when getting a raw event
29}
30
31// A cell, single conceptual entity on the screen. The screen is basically a 2d
32// array of cells. 'Ch' is a unicode character, 'Fg' and 'Bg' are foreground
33// and background attributes respectively.
34type Cell struct {
35	Ch rune
36	Fg Attribute
37	Bg Attribute
38}
39
40// To know if termbox has been initialized or not
41var (
42	IsInit bool = false
43)
44
45// Key constants, see Event.Key field.
46const (
47	KeyF1 Key = 0xFFFF - iota
48	KeyF2
49	KeyF3
50	KeyF4
51	KeyF5
52	KeyF6
53	KeyF7
54	KeyF8
55	KeyF9
56	KeyF10
57	KeyF11
58	KeyF12
59	KeyInsert
60	KeyDelete
61	KeyHome
62	KeyEnd
63	KeyPgup
64	KeyPgdn
65	KeyArrowUp
66	KeyArrowDown
67	KeyArrowLeft
68	KeyArrowRight
69	key_min // see terminfo
70	MouseLeft
71	MouseMiddle
72	MouseRight
73	MouseRelease
74	MouseWheelUp
75	MouseWheelDown
76)
77
78const (
79	KeyCtrlTilde      Key = 0x00
80	KeyCtrl2          Key = 0x00
81	KeyCtrlSpace      Key = 0x00
82	KeyCtrlA          Key = 0x01
83	KeyCtrlB          Key = 0x02
84	KeyCtrlC          Key = 0x03
85	KeyCtrlD          Key = 0x04
86	KeyCtrlE          Key = 0x05
87	KeyCtrlF          Key = 0x06
88	KeyCtrlG          Key = 0x07
89	KeyBackspace      Key = 0x08
90	KeyCtrlH          Key = 0x08
91	KeyTab            Key = 0x09
92	KeyCtrlI          Key = 0x09
93	KeyCtrlJ          Key = 0x0A
94	KeyCtrlK          Key = 0x0B
95	KeyCtrlL          Key = 0x0C
96	KeyEnter          Key = 0x0D
97	KeyCtrlM          Key = 0x0D
98	KeyCtrlN          Key = 0x0E
99	KeyCtrlO          Key = 0x0F
100	KeyCtrlP          Key = 0x10
101	KeyCtrlQ          Key = 0x11
102	KeyCtrlR          Key = 0x12
103	KeyCtrlS          Key = 0x13
104	KeyCtrlT          Key = 0x14
105	KeyCtrlU          Key = 0x15
106	KeyCtrlV          Key = 0x16
107	KeyCtrlW          Key = 0x17
108	KeyCtrlX          Key = 0x18
109	KeyCtrlY          Key = 0x19
110	KeyCtrlZ          Key = 0x1A
111	KeyEsc            Key = 0x1B
112	KeyCtrlLsqBracket Key = 0x1B
113	KeyCtrl3          Key = 0x1B
114	KeyCtrl4          Key = 0x1C
115	KeyCtrlBackslash  Key = 0x1C
116	KeyCtrl5          Key = 0x1D
117	KeyCtrlRsqBracket Key = 0x1D
118	KeyCtrl6          Key = 0x1E
119	KeyCtrl7          Key = 0x1F
120	KeyCtrlSlash      Key = 0x1F
121	KeyCtrlUnderscore Key = 0x1F
122	KeySpace          Key = 0x20
123	KeyBackspace2     Key = 0x7F
124	KeyCtrl8          Key = 0x7F
125)
126
127// Alt modifier constant, see Event.Mod field and SetInputMode function.
128const (
129	ModAlt Modifier = 1 << iota
130	ModMotion
131)
132
133// Cell colors, you can combine a color with multiple attributes using bitwise
134// OR ('|').
135const (
136	ColorDefault Attribute = iota
137	ColorBlack
138	ColorRed
139	ColorGreen
140	ColorYellow
141	ColorBlue
142	ColorMagenta
143	ColorCyan
144	ColorWhite
145)
146
147// Cell attributes, it is possible to use multiple attributes by combining them
148// using bitwise OR ('|'). Although, colors cannot be combined. But you can
149// combine attributes and a single color.
150//
151// It's worth mentioning that some platforms don't support certain attributes.
152// For example windows console doesn't support AttrUnderline. And on some
153// terminals applying AttrBold to background may result in blinking text. Use
154// them with caution and test your code on various terminals.
155const (
156	AttrBold Attribute = 1 << (iota + 9)
157	AttrUnderline
158	AttrReverse
159)
160
161// Input mode. See SetInputMode function.
162const (
163	InputEsc InputMode = 1 << iota
164	InputAlt
165	InputMouse
166	InputCurrent InputMode = 0
167)
168
169// Output mode. See SetOutputMode function.
170const (
171	OutputCurrent OutputMode = iota
172	OutputNormal
173	Output256
174	Output216
175	OutputGrayscale
176)
177
178// Event type. See Event.Type field.
179const (
180	EventKey EventType = iota
181	EventResize
182	EventMouse
183	EventError
184	EventInterrupt
185	EventRaw
186	EventNone
187)
188