term

package
v0.0.98 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 16, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ColorBlack = ColorValid + Color(iota)
	ColorMaroon
	ColorGreen
	ColorOlive
	ColorNavy
	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.

View Source
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.

Event types. See Event.Type.

View Source
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.

Input modes (see SetInputMode).

View Source
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

View Source
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

func CalculateOptimalWidth(cells [][]Cell) (max int)

CalculateOptimalWidth calculates the width of this cells, such that nothing is truncated if rendered.

func CellsToBytesBuffer added in v0.0.2

func CellsToBytesBuffer(buffer *bytes.Buffer, cells [][]Cell)

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

func CellsToString(cells [][]Cell) string

CellsToString returns the string representation of the given cell matrix.

func CellsToStringBuilder added in v0.0.2

func CellsToStringBuilder(builder *strings.Builder, cells [][]Cell)

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

func CloneCells(in [][]Cell) [][]Cell

CloneCells returns a deep clone of in.

func Close

func Close()

Close releases the process-wide termbox screen.

func ColorNamesMatching added in v0.0.84

func ColorNamesMatching(pred func(name string, c Color) bool) map[string]Color

ColorNamesMatching returns a snapshot of the color-name table filtered by an optional predicate. When pred is nil all names are returned.

func ContextWithPayload

func ContextWithPayload(ctx context.Context, payload []byte) context.Context

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

func CopyCells(dst [][]Cell, src [][]Cell) [][]Cell

CopyCells copies src into dst, re-using dst's capacity when possible.

func GetColorNames added in v0.0.84

func GetColorNames() map[string]Color

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

func MergeColorValues(m map[Color]int32)

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

func PayloadFromContext(ctx context.Context) ([]byte, bool)

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

func PublishEvent(ev Event) bool

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 Size

func Size() (width int, height int)

Size returns the size of the terminal window.

func StringToCells added in v0.0.2

func StringToCells(str string) (cells [][]Cell)

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

func AttrMaskFromTcell(m tcell.AttrMask) AttrMask

AttrMaskFromTcell converts a tcell.AttrMask into a term.AttrMask.

type Attributes

type Attributes struct {
	Fg    Color
	Bg    Color
	Attrs AttrMask
}

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 Attr

func Attr() Attributes

Attr returns the global foreground and background 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.

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

func (c Cell) CombiningRunes() []rune

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

func (c *Cell) SetCombining(runes []rune)

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

func FromTcellColor(c tcell.Color) Color

FromTcellColor converts a tcell.Color into the term.Color layout.

func GetColor added in v0.0.84

func GetColor(name string) Color

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

func NewColor(r, g, b int32) Color

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

func NewHexColor(v int32) Color

NewHexColor returns a Color whose payload is the given 24-bit RGB hex value.

func NewRGBColor added in v0.0.84

func NewRGBColor(r, g, b int32) Color

NewRGBColor returns a Color from r, g, b component values in 0..255.

func PaletteColor added in v0.0.84

func PaletteColor(index int) Color

PaletteColor returns the color for the given ECMA-48 / XTerm palette index (0..255).

func (Color) CSS added in v0.0.84

func (c Color) CSS() string

CSS returns c as a CSS color string.

func (Color) Hex added in v0.0.84

func (c Color) Hex() int32

Hex returns c as a 24-bit RGB hex value, or -1 when c is not RGB.

func (Color) IsRGB added in v0.0.84

func (c Color) IsRGB() bool

IsRGB reports whether c carries an RGB payload.

func (Color) Name added in v0.0.84

func (c Color) Name(css ...bool) string

Name returns the W3C name for c, or "" when c is unnamed.

func (Color) RGB added in v0.0.84

func (c Color) RGB() (int32, int32, int32)

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

func (c Color) String() string

String returns c as a "#rrggbb" hex literal, or "" when c is ColorDefault.

func (Color) Tcell added in v0.0.84

func (c Color) Tcell() tcell.Color

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.

func (Color) TrueColor added in v0.0.84

func (c Color) TrueColor() Color

TrueColor returns c expanded to an RGB color, preserving its value when it is already RGB.

func (Color) Valid added in v0.0.84

func (c Color) Valid() bool

Valid reports whether c was initialised (i.e. has ColorValid set).

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.

func CoordinatesSum

func CoordinatesSum(a, b Coordinates) Coordinates

CoordinatesSum adds a to 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.

func PollEvent

func PollEvent() (ev Event)

PollEvent waits for an event and returns it. Blocking.

func (Event) KeyComb added in v0.0.2

func (e Event) KeyComb() KeyComb

KeyComb returns this event as a KeyComb, or panics if this event is not of type EventKey.

type EventType

type EventType uint8

EventType is the type of event being dispatched.

type InputMode

type InputMode int

InputMode is the keyboard input mode.

func SetInputMode

func SetInputMode(mode InputMode) InputMode

SetInputMode sets termbox input mode. See InputMode constants for the available modes.

type Interrupter

type Interrupter interface {
	Interrupt(context.Context) error
}

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 Key

type Key uint16

Key is a keyboard key.

const (
	KeyCapsLock   Key = 0xFF00
	KeyNumLock    Key = 0xFF01
	KeyScrollLock Key = 0xFF02
	KeyMenu       Key = 0xFF03
)

Physical keys that are never issued as term.Event but exist so they be re-mapped to other keys.

type KeyComb added in v0.0.2

type KeyComb struct {
	Mod Modifier
	Key Key
	Ch  rune
}

KeyComb represents is a key combination. See event for more details.

func ParseKey added in v0.0.3

func ParseKey(str string) (KeyComb, error)

ParseKey parses str into a KeyComb or returns error if it fails to parse it.

func ParseKeys added in v0.0.3

func ParseKeys(sequence string) (ret []KeyComb, err error)

ParseKeys parses the given sequence of key combinations.

func (KeyComb) ShortString added in v0.0.3

func (k KeyComb) ShortString() string

ShortString returns the shorthand of the long string representation of this KeyComb.

func (KeyComb) String added in v0.0.3

func (k KeyComb) String() string

String returns the long string representation of this KeyComb.

type Modifier

type Modifier uint8

Modifier is a key modifier like <alt> or <ctrl>.

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

func MergeRanges(ranges []Range) []Range

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) Reset

func (w *StringWriter) Reset()

Reset resets this writer.

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

type Style struct {
	Fg    Color
	Bg    Color
	Attrs AttrMask
}

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

func StyleFromTcell(s tcell.Style) Style

StyleFromTcell converts a tcell.Style into a term.Style.

func (Style) Tcell added in v0.0.84

func (s Style) Tcell() tcell.Style

Tcell returns s converted to a tcell.Style suitable for handing to a tcell-backed renderer.

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

func BoundsCheckWriter(width, height int, w Writer) Writer

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.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL