Documentation
¶
Index ¶
- Constants
- Variables
- 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 ColorNamesMatching(pred func(name string, c Color) bool) map[string]Color
- 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 GetColorNames() map[string]Color
- func InterruptAt(ctx context.Context, interrupter Interrupter, fps int)
- func MergeColorValues(m map[Color]int32)
- func PayloadFromContext(ctx context.Context) ([]byte, bool)
- 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 AttrMask
- type Attributes
- type Cell
- type Color
- 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 Screen
- type ScreenWriter
- func (w *ScreenWriter) Bell()
- func (w *ScreenWriter) Clear(attr Attributes) (err error)
- func (w *ScreenWriter) ClearInterruptPending()
- func (w *ScreenWriter) Context() context.Context
- func (w *ScreenWriter) Flush() error
- func (w *ScreenWriter) Poll() <-chan Event
- func (w *ScreenWriter) PublishEvent(ev Event) bool
- func (w *ScreenWriter) SetCell(pos Coordinates, c Cell)
- func (w *ScreenWriter) SetContext(ctx context.Context)
- func (w *ScreenWriter) SetCursor(pos Coordinates)
- func (w *ScreenWriter) SetCursorStyle(style CursorStyle)
- func (w *ScreenWriter) Size() (int, int)
- func (w *ScreenWriter) UnionAttributes(pos Coordinates, attr Attributes)
- 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 Style
- type TcellScreen
- func (a *TcellScreen) Close()
- func (a *TcellScreen) Fill(ch rune, style Style)
- func (a *TcellScreen) Poll() <-chan Event
- func (a *TcellScreen) PostEvent(ev Event) error
- func (a *TcellScreen) SetContent(x, y int, primary rune, combining []rune, width uint8, style Style)
- func (a *TcellScreen) SetCursorStyle(s CursorStyle)
- func (a *TcellScreen) UnionStyle(x, y int, style Style)
- type Writer
Constants ¶
const ( ColorBlack = ColorValid + Color(iota) ColorMaroon ColorGreen ColorOlive ColorPurple ColorTeal ColorSilver ColorGray ColorRed ColorLime ColorYellow ColorBlue ColorFuchsia ColorAqua ColorWhite )
Named palette colors. The low byte matches the ECMA-48 / XTerm palette index so that NewColor / GetColor lookups round-trip against the color-name table.
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) )
Supported 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 types. See Event.Type.
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) )
Keys and mouse-button pseudo-keys.
const ( InputEsc InputMode = InputMode(termbox.InputEsc) InputAlt = InputMode(termbox.InputAlt) InputMouse = InputMode(termbox.InputMouse) InputCurrent = InputMode(termbox.InputCurrent) )
Input modes (see SetInputMode).
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 )
Modifier bits (see Event.Mod and SetInputMode).
Variables ¶
var ErrEventQFull = tcell.ErrEventQFull
ErrEventQFull is returned from Screen.PostEvent when the underlying tcell event queue is full.
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 ColorNamesMatching ¶ added in v0.0.84
ColorNamesMatching returns a snapshot of the color-name table filtered by an optional predicate. When pred is nil all names are returned.
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 GetColorNames ¶ added in v0.0.84
GetColorNames returns a snapshot of the W3C color name table as term.Color values.
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 MergeColorValues ¶ added in v0.0.84
MergeColorValues adds or overwrites entries in the underlying tcell palette table and refreshes the term color-name lookup so subsequent GetColor calls observe the updates.
func PayloadFromContext ¶
PayloadFromContext returns the payload value stored in ctx, if any.
func PublishBell ¶
func PublishBell()
PublishBell schedules RingBell on the next event-loop iteration.
func PublishEvent ¶
PublishEvent sends a synthetic event to the process-wide event poller. Returns false when the queue is full.
func RingBell ¶
func RingBell()
RingBell makes an audible noise. Must be synchronised 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 sets the cursor style on the process-wide termbox screen. Has no effect when cursor styles are unsupported.
func StringToCells ¶ added in v0.0.2
StringToCells returns the cell matrix representation of the given string.
Types ¶
type AttrMask ¶ added in v0.0.84
type AttrMask uint16
AttrMask is a bitmask of text-rendering attributes (bold, italic, underline, ...). Bits 0..7 mirror the standard SGR attributes; the higher bits carry term-specific render flags.
const ( AttrBold AttrMask = 1 << iota // bit 0 AttrBlink // bit 1 AttrReverse // bit 2 AttrUnderline // bit 3 AttrDim // bit 4 AttrItalic // bit 5 AttrStrikeThrough // bit 6 AttrInvalid // bit 7 (sentinel) )
Standard SGR attribute bits (matching tcell's layout in the low 8 bits so cells round-trip through tcell-backed renderers cleanly).
const ( // AttrNone is the empty attribute set. AttrNone AttrMask = 0 // AttrVerticalRenderOffset instructs the renderer to render the // cell offset by +height/2. AttrVerticalRenderOffset AttrMask = AttrInvalid << 1 // bit 8 // AttrNegativeVerticalRenderOffset instructs the renderer to render // the cell offset by -height/2. AttrNegativeVerticalRenderOffset AttrMask = AttrInvalid << 2 // bit 9 )
func AttrMaskFromTcell ¶ added in v0.0.84
AttrMaskFromTcell converts a tcell.AttrMask into a term.AttrMask.
type Attributes ¶
Attributes represents a cell background, foreground and attribute bitmask. It is layout-compatible with term.Style; the duplicated type exists so Cell can embed it without growing.
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.
func (Attributes) Style ¶ added in v0.0.84
func (attr Attributes) Style() Style
Style returns attr as a term.Style. The values are layout-identical; the helper exists for callers that prefer the Style nominal type at the renderer boundary.
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
// Width returns the monospace width of this Cell.
Width uint8
// Bytes is the number of bytes consumed by this Cell.
Bytes uint8
// Combining holds the remaining grapheme-cluster codepoints that
// did not fit in Ch. nil when the cell has no combining marks
// (the common case).
Combining *[]rune
}
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 grapheme clusters whose codepoints do not fit in a single rune are stored across Ch and Combining (Combining is a pointer so the common no-combining-marks case costs 8 bytes instead of a 24-byte slice header).
func (Cell) CombiningRunes ¶ added in v0.0.84
CombiningRunes returns the combining-mark slice, or nil when the cell has no combining marks. Callers must not mutate the returned slice in place; allocate a new slice and assign via SetCombining.
func (*Cell) SetCombining ¶ added in v0.0.84
SetCombining replaces this cell's combining-mark slice. Pass nil to drop combining marks.
type Color ¶ added in v0.0.84
type Color uint32
Color represents a color packed into a 32-bit value. The low 24 bits hold the payload (palette index 0..255 or 24-bit RGB), the high byte holds the validity / kind flags ColorValid, ColorIsRGB, ColorSpecial.
The renderer boundary (term.Screen implementations) is responsible for translating Color into whatever the underlying display library expects. Helpers that bridge to the tcell library live in tcell.go alongside the TcellScreen adapter.
const ( // ColorDefault is the zero value; instructs the renderer to use // whatever color the underlying terminal considers default. ColorDefault Color = 0 // ColorValid marks a Color as initialised; without it Color is // treated as ColorDefault. ColorValid Color = 1 << 24 // ColorIsRGB indicates that the low 24 bits hold a 24-bit RGB value // rather than a palette index. ColorIsRGB Color = 1 << 25 // ColorSpecial flags a Color whose payload lives outside the normal // palette/RGB color space. ColorSpecial Color = 1 << 26 )
Flag bits live in the upper byte so the low 24 bits remain a usable palette/RGB payload.
func FromTcellColor ¶ added in v0.0.84
FromTcellColor converts a tcell.Color into the term.Color layout.
func GetColor ¶ added in v0.0.84
GetColor returns the Color for the given W3C name, or a hex literal of the form "#rrggbb". Returns ColorDefault if the name is unknown.
func NewColor ¶ added in v0.0.84
NewColor returns the named Color matching r, g, b if one exists, otherwise the RGB Color produced by NewRGBColor.
func NewHexColor ¶ added in v0.0.84
NewHexColor returns a Color whose payload is the given 24-bit RGB hex value.
func NewRGBColor ¶ added in v0.0.84
NewRGBColor returns a Color from r, g, b component values in 0..255.
func PaletteColor ¶ added in v0.0.84
PaletteColor returns the color for the given ECMA-48 / XTerm palette index (0..255).
func (Color) Hex ¶ added in v0.0.84
Hex returns c as a 24-bit RGB hex value, or -1 when c is not RGB.
func (Color) RGB ¶ added in v0.0.84
RGB returns the red, green, blue components of c, each in 0..255, or (-1, -1, -1) when c is not valid.
func (Color) String ¶ added in v0.0.84
String returns c as a "#rrggbb" hex literal, or "" when c is ColorDefault.
func (Color) Tcell ¶ added in v0.0.84
Tcell converts c into a tcell.Color suitable for handing to a tcell-backed renderer. The bit layout of tcell.Color differs from term.Color (tcell uses bits 32/33/34 for its flags); this method performs the translation.
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 cursor shape/blink combination. Support varies by terminal.
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.
type InputMode ¶
type InputMode int
InputMode is the keyboard input mode.
func SetInputMode ¶
SetInputMode sets termbox input mode. See InputMode constants for the available modes.
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 Screen ¶ added in v0.0.63
type Screen interface {
SetContent(x, y int, primary rune, combining []rune, width uint8, style Style)
UnionStyle(x, y int, style Style)
Fill(ch rune, style Style)
ShowCursor(x, y int)
HideCursor()
SetCursorStyle(CursorStyle)
Size() (int, int)
Show()
Poll() <-chan Event
PostEvent(Event) error
Bell()
}
Screen is the rendering surface used by rune-go-sdk's TUI event loop and ScreenWriter. It is intentionally tcell-free: tcell-backed renderers (termbox.Screen, gui/Screen, sshshop) adapt to this interface via dedicated adapters so callers never see tcell types through the SDK.
Screen intentionally omits lifecycle/setup methods (Init, Fini, EnablePaste, EnableFocus, EnableMouse, Tty); those are owned by the caller (term.Init for the default path, or the SSH/integration layer for callers that build their own Screen).
type ScreenWriter ¶ added in v0.0.73
type ScreenWriter struct {
// contains filtered or unexported fields
}
ScreenWriter implements term.Writer on top of a term.Screen. The writer is tcell-agnostic; tcell-backed screens are wrapped by a term.TcellScreen adapter so any color/style/event conversions happen at that boundary rather than here.
func NewDefaultWriter ¶ added in v0.0.73
func NewDefaultWriter() (*ScreenWriter, error)
NewDefaultWriter initializes the underlying terminal client with the default screen and writer.
func NewScreenWriter ¶ added in v0.0.76
func NewScreenWriter(scr Screen) *ScreenWriter
NewScreenWriter allocates storage for a new ScreenWriter. The returned writer has no Screen attached yet; it is the caller's responsibility to set one via SetScreen before the writer is used. term.Init() attaches the process-wide termbox screen to term.DefaultWriter, so that writer is ready to use after Init.
func (*ScreenWriter) Bell ¶ added in v0.0.73
func (w *ScreenWriter) Bell()
Bell rings the bell on this writer's screen.
func (*ScreenWriter) Clear ¶ added in v0.0.73
func (w *ScreenWriter) Clear(attr Attributes) (err error)
Clear fills the screen with the given attributes and empty cells.
func (*ScreenWriter) ClearInterruptPending ¶ added in v0.0.73
func (w *ScreenWriter) ClearInterruptPending()
ClearInterruptPending clears the coalesced-interrupt flag for this writer. The TUI event loop calls this after delivering an interrupt to the root handler so that the next payload-less interrupt is allowed through.
func (*ScreenWriter) Context ¶ added in v0.0.73
func (w *ScreenWriter) Context() context.Context
Context satisfies term.Writer.
func (*ScreenWriter) Flush ¶ added in v0.0.73
func (w *ScreenWriter) Flush() error
Flush makes all the content changes made using SetCell and UnionAttributes visible on the display.
func (*ScreenWriter) Poll ¶ added in v0.0.73
func (w *ScreenWriter) Poll() <-chan Event
Poll returns the underlying event channel of this writer's screen.
func (*ScreenWriter) PublishEvent ¶ added in v0.0.73
func (w *ScreenWriter) PublishEvent(ev Event) bool
PublishEvent posts the given term.Event onto this writer's screen event queue. Returns false if the queue is full. Does not support EventMouse, EventRaw or EventPaste events (these are silently ignored and true is returned, mirroring termbox.PublishEvent).
func (*ScreenWriter) SetCell ¶ added in v0.0.73
func (w *ScreenWriter) SetCell(pos Coordinates, c Cell)
SetCell satisfies term.Writer.
func (*ScreenWriter) SetContext ¶ added in v0.0.73
func (w *ScreenWriter) SetContext(ctx context.Context)
SetContext sets the context for the next call to Context.
func (*ScreenWriter) SetCursor ¶ added in v0.0.73
func (w *ScreenWriter) SetCursor(pos Coordinates)
SetCursor displays the terminal cursor at the given location.
func (*ScreenWriter) SetCursorStyle ¶ added in v0.0.73
func (w *ScreenWriter) SetCursorStyle(style CursorStyle)
SetCursorStyle sets the cursor style on this writer's screen.
func (*ScreenWriter) Size ¶ added in v0.0.73
func (w *ScreenWriter) Size() (int, int)
Size returns the size of this writer's screen.
func (*ScreenWriter) UnionAttributes ¶ added in v0.0.73
func (w *ScreenWriter) UnionAttributes(pos Coordinates, attr Attributes)
UnionAttributes satisfies term.Writer.
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 Style ¶ added in v0.0.84
Style is a foreground/background color pair plus an attribute mask. It is the renderer-facing companion of term.Attributes (which carries the same fields on a Cell).
var StyleDefault Style
StyleDefault is the zero-valued Style.
func StyleFromTcell ¶ added in v0.0.84
StyleFromTcell converts a tcell.Style into a term.Style.
type TcellScreen ¶ added in v0.0.84
type TcellScreen struct {
// contains filtered or unexported fields
}
TcellScreen adapts any tcell-shaped screen (tcell.Screen, the process termbox screen, simulation screens, GUI renderers, ...) to term.Screen. Color, style and event conversions happen here so the rest of the SDK and its consumers never see tcell types directly.
func NewTcellScreen ¶ added in v0.0.84
func NewTcellScreen(s tcell.Screen) *TcellScreen
NewTcellScreen returns a Screen adapter backed by s. The adapter owns a goroutine that translates tcell events into term events; it is released when the underlying tcell.Screen channel closes.
func NewTermboxScreen ¶ added in v0.0.84
func NewTermboxScreen() *TcellScreen
NewTermboxScreen returns a Screen adapter backed by the process termbox screen. Callers should ensure termbox.Init has been called before invoking this.
func (*TcellScreen) Close ¶ added in v0.0.84
func (a *TcellScreen) Close()
Close stops the event-translation goroutine. The underlying tcell screen is not finalised.
func (*TcellScreen) Fill ¶ added in v0.0.84
func (a *TcellScreen) Fill(ch rune, style Style)
Fill implements Screen.
func (*TcellScreen) Poll ¶ added in v0.0.84
func (a *TcellScreen) Poll() <-chan Event
Poll implements Screen.
func (*TcellScreen) PostEvent ¶ added in v0.0.84
func (a *TcellScreen) PostEvent(ev Event) error
PostEvent implements Screen. The event is translated to a tcell event and pushed onto the underlying screen's event queue.
func (*TcellScreen) SetContent ¶ added in v0.0.84
func (a *TcellScreen) SetContent(x, y int, primary rune, combining []rune, width uint8, style Style)
SetContent implements Screen.
func (*TcellScreen) SetCursorStyle ¶ added in v0.0.84
func (a *TcellScreen) SetCursorStyle(s CursorStyle)
SetCursorStyle implements Screen.
func (*TcellScreen) UnionStyle ¶ added in v0.0.84
func (a *TcellScreen) UnionStyle(x, y int, style Style)
UnionStyle implements Screen.
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. |