Documentation
¶
Index ¶
- Constants
- func CalculateOptimalWidth(cells [][]Cell) (max int)
- func CellsToBytesBuffer(buffer *bytes.Buffer, cells [][]Cell)
- func CellsToString(cells [][]Cell) string
- func CellsToStringBuilder(builder *strings.Builder, cells [][]Cell)
- func CloneCells(in [][]Cell) [][]Cell
- func Close()
- func ContextWithPayload(ctx context.Context, payload []byte) context.Context
- func CoordinatesBlockSort(from Coordinates, to Coordinates) (Coordinates, Coordinates)
- func CoordinatesInBounds(pos Coordinates, bounds Coordinates) bool
- func CoordinatesIntersection(startA, endA, startB, endB Coordinates) (intersectionStart Coordinates, intersectionEnd Coordinates, ok bool)
- func CoordinatesSort(from Coordinates, to Coordinates) (Coordinates, Coordinates)
- func CopyCells(dst [][]Cell, src [][]Cell) [][]Cell
- func Init() error
- func InterruptAt(ctx context.Context, interrupter Interrupter, fps int)
- func PayloadFromContext(ctx context.Context) ([]byte, bool)
- func Poll() <-chan tcell.Event
- func PublishBell()
- func PublishEvent(ev Event) bool
- func RingBell()
- func ScheduleNextTick(fn func()) bool
- func SetAttr(newattr Attributes)
- func SetCursorStyle(style CursorStyle)
- func Size() (width int, height int)
- func StringToCells(str string) (cells [][]Cell)
- type Attributes
- type Cell
- type Coordinates
- type CursorStyle
- type Event
- type EventType
- type InputMode
- type Interrupter
- type Key
- type KeyComb
- type Modifier
- type NoopWriter
- func (w NoopWriter) Clear(Attributes) (err error)
- func (w NoopWriter) Context() context.Context
- func (w NoopWriter) Flush() (err error)
- func (w NoopWriter) SetCell(pos Coordinates, cell Cell)
- func (w NoopWriter) SetCursor(pos Coordinates)
- func (w NoopWriter) UnionAttributes(pos Coordinates, attr Attributes)
- type Range
- type StringWriter
- func (w *StringWriter) Cells() []Cell
- func (w *StringWriter) Clear(attr Attributes) (err error)
- func (w *StringWriter) Context() context.Context
- func (w *StringWriter) Flush() (err error)
- func (w *StringWriter) Init(width, height int)
- func (w *StringWriter) Reset()
- func (w *StringWriter) Resize(width, height int)
- func (w *StringWriter) SetCell(pos Coordinates, cell Cell)
- func (w *StringWriter) SetCursor(pos Coordinates)
- func (w *StringWriter) String() string
- func (w *StringWriter) UnionAttributes(pos Coordinates, attr Attributes)
- type TermboxWriter
- func (w *TermboxWriter) Clear(attr Attributes) (err error)
- func (w *TermboxWriter) Context() context.Context
- func (w *TermboxWriter) Flush() error
- func (w *TermboxWriter) SetCell(pos Coordinates, c Cell)
- func (w *TermboxWriter) SetContext(ctx context.Context)
- func (w *TermboxWriter) SetCursor(pos Coordinates)
- func (w *TermboxWriter) UnionAttributes(pos Coordinates, attr Attributes)
- type Writer
Constants ¶
const ( // AttrVerticalRenderOffset instructs the renderer to render // the cell with an offset equal to half the height of the cell. AttrVerticalRenderOffset tcell.AttrMask = tcell.AttrInvalid << 1 // AttrNegativeVerticalRenderOffset instructs the renderer to render // the cell with an offset equal to minus half of the height of the cell. AttrNegativeVerticalRenderOffset tcell.AttrMask = tcell.AttrInvalid << 2 )
const ( CursorStyleDefault = CursorStyle(tcell.CursorStyleDefault) CursorStyleBlinkingBlock = CursorStyle(tcell.CursorStyleBlinkingBlock) CursorStyleSteadyBlock = CursorStyle(tcell.CursorStyleSteadyBlock) CursorStyleBlinkingUnderline = CursorStyle(tcell.CursorStyleBlinkingUnderline) CursorStyleSteadyUnderline = CursorStyle(tcell.CursorStyleSteadyUnderline) CursorStyleBlinkingBar = CursorStyle(tcell.CursorStyleBlinkingBar) CursorStyleSteadyBar = CursorStyle(tcell.CursorStyleSteadyBar) )
List of cursor styles.
const ( EventKey EventType = EventType(termbox.EventKey) EventResize = EventType(termbox.EventResize) EventMouse = EventType(termbox.EventMouse) EventError = EventType(termbox.EventError) EventInterrupt = EventType(termbox.EventInterrupt) EventRaw = EventType(termbox.EventRaw) EventNone = EventType(termbox.EventNone) EventPasteStart = EventType(termbox.EventPasteStart) EventPasteEnd = EventType(termbox.EventPasteEnd) EventFocus = EventType(termbox.EventFocus) EventUnfocus = EventType(termbox.EventUnfocus) )
Event type. See Event.Type field.
const ( KeyF1 Key = Key(termbox.KeyF1) KeyF2 = Key(termbox.KeyF2) KeyF3 = Key(termbox.KeyF3) KeyF4 = Key(termbox.KeyF4) KeyF5 = Key(termbox.KeyF5) KeyF6 = Key(termbox.KeyF6) KeyF7 = Key(termbox.KeyF7) KeyF8 = Key(termbox.KeyF8) KeyF9 = Key(termbox.KeyF9) KeyF10 = Key(termbox.KeyF10) KeyF11 = Key(termbox.KeyF11) KeyF12 = Key(termbox.KeyF12) KeyInsert = Key(termbox.KeyInsert) KeyDelete = Key(termbox.KeyDelete) KeyHome = Key(termbox.KeyHome) KeyEnd = Key(termbox.KeyEnd) KeyPgup = Key(termbox.KeyPgup) KeyPgdn = Key(termbox.KeyPgdn) KeyArrowUp = Key(termbox.KeyArrowUp) KeyArrowDown = Key(termbox.KeyArrowDown) KeyArrowLeft = Key(termbox.KeyArrowLeft) KeyArrowRight = Key(termbox.KeyArrowRight) MouseLeft = Key(termbox.MouseLeft) MouseMiddle = Key(termbox.MouseMiddle) MouseRight = Key(termbox.MouseRight) MouseRelease = Key(termbox.MouseRelease) MouseWheelUp = Key(termbox.MouseWheelUp) MouseWheelDown = Key(termbox.MouseWheelDown) KeyBackspace = Key(termbox.KeyBackspace2) KeyTab = Key(termbox.KeyTab) KeyEnter = Key(termbox.KeyEnter) KeyEsc = Key(termbox.KeyEsc) KeySpace = Key(termbox.KeySpace) )
List of keys.
const ( InputEsc InputMode = InputMode(termbox.InputEsc) InputAlt = InputMode(termbox.InputAlt) InputMouse = InputMode(termbox.InputMouse) InputCurrent = InputMode(termbox.InputCurrent) )
Input mode. See SetInputMode function.
const ( ModAlt Modifier = 1 << iota ModShift ModMeta ModCtrl ModCtrlShift = ModShift | ModCtrl ModCtrlAlt = ModCtrl | ModAlt ModCtrlMeta = ModCtrl | ModMeta ModCtrlShiftAlt = ModShift | ModAlt | ModCtrl ModCtrlShiftMeta = ModCtrl | ModShift | ModMeta ModCtrlAltMeta = ModCtrl | ModAlt | ModMeta ModShiftMeta = ModShift | ModMeta ModAltMeta = ModAlt | ModMeta ModAltShiftMeta = ModAlt | ModShift | ModMeta ModAltShift = ModAlt | ModShift )
Alt modifier constant, see Event.Mod field and SetInputMode function.
Variables ¶
This section is empty.
Functions ¶
func CalculateOptimalWidth ¶ added in v0.0.2
CalculateOptimalWidth calculates the width of this cells, such that nothing is truncated if rendered.
func CellsToBytesBuffer ¶ added in v0.0.2
CellsToBytesBuffer copies the bytes representation of the given cell matrix to the supplied buffer.
Caller is responsible for resetting buffer prior to this call if necessary.
func CellsToString ¶ added in v0.0.2
CellsToString returns the string representation of the given cell matrix.
func CellsToStringBuilder ¶ added in v0.0.2
CellsToStringBuilder copies the string representation of the given cell matrix to the supplied builder.
Caller is responsible for resetting builder prior to this call if necessary.
func CloneCells ¶ added in v0.0.2
CloneCells returns a deep clone of in.
func Close ¶
func Close()
Close writer; should be called after successful initialization when termbox's functionality isn't required anymore.
func ContextWithPayload ¶
ContextWithPayload returns a new Context that holds locker.
func CoordinatesBlockSort ¶
func CoordinatesBlockSort(from Coordinates, to Coordinates) ( Coordinates, Coordinates, )
CoordinatesBlockSort sorts a pair of coordinates (from/to) such that:
┌──────┐┌──────┐┌──────┐┌──────┐┌──────┐┌──────┐
│ f ││ t ││ f ││ t ││ t f ││ f t │
│ t ││ f ││ t ││ f ││ ││ │
└──────┘└──────┘└──────┘└──────┘└──────┘└──────┘
| | | | | |
v v v v v v
┌──────┐┌──────┐┌──────┐┌──────┐┌──────┐┌──────┐
│ f ││ f ││ f ││ f ││ f t ││ f t │
│ t ││ t ││ t ││ t ││ ││ │
└──────┘└──────┘└──────┘└──────┘└──────┘└──────┘
func CoordinatesInBounds ¶
func CoordinatesInBounds(pos Coordinates, bounds Coordinates) bool
CoordinatesInBounds returns true if the given position is within the given right-exclusive bounds.
func CoordinatesIntersection ¶
func CoordinatesIntersection( startA, endA, startB, endB Coordinates, ) (intersectionStart Coordinates, intersectionEnd Coordinates, ok bool)
CoordinatesIntersection calculates the intersection a ∩ b in a 2D space, defined as the set of all those cells which are common to both a and b. Both a and b are expected to be right-exclusive ranges.
┌──────┐ ┌──────┐ ┌──────┐ │ AA │ ∩ │ │ = │ │ │ │ │ BB │ │ │ └──────┘ └──────┘ └──────┘ ┌──────┐ ┌──────┐ ┌──────┐ │ AAAAA│ ∩ │ │ = │ │ │AAA │ │BBBBB │ │CCC │ └──────┘ └──────┘ └──────┘ ┌──────┐ ┌──────┐ ┌──────┐ │ BBBB│ ∩ │ │ = │ │ │BBB │ │AAAAA │ │CCC │ └──────┘ └──────┘ └──────┘ ┌──────┐ ┌──────┐ ┌──────┐ │ A│ ∩ │ │ = │ │ │AAAAAA│ │BBB │ │CCC │ └──────┘ └──────┘ └──────┘
func CoordinatesSort ¶
func CoordinatesSort(from Coordinates, to Coordinates) ( Coordinates, Coordinates, )
CoordinatesSort sorts a pair of coordinates (from/to) such that:
┌──────┐┌──────┐┌──────┐┌──────┐┌──────┐┌──────┐
│ f ││ t ││ f ││ t ││ t f ││ f t │
│ t ││ f ││ t ││ f ││ ││ │
└──────┘└──────┘└──────┘└──────┘└──────┘└──────┘
| | | | | |
v v v v v v
┌──────┐┌──────┐┌──────┐┌──────┐┌──────┐┌──────┐
│ f ││ f ││ f ││ f ││ f t ││ f t │
│ t ││ t ││ t ││ t ││ ││ │
└──────┘└──────┘└──────┘└──────┘└──────┘└──────┘
func CopyCells ¶ added in v0.0.2
CopyCells copies src into dst, re-using dst's capacity when possible.
func InterruptAt ¶
func InterruptAt(ctx context.Context, interrupter Interrupter, fps int)
InterruptAt interrupts the main event loop at the given fps, using the given interrupter. This function only returns when context is canceled.
func PayloadFromContext ¶
PayloadFromContext returns the payload value stored in ctx, if any.
func PublishBell ¶
func PublishBell()
PublishBell It's a shorthand for `ScheduleNextTick(RingBell)`.
func PublishEvent ¶
PublishEvent sends a synthetic event to the event poller. If the event queue is full then this method does not publish the event and returns false.
func RingBell ¶
func RingBell()
RingBell makes an audible noise. This must be synchronized against other accesses to the term.Writer's screen buffer.
func ScheduleNextTick ¶
func ScheduleNextTick(fn func()) bool
ScheduleNextTick schedules running fn on the next event-loop iteration.
func SetAttr ¶
func SetAttr(newattr Attributes)
SetAttr sets the global foreground and background attributes.
func SetCursorStyle ¶
func SetCursorStyle(style CursorStyle)
SetCursorStyle is used to set the cursor style. If the style is not supported (or cursor styles are not supported at all), then this will have no effect.
func StringToCells ¶ added in v0.0.2
StringToCells returns the cell matrix representation of the given string.
Types ¶
type Attributes ¶
Attributes represents a cell background and foreground attributes.
func AttributesDifference ¶
func AttributesDifference(a, b Attributes) Attributes
AttributesDifference computes the set difference between a and b, that is it returns a set of attributes that contain all the bit flags set in a but not set in b, and returns ColorDefault if a's color is equal to b's color or returns the color set in a.
func AttributesUnion ¶
func AttributesUnion(a, b Attributes) Attributes
AttributesUnion computes the set union between a and b, that is it returns a set of attributes that contain all the bit flags set in a, b or both, and uses the color defined in b or if not set, uses the color in a.
type Cell ¶
type Cell struct {
Attributes
// Ch is the main character held by this cell.
// If character cannot fit in the storage provided by the
// builtin 'rune', then Width() returns > 1 and Cell.Combining
// contains the rest of data.
Ch rune
// Combining are the remaining data that does not fit in Ch.
Combining []rune
// Width returns the monospace width of this Cell.
Width uint8
// Bytes is the number of bytes consumed by this Cell.
Bytes uint8
}
Cell represents a location with content on a terminal screen. 'Ch' is a unicode character, 'Fg' and 'Bg' are foreground and background attributes respectively. Unicode graphene clusters should be processed accordingly and stored into Ch and Combining fields.
type Coordinates ¶
type Coordinates struct {
X, Y int
}
Coordinates represent a point in a 2D space.
func CoordinatesDiff ¶
func CoordinatesDiff(a, b Coordinates) Coordinates
CoordinatesDiff subtracts a from b.
type CursorStyle ¶
type CursorStyle int
CursorStyle represents a given cursor style, which can include the shape and whether the cursor blinks or is solid. Support for changing this is not universal.
type Event ¶
type Event struct {
Type EventType // one of Event* constants
Mod Modifier // one of Mod* constants or 0
Key Key // one of Key* constants, invalid if 'Ch' is not 0
Ch rune // a unicode character
Width int // width of the screen
Height int // height of the screen
Err error // error in case if input failed
MouseX int // x coord of mouse
MouseY int // y coord of mouse
Raw []byte
UserFunc func()
Context context.Context
}
Event represents a terminal event. The 'Mod', 'Key' and 'Ch' fields are valid if 'Type' is EventKey. The 'Width' and 'Height' fields are valid if 'Type' is EventResize. The 'Err' field is valid if 'Type' is EventError.
func FromTcellEvent ¶
FromTcellEvent converts a tcell.Event into a term.Event.
type InputMode ¶
type InputMode int
InputMode is the keyboard input mode.
func SetInputMode ¶
SetInputMode sets termbox input mode. Termbox has two input modes:
1. Esc input mode. When ESC sequence is in the buffer and it doesn't match any known sequence. ESC means KeyEsc. This is the default input mode.
2. Alt input mode. When ESC sequence is in the buffer and it doesn't match any known sequence. ESC enables ModAlt modifier for the next keyboard event.
Both input modes can be OR'ed with Mouse mode. Setting Mouse mode bit up will enable mouse button press/release and drag events.
If 'mode' is InputCurrent, returns the current input mode. See also Input* constants.
type Interrupter ¶
Interrupter wraps the basic method Interrupt, which sends an interrupt event to the main loop, forcing a redraw of all components.
The given context is piped back into the next loop iteration so callers can use it to distinguish between an interrupt-driven call to Draw or just the next tick.
func FuncInterrupter ¶
func FuncInterrupter(fn func(context.Context) error) Interrupter
FuncInterrupter returns an Interrupter that calls fn every time Interrupt is called.
func NopInterrupter ¶
func NopInterrupter() Interrupter
NopInterrupter is an interrupter that does nothing when Interrupt is called.
type KeyComb ¶ added in v0.0.2
KeyComb represents is a key combination. See event for more details.
func ParseKey ¶ added in v0.0.3
ParseKey parses str into a KeyComb or returns error if it fails to parse it.
func (KeyComb) ShortString ¶ added in v0.0.3
ShortString returns the shorthand of the long string representation of this KeyComb.
type NoopWriter ¶
type NoopWriter struct{}
NoopWriter is a Writer that does nothing.
func (NoopWriter) Clear ¶
func (w NoopWriter) Clear(Attributes) (err error)
func (NoopWriter) Context ¶
func (w NoopWriter) Context() context.Context
func (NoopWriter) Flush ¶
func (w NoopWriter) Flush() (err error)
func (NoopWriter) SetCell ¶
func (w NoopWriter) SetCell(pos Coordinates, cell Cell)
func (NoopWriter) SetCursor ¶
func (w NoopWriter) SetCursor(pos Coordinates)
func (NoopWriter) UnionAttributes ¶
func (w NoopWriter) UnionAttributes(pos Coordinates, attr Attributes)
type Range ¶
type Range struct {
Start Coordinates
End Coordinates
}
Range is represents a selection in a 2D space.
func MergeRanges ¶
MergeRanges combines the given range slice, such that it returns the smallest set of ranges that is equivalent to the given set of ranges, by merging all intersecting ranges.
type StringWriter ¶
type StringWriter struct {
CursorCh rune
SetContext context.Context
BackgroundCh rune
ForegroundCh rune
// contains filtered or unexported fields
}
StringWriter satisfies Writer by rendering the cells into a plain string.
func NewStringWriter ¶
func NewStringWriter(width, height int) (t *StringWriter)
NewStringWriter allocates storage for a new StringWriter and initializes it.
func (*StringWriter) Cells ¶
func (w *StringWriter) Cells() []Cell
Cells returns the internal cell slice.
func (*StringWriter) Clear ¶
func (w *StringWriter) Clear(attr Attributes) (err error)
Clear satisfies Writer. Note that attr are ignored as they can't be represented in a string.
func (*StringWriter) Context ¶
func (w *StringWriter) Context() context.Context
Context returns context.Background
func (*StringWriter) Flush ¶
func (w *StringWriter) Flush() (err error)
Flush flushes the contents of this writer into the underlying cell buffer.
func (*StringWriter) Init ¶
func (w *StringWriter) Init(width, height int)
Init initializes this StringWriter with the given height and width.
func (*StringWriter) Resize ¶
func (w *StringWriter) Resize(width, height int)
Resize satisfies Writer.
func (*StringWriter) SetCell ¶
func (w *StringWriter) SetCell(pos Coordinates, cell Cell)
SetCell satisfies Writer.
func (*StringWriter) SetCursor ¶
func (w *StringWriter) SetCursor(pos Coordinates)
SetCursor satisfies Writer by substituting the rune at pos for a pre-defined cursor-like rune.
func (*StringWriter) String ¶
func (w *StringWriter) String() string
String returns the string representation of the contents of this Writer.
func (*StringWriter) UnionAttributes ¶
func (w *StringWriter) UnionAttributes(pos Coordinates, attr Attributes)
UnionAttributes satisfies Writer.
type TermboxWriter ¶
type TermboxWriter struct {
// contains filtered or unexported fields
}
TermboxWriter implements a termbox-like API using tcell/v3.
var ( // DefaultWriter returns the default global Writer. DefaultWriter *TermboxWriter = NewTermboxWriter() )
func NewTermboxWriter ¶
func NewTermboxWriter() *TermboxWriter
NewTermboxWriter allocates storage for a new TermboxWriter and initializes it.
func (*TermboxWriter) Clear ¶
func (w *TermboxWriter) Clear(attr Attributes) (err error)
Clear fills the screen with the given attributs and empty cells.
func (*TermboxWriter) Context ¶
func (w *TermboxWriter) Context() context.Context
Context satisfies term.Writer.
func (*TermboxWriter) Flush ¶
func (w *TermboxWriter) Flush() error
Flush makes all the content changes made using SetCell and UnionAttributes visible on the display.
func (*TermboxWriter) SetCell ¶
func (w *TermboxWriter) SetCell(pos Coordinates, c Cell)
SetCell satisfies term.Writer.
func (*TermboxWriter) SetContext ¶
func (w *TermboxWriter) SetContext(ctx context.Context)
SetContext sets the context for the next call to Context.
func (*TermboxWriter) SetCursor ¶
func (w *TermboxWriter) SetCursor(pos Coordinates)
SetCursor displays the terminal cursor at the given location.
func (*TermboxWriter) UnionAttributes ¶
func (w *TermboxWriter) UnionAttributes(pos Coordinates, attr Attributes)
UnionAttributes satisfies term.Writer.
type Writer ¶
type Writer interface {
// Context returns the current context of the Writer.
// This context can be used by tui.Components in combination
// with term.Interrupter.Interrupt(context.Context) to disambiguate
// regular calls to Draw from interrupt-driven calls to Draw.
Context() context.Context
// SetCell sets the contents of the given cell location. If
// the coordinates are out of range, then the operation is ignored.
SetCell(Coordinates, Cell)
// UnionAttributes computes the set union between a and b,
// that is overrides a set of attributes at the given coordinates
// that contain all the bit flags set in a, b or both, and uses the color
// defined in b or if not set, uses the color in a.
UnionAttributes(Coordinates, Attributes)
}
Writer abstracts termbox write functionality to decouple components from termbox, so they're easier to test.
func BoundsCheckWriter ¶ added in v0.0.2
BoundsCheckWriter returns a Writer which wraps w to make sure that calls to SetCell and SetCursor will never be out of the bounds defined by height or width.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package graphemecluster is a wrapper around uniseg to support non-standard characters that are otherwise not supported, like the ones found in nerd fonts.
|
Package graphemecluster is a wrapper around uniseg to support non-standard characters that are otherwise not supported, like the ones found in nerd fonts. |