Documentation
¶
Overview ¶
Package twin provides Terminal Window interaction
Package twin provides Terminal Window interaction
Index ¶
- Variables
- type AttrMask
- type Cell
- type Color
- type ColorType
- type Event
- type EventKeyCode
- type EventMouse
- type EventResize
- type EventRune
- type FakeScreen
- func (screen *FakeScreen) Clear()
- func (screen *FakeScreen) Close()
- func (screen *FakeScreen) Events() chan Event
- func (screen *FakeScreen) GetRow(row int) []Cell
- func (screen *FakeScreen) SetCell(column int, row int, cell Cell)
- func (screen *FakeScreen) Show()
- func (screen *FakeScreen) ShowCursorAt(column int, row int)
- func (screen *FakeScreen) Size() (int, int)
- type KeyCode
- type MouseButtonMask
- type Screen
- type Style
- type UnixScreen
- func (screen *UnixScreen) Clear()
- func (screen *UnixScreen) Close()
- func (screen *UnixScreen) Events() chan Event
- func (screen *UnixScreen) SetCell(column int, row int, cell Cell)
- func (screen *UnixScreen) Show()
- func (screen *UnixScreen) ShowCursorAt(column int, row int)
- func (screen *UnixScreen) Size() (int, int)
Constants ¶
This section is empty.
Variables ¶
var ColorDefault = newColor(colorTypeDefault, 0)
Reset to default foreground / background color
var MOUSE_EVENT_REGEX = regexp.MustCompile("^\x1b\\[<([0-9]+);([0-9]+);([0-9]+)M")
Example event: "\x1b[<65;127;41M"
Where:
* "\x1b[<" says this is a mouse event
* "65" says this is Wheel Up. "64" would be Wheel Down.
* "127" is the column number on screen, "1" is the first column.
* "41" is the row number on screen, "1" is the first row.
* "M" marks the end of the mouse event.
Functions ¶
This section is empty.
Types ¶
type Color ¶
type Color uint32
Create using NewColor16(), NewColor256 or NewColor24Bit(), or use ColorDefault.
func NewColor16 ¶
Four bit colors as defined here: https://en.wikipedia.org/wiki/ANSI_escape_code#3-bit_and_4-bit
func NewColor256 ¶
func NewColorHex ¶
func (Color) BackgroundAnsiString ¶
func (Color) ForegroundAnsiString ¶
type EventKeyCode ¶
type EventKeyCode struct {
// contains filtered or unexported fields
}
func (*EventKeyCode) KeyCode ¶
func (eventKeyCode *EventKeyCode) KeyCode() KeyCode
type EventMouse ¶
type EventMouse struct {
// contains filtered or unexported fields
}
func (*EventMouse) Buttons ¶
func (eventMouse *EventMouse) Buttons() MouseButtonMask
type EventResize ¶
type EventResize struct { }
After you get this, query Screen.Size() to get the new size
type FakeScreen ¶
type FakeScreen struct {
// contains filtered or unexported fields
}
Used for testing.
Try GetRow() after some SetCell() calls to see what you got.
func NewFakeScreen ¶
func NewFakeScreen(width int, height int) *FakeScreen
func (*FakeScreen) Clear ¶
func (screen *FakeScreen) Clear()
func (*FakeScreen) Close ¶
func (screen *FakeScreen) Close()
func (*FakeScreen) Events ¶
func (screen *FakeScreen) Events() chan Event
func (*FakeScreen) GetRow ¶
func (screen *FakeScreen) GetRow(row int) []Cell
func (*FakeScreen) Show ¶
func (screen *FakeScreen) Show()
func (*FakeScreen) ShowCursorAt ¶
func (screen *FakeScreen) ShowCursorAt(column int, row int)
func (*FakeScreen) Size ¶
func (screen *FakeScreen) Size() (int, int)
type MouseButtonMask ¶
type MouseButtonMask uint16
const ( MouseWheelUp MouseButtonMask = 1 << iota MouseWheelDown MouseWheelLeft MouseWheelRight )
type Screen ¶
type Screen interface { // Close() restores terminal to normal state, must be called after you are // done with your screen Close() Clear() SetCell(column int, row int, cell Cell) // Render our contents into the terminal window Show() // Returns screen width and height. // // NOTE: Never cache this response! On window resizes you'll get an // EventResize on the Screen.Events channel, and this method will start // returning the new size instead. Size() (int, int) // ShowCursorAt() moves the cursor to the given screen position and makes // sure it is visible. // // If the position is outside of the screen, the cursor will be hidden. ShowCursorAt(column int, row int) // This channel is what your main loop should be checking. Events() chan Event }
type Style ¶
type Style struct {
// contains filtered or unexported fields
}
var StyleDefault Style
func (Style) Background ¶
func (Style) Foreground ¶
func (Style) RenderUpdateFrom ¶
Emit an ANSI escape sequence switching from a previous style to the current one.
func (Style) WithoutAttr ¶
type UnixScreen ¶
type UnixScreen struct {
// contains filtered or unexported fields
}
func (*UnixScreen) Clear ¶
func (screen *UnixScreen) Clear()
func (*UnixScreen) Close ¶
func (screen *UnixScreen) Close()
Close() restores terminal to normal state, must be called after you are done with the screen returned by NewScreen()
func (*UnixScreen) Events ¶
func (screen *UnixScreen) Events() chan Event
func (*UnixScreen) Show ¶
func (screen *UnixScreen) Show()
Render our contents into the terminal window
Note that we start by prepping everything we want to write, then write it all in one go. This is to make the screen update experience as atomic and flicker free as possible.
func (*UnixScreen) ShowCursorAt ¶
func (screen *UnixScreen) ShowCursorAt(column int, row int)
ShowCursorAt() moves the cursor to the given screen position and makes sure it is visible.
If the position is outside of the screen, the cursor will be hidden.
func (*UnixScreen) Size ¶
func (screen *UnixScreen) Size() (int, int)
Returns screen width and height.
NOTE: Never cache this response! On window resizes you'll get an EventResize on the Screen.Events channel, and this method will start returning the new size instead.