ted/ui/driver.go

144 lines
2 KiB
Go
Raw Normal View History

// The UI driver. This is used to interact with the terminal drawing routines.
package ui
// The set of attributes a specific cell can have
2017-08-25 23:48:22 +00:00
type Attribute uint16
const (
2017-08-25 23:48:22 +00:00
// Can have only one of these
ColorDefault Attribute = iota
ColorBlack
ColorRed
ColorGreen
ColorYellow
ColorBlue
ColorMagenta
ColorCyan
ColorWhite
)
// and zero or more of these (combined using OR '|')
const (
2017-08-25 23:48:22 +00:00
AttrBold Attribute = 1 << (iota + 9)
AttrUnderline
AttrReverse
)
// Special keys
const (
2017-08-25 23:48:22 +00:00
KeyCtrlSpace rune = 0x8000 + iota
KeyCtrlA
KeyCtrlB
KeyCtrlC
KeyCtrlD
KeyCtrlE
KeyCtrlF
KeyCtrlG
KeyCtrlH
KeyCtrlI
KeyCtrlJ
KeyCtrlK
KeyCtrlL
KeyCtrlM
KeyCtrlN
KeyCtrlO
KeyCtrlP
KeyCtrlQ
KeyCtrlR
KeyCtrlS
KeyCtrlT
KeyCtrlU
KeyCtrlV
KeyCtrlW
KeyCtrlX
KeyCtrlY
KeyCtrlZ
KeyCtrl3
KeyCtrl4
KeyCtrl5
KeyCtrl6
KeyCtrl7
KeyCtrl8
KeyF1
KeyF2
KeyF3
KeyF4
KeyF5
KeyF6
KeyF7
KeyF8
KeyF9
KeyF10
KeyF11
KeyF12
KeyInsert
KeyDelete
KeyHome
KeyEnd
KeyPgup
KeyPgdn
KeyArrowUp
KeyArrowDown
KeyArrowLeft
KeyArrowRight
KeyBackspace = KeyCtrlH
KeyBackspace2
KeyEnter = KeyCtrlM
KeyEsc = KeyCtrl3
)
// The type of events supported by the driver
2017-08-25 23:48:22 +00:00
type EventType int
const (
2017-08-25 23:48:22 +00:00
EventNone EventType = iota
// Event when the window is resized
EventResize
// Event indicating a key press. The key is set in Ch and modifications
// are set in Or
EventKeyPress
)
const (
2017-08-25 23:48:22 +00:00
ModKeyAlt int = (1 << iota)
)
// Data from an event callback.
type Event struct {
2017-08-25 23:48:22 +00:00
Type EventType
Par int
Ch rune
}
// The terminal driver interface.
type Driver interface {
2017-08-25 23:48:22 +00:00
// Initializes the driver. Returns an error if there was an error
Init() error
// Closes the driver
Close()
2017-08-25 23:48:22 +00:00
// Returns the size of the window.
Size() (int, int)
2017-08-25 23:48:22 +00:00
// Sets the value of a specific cell
SetCell(x, y int, ch rune, fg, bg Attribute)
2017-08-25 23:48:22 +00:00
// Synchronizes the internal buffer with the real buffer
Sync()
2017-08-25 23:48:22 +00:00
// Wait for an event
WaitForEvent() Event
2017-08-25 23:48:22 +00:00
// Move the position of the cursor
SetCursor(x, y int)
2017-08-25 23:48:22 +00:00
// Hide the cursor
HideCursor()
}