component

package
v0.0.49 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const DefaultAspectRatio = 16.0 / 9.0 * 5 / 2

DefaultAspectRatio returns an aspect ratio that looks like 16:9 in squared pixels Note that cells are not square, so this ratio compensates for that.

View Source
const (
	// MaxCols is the maximum number of available columns in a row.
	MaxCols = 12
)

Variables

This section is empty.

Functions

func Async added in v0.0.2

func Async[T tui.Component](
	interrupter term.Interrupter, placeholder T, fn func() (T, error),
) T

Async runs the given constructor in a separate goroutine and renders a placeholder until it returns and the returned component is installed.

Note that if Async's type parameter is an uknown flavor of tui.Component, it will panic. Only Responsive, Floating, WithAttributes are allowed. This design choice might feel un-ergonomic at first, but it's better to panic at the constructor than when SetAttr/Dimensions/Height panics at runtime because the underlying component doesn't implement them.

func BellowAnimationFrames added in v0.0.9

func BellowAnimationFrames() ([]string, []int)

BellowAnimationFrames returns the frames and sequence numbers of a bellow animation. It only needs 2 term.Cells in terms of width and 1 cell in height.

func CursorAnimationFrames added in v0.0.9

func CursorAnimationFrames() ([]string, []int)

CursorAnimationFrames returns the frames and sequence numbers of the default cursor animation. It only needs 1 term.Cells in terms of width and 1 cell in height.

func DrawFrame added in v0.0.2

func DrawFrame(
	w term.Writer, f FrameCharSet, attrs term.Attributes, limitX, limitY int,
)

DrawFrame draws a frame at 0, 0, limitX, limitY, with the given FrameCharSet.

func EncodeAnimation added in v0.0.9

func EncodeAnimation(a *Animation, width, height int) []byte

EncodeAnimation encodes the given Animation as a compressed slice of bytes that can be stored or transferred. If the underlying Animation's frames are dynamic components, then this is lost and encoded as a static string component, encoded with the given width and height.

func Grid added in v0.0.2

func Grid(matrix [][]tui.Component) tui.Component

Grid renders matrix as an equally sized grid of components. Note that each []tui.Component in matrix is treated as a row.

func IsAsyncContext added in v0.0.2

func IsAsyncContext(ctx context.Context) bool

IsAsyncContext determines if context belongs to an Async component interrupting.

func Nop added in v0.0.2

func Nop() tui.Component

Nop returns a Component that does nothing.

func ProgressAnimationFrames added in v0.0.9

func ProgressAnimationFrames() ([]string, []int)

ProgressAnimationFrames returns the frames and sequence numbers of the default progress animation. It only needs 2 term.Cells in terms of width and 1 cell in height.

func SpinningCircleAnimationFrames added in v0.0.9

func SpinningCircleAnimationFrames() ([]string, []int)

SpinningCircleAnimationFrames returns the frames and sequence numbers of the default progress animation. It only needs 2 term.Cells in terms of width and 1 cell in height.

func SpinningSquareAnimationFrames added in v0.0.9

func SpinningSquareAnimationFrames() ([]string, []int)

SpinningSquareAnimationFrames returns the frames and sequence numbers of a fun progress animation. It only needs 2 term.Cells in terms of width and 1 cell in height.

func Sync

func Sync(mu sync.Locker, c tui.Component) tui.Component

Sync wraps a tui.Component to provide access synchronization with mu.

func WithLogging added in v0.0.2

func WithLogging(comp tui.Component, logger func(string, ...any)) tui.Component

WithLogging wraps comp to log calls to Resize and Draw using the provided logger.

Types

type Alignment

type Alignment int

Alignment represents the content alignment.

const (
	// AlignmentLeft horizontally aligns content to the left.
	AlignmentLeft Alignment = 1 << iota
	// AlignmentRight horizontally aligns content to the right.
	AlignmentRight
	// AlignmentHorizontallyCentered horizontally aligns content to the center.
	AlignmentHorizontallyCentered
	// AlignmentTop vertically aligns content to the top.
	AlignmentTop
	// AlignmentBottom vertically aligns content to the bottom.
	AlignmentBottom
	// AlignmentVerticallyCentered vertically aligns content to center.
	AlignmentVerticallyCentered

	// AlignmentCentered vertically and horizontally aligns content to center.
	AlignmentCentered = AlignmentHorizontallyCentered | AlignmentVerticallyCentered
)

type Animation added in v0.0.9

type Animation struct {
	// contains filtered or unexported fields
}

Animation is a tui.Component that renders a series of frames on loop at the specified fps.

func DecodeAnimation added in v0.0.9

func DecodeAnimation(
	raw []byte, fps int,
	interrupter term.Interrupter,
) (*Animation, error)

DecodeAnimation decodes the given raw compressed animation into an Animation tui.Component. If raw is empty, an empty animation is returned. This method returns an error if raw is somehow corrupted or is missing data.

func NewAnimation added in v0.0.9

func NewAnimation(
	interrupter term.Interrupter,
	frames []string, sequence []int, fps int,
) *Animation

NewAnimation allocates storage for a new Animation and initializes it. See Init for more details.

func (*Animation) Close added in v0.0.9

func (a *Animation) Close() error

Close cleans all resources associated with this Animation.

func (*Animation) Draw added in v0.0.9

func (a *Animation) Draw(w term.Writer)

Draw satisfies tui.Component.

func (*Animation) Init added in v0.0.9

func (a *Animation) Init(
	interrupter term.Interrupter,
	frames []string, sequence []int, fps int,
)

Init initializes this animation with the given interrupter, frames, fps. It fires a goroutine which will call the given interrupter at the specified fps.

Close should be called to cleanup resources and stop the interrupt goroutine.

func (*Animation) InitWithComponents added in v0.0.9

func (a *Animation) InitWithComponents(
	ctx context.Context, interrupter term.Interrupter,
	frames []WithAttributes, sequence []int, fps int,
)

InitWithComponents initializes this animation with the given interrupter, frames as tui.Components, and fps. The given context is passed in calls to interrupter.Interrupt. See Init for more details.

func (*Animation) Resize added in v0.0.9

func (a *Animation) Resize(width, height int)

Resize satisfies tui.Component.

func (*Animation) SetAttr added in v0.0.9

func (a *Animation) SetAttr(attr term.Attributes) term.Attributes

SetAttr satisfies WithAttributes.

type AspectRatioFloatingResponsive added in v0.0.2

type AspectRatioFloatingResponsive struct {
	Responsive
	// contains filtered or unexported fields
}

AspectRatioFloatingResponsive wraps a Responsive component and satisfies Floating by using its Height method to find a width such that the resulting dimensions approximate a given aspect ratio.

func NewAspectRatioFloatingResponsive added in v0.0.2

func NewAspectRatioFloatingResponsive(responsive Responsive, aspectRatio float64) *AspectRatioFloatingResponsive

NewAspectRatioFloatingResponsive allocates storage for a new AspectRatioFloatingResponsive and initializes it.

func (*AspectRatioFloatingResponsive) Dimensions added in v0.0.2

func (r *AspectRatioFloatingResponsive) Dimensions() (width int, height int)

Dimensions satisfies Floating by using the underlying component's Height to find the set of dimensions that respect the instructed aspect ratio.

func (*AspectRatioFloatingResponsive) Init added in v0.0.2

func (r *AspectRatioFloatingResponsive) Init(responsive Responsive, aspectRatio float64)

Init initializes this AspectRatioFloatingResponsive with responsive and aspectRatio.

func (*AspectRatioFloatingResponsive) SetAttr added in v0.0.2

SetAttr satisfies WithAttributes, if the underlying Responsive satisfies WithAttributes, otherwise this method panics.

type Background added in v0.0.2

type Background struct {
	// contains filtered or unexported fields
}

Background represents a background Component. It wraps a tui.Component to make sure that all cells are reset to cell, before comp is drawn.

If cell.Ch is non-zero, then the Background overrides the underlying component's attributes in calls to SetCell such that cell.Bg and cell.Fg are always used.

func NewBackground added in v0.0.2

func NewBackground(comp tui.Component, cell term.Cell) *Background

NewBackground allocates storage for a new Background and initializes it.

func WithBackground added in v0.0.2

func WithBackground(comp tui.Component, cell term.Cell) *Background

WithBackground is deprecated. Use NewBackground instead.

func (*Background) Content added in v0.0.2

func (b *Background) Content() tui.Component

Content returns the inner component.

func (*Background) Dimensions added in v0.0.2

func (s *Background) Dimensions() (width, height int)

Dimensions satisfies Floating if underlying tui.Component satisfies Floating, or panics if it doesn't.

func (*Background) Draw added in v0.0.2

func (b *Background) Draw(w term.Writer)

Draw satisfies tui.Component

func (*Background) Height added in v0.0.2

func (s *Background) Height(width int) int

Height satisfies Responsive if underlying tui.Component satisfies Responsive, or panics if it doesn't.

func (*Background) Init added in v0.0.2

func (b *Background) Init(comp tui.Component, c term.Cell)

Init initializes this Background with comp and cell.

func (*Background) Resize added in v0.0.2

func (b *Background) Resize(width, height int)

Resize satisfies tui.Component

func (*Background) SetAttr added in v0.0.2

func (s *Background) SetAttr(attr term.Attributes) term.Attributes

SetAttr satisfies WithAttributes if underlying tui.Component satisfies WithAttributes, or panics if it doesn't.

type Container added in v0.0.2

type Container struct {
	// contains filtered or unexported fields
}

Container provides means to position components in a viewport, through a set of Rows that fill the available width and stack on top of each other. See Row for more details.

A zero-valued container is ready for use.

func NewContainer added in v0.0.2

func NewContainer() *Container

NewContainer allocates storage for a new container and initializes it.

func (*Container) AddRow added in v0.0.2

func (c *Container) AddRow() *Row

AddRow appends a row to this Container.

func (*Container) Dimensions added in v0.0.2

func (r *Container) Dimensions() (retWidth int, retHeight int)

Dimensions satisfies component.Floating. If underlying components do not satisfy component.Floating, then this method panics.

func (*Container) Draw added in v0.0.2

func (c *Container) Draw(w term.Writer)

Draw satisfies tui.Component.

func (*Container) Height added in v0.0.2

func (c *Container) Height(width int) (height int)

Height satisfies component.Responsive.

func (*Container) Resize added in v0.0.2

func (c *Container) Resize(width, height int)

Resize satisfies tui.Component.

func (*Container) ScrollDown added in v0.0.2

func (c *Container) ScrollDown() bool

ScrollDown scrolls the contents of this container down.

func (*Container) ScrollToBottom added in v0.0.24

func (c *Container) ScrollToBottom()

ScrollToBottom scrolls the contents of this container to the bottom.

func (*Container) ScrollUp added in v0.0.2

func (c *Container) ScrollUp() bool

ScrollUp scrolls the contents of this container up.

type Floating

type Floating interface {
	tui.Component
	Dimensions() (width int, height int)
}

Floating components are not in principle confined to a predetermined space and so are allowed certain degree of freedom. Dimensions should be used to indicate to parent components the desired dimensions, although it shouldn't be assumed that it will be respected.

func Inline added in v0.0.2

func Inline(components []Floating, alignment Alignment) Floating

Inline renders the given slice of components next to each other, occupying the maximum height of all the components but respecting each component's width. If there's overflow, then the overflowing components will be truncated at the opposite side of the Alignment.

func NopFloating added in v0.0.2

func NopFloating() Floating

NopFloating returns a Floating that does nothing.

func NopFloatingFromComponent added in v0.0.2

func NopFloatingFromComponent(c tui.Component) Floating

NopFloatingFromComponent wraps a Component to provide a Floating that does nothing.

func PaddedFloating

func PaddedFloating(f Floating, padx, pady int) Floating

PaddedFloating wraps a Floating component and adds a pre-determined amount of x axis and y axis padding.

func StaticFloating

func StaticFloating(c tui.Component, width, height int) Floating

StaticFloating wraps a tui.Component and returns a Floating that always return the same Dimensions values.

type FloatingReference added in v0.0.2

type FloatingReference struct {
	Reference
}

FloatingReference can be used to dynamically swap a component.Floating. If the underlying component.Floating is nil, then methods do nothing.

func NewFloatingReference added in v0.0.2

func NewFloatingReference(ref Floating) *FloatingReference

NewFloatingReference allocates storage for a new FloatingReference and initializes it with ref.

func (*FloatingReference) Dimensions added in v0.0.2

func (r *FloatingReference) Dimensions() (width, height int)

Dimensions satisfies Floating.

func (*FloatingReference) Init added in v0.0.2

func (r *FloatingReference) Init(ref Floating)

Init initializes this reference with ref. It can be used subsequently to override the underlying tui.Component reference.

type FloatingResponsive added in v0.0.2

type FloatingResponsive interface {
	Responsive
	Floating
}

FloatingResponsive is a Floating that also satisfies Responsive.

func NopFloatingFromResponsive added in v0.0.2

func NopFloatingFromResponsive(r Responsive) FloatingResponsive

NopFloatingFromResponsive wraps a Responsive to provide a FloatingResponsive that does nothing.

func NopFloatingResponsive added in v0.0.2

func NopFloatingResponsive() FloatingResponsive

NopFloatingResponsive returns a FloatingResponsive that does nothing.

func NopFloatingResponsiveFromComponent added in v0.0.2

func NopFloatingResponsiveFromComponent(c tui.Component) FloatingResponsive

NopFloatingResponsiveFromComponent wraps a Component to provide a FloatingResponsive that does nothing.

func NopResponsiveFromFloating added in v0.0.2

func NopResponsiveFromFloating(f Floating) FloatingResponsive

NopResponsiveFromFloating wraps a Floating to provide a FloatingResponsive that does nothing.

type FocusList added in v0.0.2

type FocusList struct {
	Inverted bool
	// contains filtered or unexported fields
}

FocusList wraps a List to provide an element Focus. It takes tui.Component components.

func NewFocusList added in v0.0.2

func NewFocusList() *FocusList

NewFocusList allocates storage for a new FocusList and initializes it.

func (*FocusList) Back added in v0.0.2

func (l *FocusList) Back() (ListNode, bool)

Back returns the last node of list l or nil if the list is empty.

func (*FocusList) CanFocusDown added in v0.0.2

func (l *FocusList) CanFocusDown() bool

CanFocusDown returns true if FocusDown would return true.

func (*FocusList) CanFocusUp added in v0.0.2

func (l *FocusList) CanFocusUp() bool

CanFocusUp returns true if FocusUp would return true.

func (*FocusList) Draw added in v0.0.2

func (l *FocusList) Draw(w term.Writer)

Draw satisfies tui.Component

func (*FocusList) ElementAt added in v0.0.2

func (l *FocusList) ElementAt(pos term.Coordinates) (ListNode, bool)

ElementAt returns the element at pos Coordinates or panics if coordinates are out of the bounds of this List.

func (*FocusList) ElementHeight added in v0.0.2

func (l *FocusList) ElementHeight() int

ElementHeight returns the height for each element of this list.

func (*FocusList) Focus added in v0.0.2

func (l *FocusList) Focus() (ListNode, bool)

Focus returns the current node in focus.

func (*FocusList) FocusDown added in v0.0.2

func (l *FocusList) FocusDown() bool

FocusDown sets the focus to the node after the current focus and returns true, or if the focus is already the last node, it does nothing and returns false.

func (*FocusList) FocusEnd added in v0.0.2

func (l *FocusList) FocusEnd() (ok bool)

FocusEnd sets the focus to the last node of l.

func (*FocusList) FocusOffset added in v0.0.2

func (l *FocusList) FocusOffset() int

FocusOffset returns this list's focus index in the underlying list.

func (*FocusList) FocusStart added in v0.0.2

func (l *FocusList) FocusStart() (ok bool)

FocusStart sets the focus to the first node of l.

func (*FocusList) FocusUp added in v0.0.2

func (l *FocusList) FocusUp() bool

FocusUp sets the focus to the node before the current focus and returns true, or if the focus is already the first node, it does nothing and returns false.

func (*FocusList) Front added in v0.0.2

func (l *FocusList) Front() (ListNode, bool)

Front returns the first node of list l or nil if the list is empty.

func (*FocusList) Init added in v0.0.2

func (l *FocusList) Init()

Init initializes this FocusList with the default element height of 1.

func (*FocusList) InitWithAttr added in v0.0.2

func (l *FocusList) InitWithAttr(text, focus term.Attributes)

InitWithAttr initializes this FocusList with the default element height of 1, and text as the text attributes and focus as the focus attributes.

func (*FocusList) Iterate added in v0.0.2

func (l *FocusList) Iterate(fn func(tui.Component))

Iterate iterates over all elements in l.

func (*FocusList) IterateVisible added in v0.0.2

func (l *FocusList) IterateVisible(fn func(tui.Component))

IterateVisible iterates only the visible elements in l.

func (*FocusList) Len added in v0.0.2

func (l *FocusList) Len() int

Len returns the number of nodes of list l in O(1).

func (*FocusList) Offset added in v0.0.2

func (l *FocusList) Offset() int

Offset returns this list's current seek offset.

func (*FocusList) PushBack added in v0.0.2

func (l *FocusList) PushBack(c tui.Component) ListNode

PushBack inserts a new element c at the back of list l and returns the linked node.

func (*FocusList) PushBackList added in v0.0.2

func (l *FocusList) PushBackList(other *FocusList)

PushBackList inserts a copy of an other list at the back of list l. The lists l and other must NOT be the same or nil.

func (*FocusList) PushFront added in v0.0.2

func (l *FocusList) PushFront(c tui.Component) ListNode

PushFront inserts a new element c with value v at the front of list l and returns e.

func (*FocusList) PushFrontList added in v0.0.2

func (l *FocusList) PushFrontList(other *FocusList)

PushFrontList inserts a copy of an other list at the front of list l. The lists l and other must NOT be the same or nil.

func (*FocusList) Remove added in v0.0.2

func (l *FocusList) Remove(n *ListNode) tui.Component

Remove removes a node.

func (*FocusList) Reset added in v0.0.2

func (l *FocusList) Reset()

Reset resets the contents of this FocusList.

func (*FocusList) Resize added in v0.0.2

func (l *FocusList) Resize(width, height int)

Resize satisfies tui.Component

func (*FocusList) SetElementHeight added in v0.0.2

func (l *FocusList) SetElementHeight(height int)

SetElementHeight sets the height for each element of this list.

func (*FocusList) SetFocus added in v0.0.2

func (l *FocusList) SetFocus(node ListNode)

SetFocus sets the focus of this FocusList to node.

func (*FocusList) SetFocusAttr added in v0.0.2

func (l *FocusList) SetFocusAttr(attr term.Attributes)

SetFocusAttr sets the attributes of the focus nodes. The current focus node is changed and any future focused nodes will inherit the given attr.

func (*FocusList) Sort added in v0.0.2

func (l *FocusList) Sort(less func(a, b tui.Component) bool)

Sort sorts the elements of this list with the provided less function. It also resets the current focus node, according to the Inverted property in FocusList.

type Frame added in v0.0.2

type Frame struct {
	FrameCharSet
	term.Attributes
	ScrollBarAttributes term.Attributes
	ScrollBarChar       rune
	// contains filtered or unexported fields
}

Frame is a Component that simply draws a border around a nested component. By default, uses FrameCharSetDefault() for the border characters.

Note that this component can achieve other effects (highlight, frame) by setting the right cell characters and/or attributes.

func NewFrame added in v0.0.2

func NewFrame(content tui.Component) (f *Frame)

NewFrame allocates storage and initializes a new frame with the given border attributes and underlying component.

func (*Frame) Content added in v0.0.2

func (f *Frame) Content() tui.Component

Content returns the underlying Component.

func (*Frame) ContentPosition added in v0.0.2

func (f *Frame) ContentPosition() term.Coordinates

ContentPosition returns the position of the content inside this frame.

func (*Frame) ContentSize added in v0.0.2

func (f *Frame) ContentSize() (int, int)

ContentSize returns the size and width of the inner content.

func (*Frame) Dimensions added in v0.0.2

func (f *Frame) Dimensions() (width, height int)

Dimensions satisfies Floating. If the underlying component is not a Floating component this method panics.

func (*Frame) Draw added in v0.0.2

func (f *Frame) Draw(w term.Writer)

Draw draws this frame's border and contents to the given Writer.

func (*Frame) Height added in v0.0.2

func (f *Frame) Height(width int) int

Height satisfies component.Responsive. It panics if underlying component is not component.Responsive.

func (*Frame) Init added in v0.0.2

func (f *Frame) Init(content tui.Component)

Init initializes this frame with the given Component and border attributes.

func (*Frame) Resize added in v0.0.2

func (f *Frame) Resize(width, height int)

Resize updates this frame with a new width and height. If width or height is smaller than 3 cells, the border will not be drawn.

func (*Frame) ScrollBar added in v0.0.2

func (f *Frame) ScrollBar() (pos term.Coordinates, height int, ok bool)

ScrollBar returns the position and height of the scrollbar, if a scroll bar is to be drawn, otherwise it returns false.

func (*Frame) SetAttr added in v0.0.2

func (f *Frame) SetAttr(attr term.Attributes) (ret term.Attributes)

SetAttr satisfies WithAttributes. This method only changes frame attr if underlying content does not satisfy WithAttributes.

func (*Frame) SetContent added in v0.0.2

func (f *Frame) SetContent(content tui.Component)

SetContent updates the underlying component and resizes it to conform to this frame's width and height.

func (*Frame) SetContentResize added in v0.0.2

func (f *Frame) SetContentResize(content tui.Component, resize bool)

SetContentResize allows clients to control whether content is resized during this method call.

type FrameCharSet added in v0.0.2

type FrameCharSet struct {
	TopLeft, TopRight               rune
	BottomLeft, BottomRight         rune
	HorizontalTop, VerticalLeft     rune
	HorizontalBottom, VerticalRight rune
}

FrameCharSet is a struct used to store the set of characters used to draw a frame.

Example characters (ASCII 9472-9580):

'─', '━', '│', '┃', '┄', '┅', '┆', '┇', '┈', '┉', '┊', '┋', '┌', '┍',

'┎', '┏', '┐', '┑', '┒', '┓', '└', '┕', '┖', '┗', '┘', '┙', '┚', '┛',

'├', '┝', '┞', '┟', '┠', '┡', '┢', '┣', '┤', '┥', '┦', '┧', '┨', '┩',

'┪', '┫', '┬', '┭', '┮', '┯', '┰', '┱', '┲', '┳', '┴', '┵', '┶', '┷',

'┸', '┹', '┺', '┻', '┼', '┽', '┾', '┿', '╀', '╁', '╂', '╃', '╄', '╅',

'╆', '╇', '╈', '╉', '╊', '╋', '╌', '╍', '╎', '╏', '═', '║', '╒', '╓',

'╔', '╕', '╖', '╗', '╘', '╙', '╚', '╛', '╜', '╝', '╞', '╟', '╠', '╡',

'╢', '╣', '╤', '╥', '╦', '╧', '╨', '╩'

func FrameCharSetDefault added in v0.0.2

func FrameCharSetDefault() FrameCharSet

FrameCharSetDefault returns the default FrameCharSet used across the library. It produces the following frame:

┌─┐
│ │
└─┘

func FrameCharSetHighlight added in v0.0.2

func FrameCharSetHighlight() FrameCharSet

FrameCharSetHighlight returns a charset that produces the following frame:

┏━┓
┃ ┃
┗━┛

func FrameCharSetStack added in v0.0.2

func FrameCharSetStack() FrameCharSet

FrameCharSetStack returns a charset that produces the following frame:

├─┤
│ │
├─┤

func FrameCharSetStackHead added in v0.0.2

func FrameCharSetStackHead() FrameCharSet

FrameCharSetStackHead returns a charset that produces the following frame:

┌─┐
│ │
├─┤

func FrameCharSetStackHeadHighlight added in v0.0.2

func FrameCharSetStackHeadHighlight() FrameCharSet

FrameCharSetStackHeadHighlight returns a charset that produces the following frame:

┏━┓
┃ ┃
┡━┩

func FrameCharSetStackHighlight added in v0.0.2

func FrameCharSetStackHighlight() FrameCharSet

FrameCharSetStackHighlight returns a charset that produces the following frame:

┢━┪
┃ ┃
┡━┩

func FrameCharSetStackTail added in v0.0.2

func FrameCharSetStackTail() FrameCharSet

FrameCharSetStackTail returns a charset that produces the following frame:

├─┤
│ │
└─┘

func FrameCharSetStackTailHighlight added in v0.0.2

func FrameCharSetStackTailHighlight() FrameCharSet

FrameCharSetStackTailHighlight returns a charset that produces the following frame:

┢━┪
┃ ┃
┗━┛

type FrameUnion added in v0.0.2

type FrameUnion struct {

	// Frame determines whether underlying components are an instance of Frame
	// and so FrameUnion should stitch them together with FrameUnionCharSet.
	// Default is true.
	Frame bool

	// Attributes to be set to FrameUnionCharSet.
	term.Attributes

	FrameUnionCharSet
	// contains filtered or unexported fields
}

FrameUnion is a tui.Component which Draws a main Component at the max available width and height, but otherwise depending on how many other statically sized components are stacked either left, right top or bottom.

It respects the stacked components height if stacked on top or bottom and it respects the stacked components width if stacked left or right. The API uses Virtual instead of tui.Component to determine what's the desired height or width.

func NewFrameUnion added in v0.0.2

func NewFrameUnion(main tui.Component) *FrameUnion

NewFrameUnion allocates storage for a new FrameUnion and initializes it.

func (*FrameUnion) ComponentAt added in v0.0.2

func (u *FrameUnion) ComponentAt(pos term.Coordinates) (Virtual[tui.Component], bool)

ComponentAt returns the component at pos or false if there's no component at pos.

func (*FrameUnion) Draw added in v0.0.2

func (u *FrameUnion) Draw(w term.Writer)

Draw satisfies tui.Component

func (*FrameUnion) Init added in v0.0.2

func (u *FrameUnion) Init(main tui.Component)

Init initializes this frame union with main as the main compontent.

func (*FrameUnion) MainHeight added in v0.0.2

func (u *FrameUnion) MainHeight() int

MainHeight returns the main component's height.

func (*FrameUnion) MainPosition added in v0.0.2

func (u *FrameUnion) MainPosition() (offset term.Coordinates)

MainPosition returns the main component's offset from the top-left corner.

func (*FrameUnion) MainWidth added in v0.0.2

func (u *FrameUnion) MainWidth() int

MainWidth returns the main component's width.

func (*FrameUnion) Resize added in v0.0.2

func (u *FrameUnion) Resize(width, height int)

Resize satisfies tui.Component

func (*FrameUnion) UnionBottom added in v0.0.2

func (u *FrameUnion) UnionBottom(bottom tui.Component, height int)

UnionBottom stacks bottom under of the main component. This method panics if bottom is nil.

func (*FrameUnion) UnionBottomFrame added in v0.0.2

func (u *FrameUnion) UnionBottomFrame(bottom tui.Component, height int, frame bool)

UnionBottomFrame stacks bottom under of the main component, and if u.Frame is set to true and the given frame argument too, it will union the frames of the adjacent components with the configured union charset. This method panics if bottom is nil.

func (*FrameUnion) UnionLeft added in v0.0.2

func (u *FrameUnion) UnionLeft(left tui.Component, width int)

UnionLeft stacks left to the left of the main component. This method panics if left is nil.

func (*FrameUnion) UnionLeftFrame added in v0.0.2

func (u *FrameUnion) UnionLeftFrame(left tui.Component, width int, frame bool)

UnionLeftFrame stacks left to the left of the main component, and if u.Frame is set to true and the given frame argument too, it will union the frames of the adjacent components with the configured union charset. This method panics if left is nil.

func (*FrameUnion) UnionRight added in v0.0.2

func (u *FrameUnion) UnionRight(right tui.Component, width int)

UnionRight stacks right to the right of the main component. This method panics if right is nil.

func (*FrameUnion) UnionRightFrame added in v0.0.2

func (u *FrameUnion) UnionRightFrame(right tui.Component, width int, frame bool)

UnionRightFrame stacks right to the right of the main component, and if u.Frame is set to true and the given frame argument too, it will union the frames of the adjacent components with the configured union charset. This method panics if right is nil.

func (*FrameUnion) UnionTop added in v0.0.2

func (u *FrameUnion) UnionTop(top tui.Component, height int)

UnionTop stacks top on top of the main component. This method panics if top is nil.

func (*FrameUnion) UnionTopFrame added in v0.0.2

func (u *FrameUnion) UnionTopFrame(top tui.Component, height int, frame bool)

UnionTopFrame stacks top on top of the main component, and if u.Frame is set to true and the given frame argument too, it will union the frames of the adjacent components with the configured union charset. This method panics if top is nil.

type FrameUnionCharSet added in v0.0.2

type FrameUnionCharSet struct {
	FrameCharSet
	Left   rune
	Right  rune
	Top    rune
	Bottom rune
}

FrameUnionCharSet configures the characters used to draw the frame union between the top and bottom components.

func DefaultFrameUnionCharSet added in v0.0.2

func DefaultFrameUnionCharSet() (ret FrameUnionCharSet)

DefaultFrameUnionCharSet returns the default FrameUnionCharSet used.

type LazyBytes added in v0.0.2

type LazyBytes struct {
	Data            []byte
	Tokens          *[]int
	Attributes      term.Attributes
	TokenAttributes term.Attributes
}

LazyBytes is an immutable String component that is allocation free until the first call to Draw.

Akin to String, it compacts string into one line and but it takes data as a slice of bytes and a set of x positions to apply TokenAttributes to. In contrast, SetAttr it's a O(n) rather than String's O(1), so do not call it for every string after they have been drawn once, otherwise just use String, which will offer better features and performance characteristics.

It should be wrapped by a Virtual component or used with a term.Writer to handle out of bound calls to SetCell.

It is useful for collections, where not all strings need to be drawn and there's a clear performance requirement that offsets its limitations.

Note that grapheme clusters are not supported by this component.

func (LazyBytes) Draw added in v0.0.2

func (l LazyBytes) Draw(w term.Writer)

Draw satisfies tui.Component.

func (LazyBytes) Resize added in v0.0.2

func (l LazyBytes) Resize(width, height int)

Resize is ignored.

type List added in v0.0.2

type List struct {
	// contains filtered or unexported fields
}

List satisfies tui.Component by drawing a set of children components with a fixed height and a width that's equal to the maximum width available for this component.

The height of the components can be set via the constructors and it can be modified later with SetElementHeight.

func NewList added in v0.0.2

func NewList(elementHeight int) (l *List)

NewList allocates storage for a new List and initializes it.

func (*List) Back added in v0.0.2

func (l *List) Back() (ListNode, bool)

Back returns the last node of list l or false if the list is empty.

func (*List) CanSeekDown added in v0.0.2

func (l *List) CanSeekDown() bool

CanSeekDown returns whether SeekUp would seek one row down.

func (*List) CanSeekUp added in v0.0.2

func (l *List) CanSeekUp() bool

CanSeekUp returns whether SeekUp would seek one row up.

func (*List) Draw added in v0.0.2

func (l *List) Draw(w term.Writer)

Draw draws this list's elements with the current seek offset.

func (*List) ElementAt added in v0.0.2

func (l *List) ElementAt(pos term.Coordinates) (ListNode, bool)

ElementAt returns the element at pos Coordinates or panics if coordinates are out of the bounds of this List.

func (*List) ElementHeight added in v0.0.2

func (l *List) ElementHeight() int

ElementHeight returns the height for each element of this list.

func (*List) Front added in v0.0.2

func (l *List) Front() (ListNode, bool)

Front returns the first node of list l or false if the list is empty.

func (*List) Head added in v0.0.2

func (l *List) Head() (ListNode, bool)

Head returns the first node of list l, starting at the current seek offset or false if the list is empty.

func (*List) Height added in v0.0.2

func (l *List) Height() int

Height returns the height of this List, in the last call to Resize.

func (*List) Init added in v0.0.2

func (l *List) Init(elementHeight int)

Init initializes this List.

func (*List) InsertAfter added in v0.0.2

func (l *List) InsertAfter(c tui.Component, mark ListNode) ListNode

InsertAfter inserts a new element c immediately after mark and returns the linked node. If mark is not an element of l, the list is not modified.

func (*List) InsertBefore added in v0.0.2

func (l *List) InsertBefore(c tui.Component, mark ListNode) ListNode

InsertBefore inserts a new element c immediately before mark and returns the linked node. If mark is not an element of l, the list is not modified.

func (*List) Len added in v0.0.2

func (l *List) Len() int

Len returns the number of nodes of list l in O(1).

func (*List) MaxOffset added in v0.0.2

func (l *List) MaxOffset() int

MaxOffset returns this list's max seek offset.

func (*List) Offset added in v0.0.2

func (l *List) Offset() int

Offset returns this list's current seek offset.

func (*List) PushBack added in v0.0.2

func (l *List) PushBack(c tui.Component) ListNode

PushBack inserts a new element c at the back of list l and returns the linked node.

func (*List) PushBackList added in v0.0.2

func (l *List) PushBackList(other *List)

PushBackList inserts a copy of an other list at the back of list l. The lists l and other must NOT be the same or nil.

func (*List) PushFront added in v0.0.2

func (l *List) PushFront(c tui.Component) ListNode

PushFront inserts a new element c at the front of list l and returns the linked node.

func (*List) PushFrontList added in v0.0.2

func (l *List) PushFrontList(other *List)

PushFrontList inserts a copy of an other list at the front of list l. The lists l and other must NOT be the same or nil.

func (*List) Remove added in v0.0.2

func (l *List) Remove(e *ListNode) tui.Component

Remove removes e from l if e is a node of list l. It returns the element value e.Value.

func (*List) Reset added in v0.0.2

func (l *List) Reset()

Reset resets the contents of this List.

func (*List) Resize added in v0.0.2

func (l *List) Resize(width, height int)

Resize resizes this list to fit within width and height.

func (*List) SeekDown added in v0.0.2

func (l *List) SeekDown() bool

SeekDown shifts the contents of this list one row down.

func (*List) SeekEnd added in v0.0.2

func (l *List) SeekEnd() (ok bool)

SeekEnd shifts the contents of this list such that the last element is drawn at the top of the list.

func (*List) SeekStart added in v0.0.2

func (l *List) SeekStart() (ok bool)

SeekStart shifts the contents of this list such that the first element is drawn at the top of the list.

func (*List) SeekUp added in v0.0.2

func (l *List) SeekUp() bool

SeekUp shifts the contents of this list one row up.

func (*List) SetElementHeight added in v0.0.2

func (l *List) SetElementHeight(height int)

SetElementHeight sets the height for each element of this list.

func (*List) Sort added in v0.0.2

func (l *List) Sort(less func(a, b tui.Component) bool)

Sort in-place sorts this List with the provided less function. It resets the current seek offset, if any.

func (*List) Width added in v0.0.2

func (l *List) Width() int

Width returns the width of this List, in the last call to Resize.

type ListNode added in v0.0.2

type ListNode struct {
	// contains filtered or unexported fields
}

ListNode is an element of a component List.

func (ListNode) Next added in v0.0.2

func (e ListNode) Next() (ListNode, bool)

Next gets the next linked node in the list after e.

func (ListNode) Position added in v0.0.40

func (e ListNode) Position() term.Coordinates

Position returns the viewport coordinates of this node, as set during the last Draw call.

func (ListNode) Prev added in v0.0.2

func (e ListNode) Prev() (ListNode, bool)

Prev gets the previous linked node in the list before e.

func (ListNode) SetValue added in v0.0.2

func (e ListNode) SetValue(c tui.Component)

SetValue sets the tui.Component value in ListNode.

func (ListNode) Value added in v0.0.2

func (e ListNode) Value() tui.Component

Value gets the tui.Component value in ListNode.

type Overlay added in v0.0.2

type Overlay struct {
	Span
	// contains filtered or unexported fields
}

Overlay overlays one component over another one, with potentially padding and/or alignment, specified by SpanConfig.

func NewOverlay added in v0.0.2

func NewOverlay(
	background, cover tui.Component, backAttr term.Attributes, config SpanConfig,
) *Overlay

NewOverlay allocates storage for a new overlay and initializes it.

func (*Overlay) Draw added in v0.0.2

func (o *Overlay) Draw(w term.Writer)

Draw satisfies tui.Component.

func (*Overlay) Init added in v0.0.2

func (o *Overlay) Init(
	background, cover tui.Component, backAttr term.Attributes, config SpanConfig,
)

Init initializes this overlay with the given background, cover and configuration.

func (*Overlay) Resize added in v0.0.2

func (o *Overlay) Resize(width, height int)

Resize satisfies tui.Component.

type Prompt added in v0.0.2

type Prompt struct {
	// contains filtered or unexported fields
}

Prompt implements a prompt / question with options component.

func NewPrompt added in v0.0.2

func NewPrompt(cfg PromptConfig) *Prompt

NewPrompt allocates storage for a new prompt and initializes it. See Init for more details.

func (*Prompt) Dimensions added in v0.0.2

func (p *Prompt) Dimensions() (int, int)

Dimensions satisfies Floating.

func (*Prompt) Draw added in v0.0.2

func (p *Prompt) Draw(w term.Writer)

Draw satisfies tui.Component

func (*Prompt) Init added in v0.0.2

func (p *Prompt) Init(cfg PromptConfig)

Init initializes this prompt with cfg. Note that PromptConfig.Options must always contain at least one option and PromptConfig.Message must not be empty. If one of these two rules is violated this method panics.

func (*Prompt) OptionAt added in v0.0.41

func (p *Prompt) OptionAt(x, y int) int

OptionAt returns the index of the option at the given coordinates, or -1 if no option is at that position.

func (*Prompt) Resize added in v0.0.2

func (p *Prompt) Resize(width, height int)

Resize satisfies tui.Component

func (*Prompt) SetOptionAttr added in v0.0.2

func (p *Prompt) SetOptionAttr(i int, attr term.Attributes)

SetOptionAttr sets the attributes of option at index i.

type PromptConfig added in v0.0.2

type PromptConfig struct {
	Message string
	Options []string
	Frame   FrameCharSet
	// AspectRatio of the floating prompt message. By default
	// DefaultAspectRatio is used. Ignored when NewMessage is set.
	AspectRatio float64
	// NewMessage, when non-nil, is called with cfg.Message to
	// build the prompt's message area. The returned Floating
	// replaces the default ResponsiveString wrapped with
	// NewAspectRatioFloatingResponsive.
	NewMessage           func(msg string) Floating
	BackgroundAttributes term.Attributes
	MinWidth             int
}

PromptConfig holds configuration for initializing a Prompt.

type Reference added in v0.0.2

type Reference struct {
	// contains filtered or unexported fields
}

Reference can be used to dynamically swap a tui.Component. If the underlying tui.Component is nil, then Resize and Draw do nothing.

func NewReference added in v0.0.2

func NewReference(ref tui.Component) *Reference

NewReference allocates storage for a new Reference and initializes it with ref.

func (*Reference) Draw added in v0.0.2

func (r *Reference) Draw(w term.Writer)

Draw satisfies tui.Component.

func (*Reference) Init added in v0.0.2

func (r *Reference) Init(ref tui.Component)

Init initializes this reference with ref. It can be used subsequently to override the underlying tui.Component reference.

func (*Reference) Resize added in v0.0.2

func (r *Reference) Resize(width, height int)

Resize satisfies tui.Component.

type Responsive added in v0.0.2

type Responsive interface {
	tui.Component
	// Height allows for children components to return a height hint
	// given a width so a parent component can compose accordingly.
	// The returned height can be overridden at the parent's discretion
	// (i.e. there's simply no height left on the screen)
	// so implementers should expect that on calls to Resize.
	Height(width int) int
}

Responsive components implement a backpressure mechanism (Height) for aggregate components to dynamically resize children based on their contents. See Height for more details.

func Divider added in v0.0.2

func Divider(perc float64, cfg StringConfig) Responsive

Divider returns a divider compatible with Responsive collections that will simply draw a line that will occupy perc of its width.

func FuncResponsive added in v0.0.2

func FuncResponsive(c tui.Component, heightFn func(width int) int) Responsive

FuncResponsive wraps a tui.Component that satisfies Responsive's Height by calling heightFn.

func NopResponsive added in v0.0.2

func NopResponsive() Responsive

NopResponsive returns a Responsive that does nothing.

func NopResponsiveFromComponent added in v0.0.2

func NopResponsiveFromComponent(c tui.Component) Responsive

NopResponsiveFromComponent wraps a Component to provide a Responsive that does nothing.

type ResponsiveList added in v0.0.2

type ResponsiveList struct {
	Alignment
	// contains filtered or unexported fields
}

ResponsiveList differs from List in that it enables clients to set the min width and height of the children components by using a push API with Responsive components, rather than tui.Components.

It also seeks in rows rather than elements, so long elements greater than height can be seeked top to bottom, one row at a time.

Alignment responds to AlignmentTop or AlignmentBottom for content alignment.

func NewResponsiveList added in v0.0.2

func NewResponsiveList() (l *ResponsiveList)

NewResponsiveList allocates storage for a new ResponsiveList and initializes it.

func (*ResponsiveList) Back added in v0.0.2

func (l *ResponsiveList) Back() (ListNode, bool)

Back returns the last node of list l or false if the list is empty.

func (*ResponsiveList) CanSeekDown added in v0.0.2

func (l *ResponsiveList) CanSeekDown() bool

CanSeekDown returns whether SeekDown would seek one row down.

func (*ResponsiveList) CanSeekUp added in v0.0.2

func (l *ResponsiveList) CanSeekUp() bool

CanSeekUp returns whether SeekUp would seek one row up.

func (*ResponsiveList) Draw added in v0.0.2

func (l *ResponsiveList) Draw(w term.Writer)

Draw draws this list's elements with the current seek offset.

func (*ResponsiveList) ElementAt added in v0.0.2

func (l *ResponsiveList) ElementAt(pos term.Coordinates) (ListNode, bool)

ElementAt returns the element at pos Coordinates or panics if coordinates are out of the bounds of this ResponsiveList.

func (*ResponsiveList) Front added in v0.0.2

func (l *ResponsiveList) Front() (ListNode, bool)

Front returns the first node of list l or false if the list is empty.

func (*ResponsiveList) Height added in v0.0.2

func (l *ResponsiveList) Height(width int) (ret int)

Height satisfies Responsive.

func (*ResponsiveList) Init added in v0.0.2

func (l *ResponsiveList) Init()

Init initializes this list. It can be used to reset its internal state.

func (*ResponsiveList) InsertAfter added in v0.0.2

func (l *ResponsiveList) InsertAfter(c Responsive, mark ListNode) ListNode

InsertAfter inserts a new element c immediately after mark and returns the linked node. If mark is not an element of l, the list is not modified.

func (*ResponsiveList) InsertBefore added in v0.0.2

func (l *ResponsiveList) InsertBefore(c Responsive, mark ListNode) ListNode

InsertBefore inserts a new element c immediately before mark and returns the linked node. If mark is not an element of l, the list is not modified.

func (*ResponsiveList) Iterate added in v0.0.2

func (l *ResponsiveList) Iterate(fn func(Responsive))

Iterate iterates over all elements in l.

func (*ResponsiveList) Len added in v0.0.2

func (l *ResponsiveList) Len() int

Len returns the number of nodes of list l in O(1).

func (*ResponsiveList) MaxOffset added in v0.0.2

func (l *ResponsiveList) MaxOffset() int

MaxOffset returns the max seek offset of this list, given the current dimensions.

func (*ResponsiveList) PushBack added in v0.0.2

func (l *ResponsiveList) PushBack(c Responsive) ListNode

PushBack inserts a new element c at the back of list l and returns the linked node.

func (*ResponsiveList) PushBackList added in v0.0.2

func (l *ResponsiveList) PushBackList(other *ResponsiveList)

PushBackList inserts a copy of an other list at the back of list l. The lists l and other must NOT be the same or nil.

func (*ResponsiveList) PushFront added in v0.0.2

func (l *ResponsiveList) PushFront(c Responsive) ListNode

PushFront inserts a new element c at the front of list l and returns the linked node.

func (*ResponsiveList) PushFrontList added in v0.0.2

func (l *ResponsiveList) PushFrontList(other *ResponsiveList)

PushFrontList inserts a copy of an other list at the front of list l. The lists l and other must NOT be the same or nil.

func (*ResponsiveList) Remove added in v0.0.2

func (l *ResponsiveList) Remove(e *ListNode) Responsive

Remove removes e from l if e is a node of list l. It returns the element value e.Value.

func (*ResponsiveList) Reset added in v0.0.2

func (l *ResponsiveList) Reset()

Reset resets the contents of this List.

func (*ResponsiveList) Resize added in v0.0.2

func (l *ResponsiveList) Resize(width, height int)

Resize resizes this list to fit within width and height.

func (*ResponsiveList) SeekDown added in v0.0.2

func (l *ResponsiveList) SeekDown() bool

SeekDown shifts the contents of this list one row down.

func (*ResponsiveList) SeekEnd added in v0.0.2

func (l *ResponsiveList) SeekEnd() (ok bool)

SeekEnd shifts the contents of this list such that the end of the last element is drawn at the end of the draw area.

func (*ResponsiveList) SeekStart added in v0.0.2

func (l *ResponsiveList) SeekStart() (ok bool)

SeekStart shifts the contents of this list to the start of the list.

func (*ResponsiveList) SeekUp added in v0.0.2

func (l *ResponsiveList) SeekUp() bool

SeekUp shifts the contents of this list one row up.

func (*ResponsiveList) SizeHeight added in v0.0.2

func (l *ResponsiveList) SizeHeight() int

SizeHeight returns the height of this List, in the last call to Resize.

func (*ResponsiveList) SizeWidth added in v0.0.2

func (l *ResponsiveList) SizeWidth() int

SizeWidth returns the width of this List, in the last call to Resize.

func (*ResponsiveList) Sort added in v0.0.2

func (l *ResponsiveList) Sort(less func(a, b Responsive) bool)

Sort sorts the elements of this list with the provided less function.

type ResponsiveString added in v0.0.2

type ResponsiveString struct {
	// contains filtered or unexported fields
}

ResponsiveString is a String component that also satisfies Responsive.

func NewResponsiveString added in v0.0.2

func NewResponsiveString(str string, cfg StringResponsiveConfig) *ResponsiveString

NewResponsiveString allocates storage for a new ResponsiveString based on str and cfg.

func NewResponsiveStringFromCells added in v0.0.2

func NewResponsiveStringFromCells(cells [][]term.Cell, cfg StringResponsiveConfig) *ResponsiveString

NewResponsiveStringFromCells returns a Responsive implementation for a matrix of cells.

func (*ResponsiveString) Dimensions added in v0.0.2

func (s *ResponsiveString) Dimensions() (width, height int)

Dimensions returns the optimal width and height.

func (*ResponsiveString) Draw added in v0.0.2

func (s *ResponsiveString) Draw(w term.Writer)

Draw satisfies tui.Component.

func (*ResponsiveString) Height added in v0.0.2

func (s *ResponsiveString) Height(width int) int

Height satisfies Responsive.

func (*ResponsiveString) Init added in v0.0.2

func (s *ResponsiveString) Init(cells [][]term.Cell, cfg StringResponsiveConfig)

Init initializes a ResponsiveString with the given cells and cfg.

func (*ResponsiveString) Reset added in v0.0.2

func (s *ResponsiveString) Reset(cells [][]term.Cell, cfg StringResponsiveConfig)

Reset resets a ResponsiveString with the given cells and cfg.

func (*ResponsiveString) Resize added in v0.0.2

func (s *ResponsiveString) Resize(width, height int)

Resize satisfies tui.Component.

func (*ResponsiveString) SetAttr added in v0.0.2

func (s *ResponsiveString) SetAttr(attr term.Attributes) term.Attributes

SetAttr satisfies WithAttributes.

func (*ResponsiveString) String added in v0.0.2

func (s *ResponsiveString) String() string

String satisfies fmt.Stringer.

type Row added in v0.0.2

type Row struct {
	Virtual[tui.Component]
	// contains filtered or unexported fields
}

Row provides means to horizontally stack a set of components. It exposes AddComponent which enables clients to preemptively divide the available width in 12 columns. A component that's installed with 6 columns for instance, will use exactly 50% of the available width.

Row satisfies component.Responsive by returning the biggest height of any of its children.

A zero-valued row is ready to be used.

func NewRow added in v0.0.2

func NewRow() *Row

NewRow allocates storage for a new Row and initializes it.

func (*Row) AddComponent added in v0.0.2

func (r *Row) AddComponent(c Responsive, cols int) *Virtual[Responsive]

AddComponent adds a component to this Row with the given columns over MaxCols as the pre-defined width.

func (*Row) Dimensions added in v0.0.2

func (r *Row) Dimensions() (retWidth int, retHeight int)

Dimensions satisfies component.Floating. If underlying components do not satisfy component.Floating, then this method panics.

func (*Row) Draw added in v0.0.2

func (r *Row) Draw(w term.Writer)

Draw satisfies tui.Component.

func (*Row) Height added in v0.0.2

func (r *Row) Height(width int) (ret int)

Height satisfies component.Responsive.

func (*Row) Resize added in v0.0.2

func (r *Row) Resize(width, height int)

Resize satisfies tui.Component.

type Scrollable

type Scrollable interface {
	tui.Component

	SeekUp() bool
	SeekDown() bool
	SeekOffset() int
	MaxSeekOffset() int
}

Scrollable abstracts a component that can scroll up or down.

func NopScrollable

func NopScrollable() Scrollable

NopScrollable returns a Scrollable that does nothing.

func NopScrollableFromComponent added in v0.0.2

func NopScrollableFromComponent(c tui.Component) Scrollable

NopScrollableFromComponent wraps a Component to provide a Scrollable that does nothing.

type ScrollableFloating

type ScrollableFloating interface {
	Scrollable
	Floating
}

ScrollableFloating is a Floating that is capable of scrolling content.

func NopFloatingFromScrollable added in v0.0.2

func NopFloatingFromScrollable(s Scrollable) ScrollableFloating

NopFloatingFromScrollable wraps a Scrollable to provide a ScrollableFloating that does nothing.

func NopScrollableFloating

func NopScrollableFloating() ScrollableFloating

NopScrollableFloating returns a ScrollableFloating that does nothing.

func NopScrollableFloatingFromComponent added in v0.0.2

func NopScrollableFloatingFromComponent(c tui.Component) ScrollableFloating

NopScrollableFloatingFromComponent wraps a Component to provide a ScrollableFloating that does nothing.

func NopScrollableFromFloating added in v0.0.2

func NopScrollableFromFloating(f Floating) ScrollableFloating

NopScrollableFromFloating wraps a Floating to provide a ScrollableFloating that does nothing.

type ScrollableFloatingWithAttributes added in v0.0.2

type ScrollableFloatingWithAttributes interface {
	Scrollable
	Floating
	WithAttributes
}

ScrollableFloatingWithAttributes is a FloatingWithAttributes that is capable of scrolling content.

func NopFloatingFromScrollableWithAttributes added in v0.0.2

func NopFloatingFromScrollableWithAttributes(sa ScrollableWithAttributes) ScrollableFloatingWithAttributes

NopFloatingFromScrollableWithAttributes wraps a ScrollableWithAttributes to provide a ScrollableFloatingWithAttributes that does nothing.

func NopScrollableFloatingFromWithAttributes added in v0.0.2

func NopScrollableFloatingFromWithAttributes(a WithAttributes) ScrollableFloatingWithAttributes

NopScrollableFloatingFromWithAttributes wraps a WithAttributes to provide a ScrollableFloatingWithAttributes that does nothing.

func NopScrollableFloatingWithAttributes added in v0.0.2

func NopScrollableFloatingWithAttributes() ScrollableFloatingWithAttributes

NopScrollableFloatingWithAttributes returns a ScrollableFloatingWithAttributes that does nothing.

func NopScrollableFloatingWithAttributesFromComponent added in v0.0.2

func NopScrollableFloatingWithAttributesFromComponent(c tui.Component) ScrollableFloatingWithAttributes

NopScrollableFloatingWithAttributesFromComponent wraps a Component to provide a ScrollableFloatingWithAttributes that does nothing.

func NopScrollableFromWithAttributesFloating added in v0.0.2

func NopScrollableFromWithAttributesFloating(af WithAttributesFloating) ScrollableFloatingWithAttributes

NopScrollableFromWithAttributesFloating wraps a WithAttributesFloating to provide a ScrollableFloatingWithAttributes that does nothing.

func NopScrollableWithAttributesFromFloating added in v0.0.2

func NopScrollableWithAttributesFromFloating(f Floating) ScrollableFloatingWithAttributes

NopScrollableWithAttributesFromFloating wraps a Floating to provide a ScrollableFloatingWithAttributes that does nothing.

func NopWithAttributesFloatingFromScrollable added in v0.0.2

func NopWithAttributesFloatingFromScrollable(s Scrollable) ScrollableFloatingWithAttributes

NopWithAttributesFloatingFromScrollable wraps a Scrollable to provide a ScrollableFloatingWithAttributes that does nothing.

func NopWithAttributesFromScrollableFloating added in v0.0.2

func NopWithAttributesFromScrollableFloating(sf ScrollableFloating) ScrollableFloatingWithAttributes

NopWithAttributesFromScrollableFloating wraps a ScrollableFloating to provide a ScrollableFloatingWithAttributes that does nothing.

type ScrollableWithAttributes added in v0.0.2

type ScrollableWithAttributes interface {
	Scrollable
	WithAttributes
}

ScrollableWithAttributes is a WithAttributes that is capable of scrolling content.

func NopScrollableFromWithAttributes added in v0.0.2

func NopScrollableFromWithAttributes(a WithAttributes) ScrollableWithAttributes

NopScrollableFromWithAttributes wraps a WithAttributes to provide a ScrollableWithAttributes that does nothing.

func NopScrollableWithAttributes added in v0.0.2

func NopScrollableWithAttributes() ScrollableWithAttributes

NopScrollableWithAttributes returns a ScrollableWithAttributes that does nothing.

func NopScrollableWithAttributesFromComponent added in v0.0.2

func NopScrollableWithAttributesFromComponent(c tui.Component) ScrollableWithAttributes

NopScrollableWithAttributesFromComponent wraps a Component to provide a ScrollableWithAttributes that does nothing.

func NopWithAttributesFromScrollable added in v0.0.2

func NopWithAttributesFromScrollable(s Scrollable) ScrollableWithAttributes

NopWithAttributesFromScrollable wraps a Scrollable to provide a ScrollableWithAttributes that does nothing.

type Span added in v0.0.2

type Span struct {
	// contains filtered or unexported fields
}

Span is a component that takes another component and handles padding and alignment.

func NewSpan added in v0.0.2

func NewSpan(content tui.Component, cfg SpanConfig) *Span

NewSpan returns an initialized Span. See Span.Init for more info.

func (*Span) Content added in v0.0.2

func (s *Span) Content() tui.Component

Content returns this Span's underlying content.

func (*Span) ContentOffset added in v0.0.2

func (s *Span) ContentOffset() term.Coordinates

ContentOffset returns the offset in term.Coordinates of the content inside the span.

func (*Span) Dimensions added in v0.0.2

func (s *Span) Dimensions() (width, height int)

Dimensions satisfies Floating by returning the underlying component's Dimensions with added padding, or panics if the underlying component does not satisfy Floating.

func (*Span) Draw added in v0.0.2

func (s *Span) Draw(w term.Writer)

Draw satisfies tui.Component

func (*Span) Height added in v0.0.2

func (s *Span) Height(width int) int

Height satisfies Responsive by returning the underlying component's Height with added padding, or panics if the underlying component does not satisfy Responsive.

func (*Span) Init added in v0.0.2

func (s *Span) Init(content tui.Component, cfg SpanConfig)

Init initializes this Span with content.

func (*Span) Resize added in v0.0.2

func (s *Span) Resize(width, height int)

Resize satisfies tui.Component

func (*Span) SetAttr added in v0.0.2

func (s *Span) SetAttr(attr term.Attributes) term.Attributes

SetAttr satisfies WithAttributes if the underlying component satisfies WithAttributes, otherwise it panics.

func (*Span) SetContent added in v0.0.2

func (s *Span) SetContent(content tui.Component)

SetContent updates the underlying component and resizes it to conform to this frame's width and height.

type SpanConfig added in v0.0.2

type SpanConfig struct {
	PadHorizontal int
	PadVertical   int

	PadHorizontalPerc float64
	PadVerticalPerc   float64

	// PadAutoFloating calculates horizontal and vertical
	// padding automatically from the inner component's
	// Dimensions. The inner component must satisfy Floating
	// or the constructor will panic. When set, PadHorizontal,
	// PadVertical, PadHorizontalPerc and PadVerticalPerc are
	// ignored.
	PadAutoFloating bool

	ContentAlignment Alignment
}

SpanConfig represents the configuration of a Span.

Padding can be configured as an absolute number of cells (PadHorizontal/PadVertical) or as a percentage of the available space (PadHorizontalPerc/PadVerticalPerc). Either PadHorizontal/PadVertical or PadHorizontalPerc/PadVerticalPerc should be set; If both are set, then Horizontal/Vertical take precedence.

Negative padding on PadHorizontal/PadVertical indicates that the padding should be automatically calculated based on the available height/width. For instance, a Horizontal padding of -1, indicates that the padding needs to be set such that the inner component is exactly 1 cell.

func DefaultSpanConfig added in v0.0.2

func DefaultSpanConfig() (ret SpanConfig)

DefaultSpanConfig returns the default span configuration which is no padding, and content alignment centered.

type String added in v0.0.2

type String struct {
	// contains filtered or unexported fields
}

String is a tui.Component that draws a string with or without a background. It satisfies both Floating and WithAttributes. See NewString and NewStringWithConfig for more details.

func NewString added in v0.0.2

func NewString(str string) String

NewString converts a string into top left centered one line tui.Component which draws the given string. If the string needs to be centered dynamically, or drawn multi-line use StringWithConfig instead.

func NewStringWithConfig added in v0.0.2

func NewStringWithConfig(str string, cfg StringConfig) String

NewStringWithConfig converts a string into a static tui.Component with background/foreground attributes, content alignment and a frame, all configurable through cfg. The returned component is significantly slower to Draw and Resize than the component returned by String.

func (String) Config added in v0.0.2

func (s String) Config() StringConfig

Config returns this String's StringConfig.

type StringConfig added in v0.0.2

type StringConfig struct {
	Alignment
	term.Attributes
	FrameCharSet
	BackgroundAttributes term.Attributes
	BackgroundRune       rune
	PaddingVertical      int
	PaddingHorizontal    int
	MinWidth             int
}

StringConfig defines options for StringConfig and StringResponsive constructors.

type StringResponsiveConfig added in v0.0.2

type StringResponsiveConfig struct {
	// NoSplitWords instructs the underlying string responsive component
	// to attempt to not split words in half when possible.
	NoSplitWords bool
	StringConfig
}

StringResponsiveConfig adds responsive-specific configuration to a StringConfig.

type TestComponent added in v0.0.2

type TestComponent struct {
	Ch rune
	term.Attributes
	// contains filtered or unexported fields
}

TestComponent draws rune Ch, and attributes Bg, Fg on every cell available. This component is used for testing or debugging.

func (*TestComponent) Draw added in v0.0.2

func (t *TestComponent) Draw(w term.Writer)

Draw satisfies tui.Component.

func (*TestComponent) Resize added in v0.0.2

func (t *TestComponent) Resize(width, height int)

Resize satisfies tui.Component.

func (*TestComponent) SetAttr added in v0.0.2

func (t *TestComponent) SetAttr(attr term.Attributes) (ret term.Attributes)

SetAttr satisfies WithAttributes

type TestResponsive added in v0.0.2

type TestResponsive struct {
	TestComponent
	PassedWidth int
	WantHeight  int
	WantWidth   int
}

TestResponsive is a Responsive and Floating for testing.

func (*TestResponsive) Dimensions added in v0.0.2

func (t *TestResponsive) Dimensions() (width, height int)

Dimensions satisfies Floating.

func (*TestResponsive) Height added in v0.0.2

func (t *TestResponsive) Height(width int) int

Height satisfies Responsive.

type Virtual added in v0.0.2

type Virtual[T tui.Component] struct {
	C T
	// contains filtered or unexported fields
}

Virtual wraps a component to provide virtual coordinates and write bound checking. It exposes Move which can be used to move the inner component in the virtual coordinate space.

func (*Virtual[T]) Draw added in v0.0.2

func (c *Virtual[T]) Draw(writer term.Writer)

Draw uses a virtual writer to perform bound checking and if successful draw the inner component in the virtual coordinate space.

func (*Virtual[T]) Height added in v0.0.2

func (c *Virtual[T]) Height() int

Height returns the height set in last Resize.

func (*Virtual[T]) Move added in v0.0.2

func (c *Virtual[T]) Move(pos term.Coordinates)

Move changes the position of this virtual component in the virtual coordinate space.

func (*Virtual[T]) Position added in v0.0.2

func (c *Virtual[T]) Position() term.Coordinates

Position returns this virtual component's position in the virtual coordinate space.

func (*Virtual[T]) Resize added in v0.0.2

func (c *Virtual[T]) Resize(width, height int)

Resize resizes the underlying component and stores size to perform bound checking on Draw.

func (*Virtual[T]) Width added in v0.0.2

func (c *Virtual[T]) Width() int

Width returns the width set in last Resize.

type VirtualWriter added in v0.0.2

type VirtualWriter struct {
	Writer        term.Writer
	Offset        term.Coordinates
	Height, Width int
}

VirtualWriter wraps the given w with a writer that applies an offset and SetCell clipping according to offset, height and width.

func (*VirtualWriter) Context added in v0.0.2

func (w *VirtualWriter) Context() context.Context

Context satisfies term.Writer.

func (*VirtualWriter) SetCell added in v0.0.2

func (w *VirtualWriter) SetCell(pos term.Coordinates, c term.Cell)

SetCell satisfies term.Writer.

func (*VirtualWriter) UnionAttributes added in v0.0.2

func (w *VirtualWriter) UnionAttributes(pos term.Coordinates, attr term.Attributes)

UnionAttributes satisfies term.Writer.

type WithAttributes added in v0.0.2

type WithAttributes interface {
	tui.Component
	SetAttr(term.Attributes) term.Attributes
}

WithAttributes represents a tui.Component that can be set attributes.

func NopWithAttributes added in v0.0.2

func NopWithAttributes() WithAttributes

NopWithAttributes returns a WithAttributes that does nothing.

func NopWithAttributesFromComponent added in v0.0.2

func NopWithAttributesFromComponent(c tui.Component) WithAttributes

NopWithAttributesFromComponent wraps a Component to provide a WithAttributes that does nothing.

type WithAttributesFloating added in v0.0.2

type WithAttributesFloating interface {
	WithAttributes
	Floating
}

WithAttributesFloating is a Floating that is capable of setting attributes.

func NopFloatingFromWithAttributes added in v0.0.2

func NopFloatingFromWithAttributes(a WithAttributes) WithAttributesFloating

NopFloatingFromWithAttributes wraps a WithAttributes to provide a WithAttributesFloating that does nothing.

func NopWithAttributesFloating added in v0.0.2

func NopWithAttributesFloating() WithAttributesFloating

NopWithAttributesFloating returns a WithAttributesFloating that does nothing.

func NopWithAttributesFloatingFromComponent added in v0.0.2

func NopWithAttributesFloatingFromComponent(c tui.Component) WithAttributesFloating

NopWithAttributesFloatingFromComponent wraps a Component to provide a WithAttributesFloating that does nothing.

func NopWithAttributesFromFloating added in v0.0.2

func NopWithAttributesFromFloating(f Floating) WithAttributesFloating

NopWithAttributesFromFloating wraps a Floating to provide a WithAttributesFloating that does nothing.

type WithAttributesResponsive added in v0.0.2

type WithAttributesResponsive interface {
	WithAttributes
	Responsive
}

WithAttributesResponsive is a Responsive that is capable of setting attributes.

func NopResponsiveFromWithAttributes added in v0.0.2

func NopResponsiveFromWithAttributes(a WithAttributes) WithAttributesResponsive

NopResponsiveFromWithAttributes wraps a WithAttributes to provide a WithAttributesResponsive that does nothing.

func NopWithAttributesFromResponsive added in v0.0.2

func NopWithAttributesFromResponsive(r Responsive) WithAttributesResponsive

NopWithAttributesFromResponsive wraps a Responsive to provide a WithAttributesResponsive that does nothing.

func NopWithAttributesResponsive added in v0.0.2

func NopWithAttributesResponsive() WithAttributesResponsive

NopWithAttributesResponsive returns a WithAttributesResponsive that does nothing.

func NopWithAttributesResponsiveFromComponent added in v0.0.2

func NopWithAttributesResponsiveFromComponent(c tui.Component) WithAttributesResponsive

NopWithAttributesResponsiveFromComponent wraps a Component to provide a WithAttributesResponsive that does nothing.

type WithAttributesResponsiveFloating added in v0.0.2

type WithAttributesResponsiveFloating interface {
	WithAttributes
	Responsive
	Floating
}

WithAttributesResponsiveFloating is a Responsive and Floating that is capable of setting attributes.

func NopFloatingFromWithAttributesResponsive added in v0.0.2

func NopFloatingFromWithAttributesResponsive(ar WithAttributesResponsive) WithAttributesResponsiveFloating

NopFloatingFromWithAttributesResponsive wraps a WithAttributesResponsive to provide a WithAttributesResponsiveFloating that does nothing.

func NopResponsiveFloatingFromWithAttributes added in v0.0.2

func NopResponsiveFloatingFromWithAttributes(a WithAttributes) WithAttributesResponsiveFloating

NopResponsiveFloatingFromWithAttributes wraps a WithAttributes to provide a WithAttributesResponsiveFloating that does nothing.

func NopResponsiveFromWithAttributesFloating added in v0.0.2

func NopResponsiveFromWithAttributesFloating(af WithAttributesFloating) WithAttributesResponsiveFloating

NopResponsiveFromWithAttributesFloating wraps a WithAttributesFloating to provide a WithAttributesResponsiveFloating that does nothing.

func NopWithAttributesFloatingFromResponsive added in v0.0.2

func NopWithAttributesFloatingFromResponsive(r Responsive) WithAttributesResponsiveFloating

NopWithAttributesFloatingFromResponsive wraps a Responsive to provide a WithAttributesResponsiveFloating that does nothing.

func NopWithAttributesFromFloatingResponsive added in v0.0.2

func NopWithAttributesFromFloatingResponsive(fr FloatingResponsive) WithAttributesResponsiveFloating

NopWithAttributesFromFloatingResponsive wraps a FloatingResponsive to provide a WithAttributesResponsiveFloating that does nothing.

func NopWithAttributesResponsiveFloating added in v0.0.2

func NopWithAttributesResponsiveFloating() WithAttributesResponsiveFloating

NopWithAttributesResponsiveFloating returns a WithAttributesResponsiveFloating that does nothing.

func NopWithAttributesResponsiveFloatingFromComponent added in v0.0.2

func NopWithAttributesResponsiveFloatingFromComponent(c tui.Component) WithAttributesResponsiveFloating

NopWithAttributesResponsiveFloatingFromComponent wraps a Component to provide a WithAttributesResponsiveFloating that does nothing.

func NopWithAttributesResponsiveFromFloating added in v0.0.2

func NopWithAttributesResponsiveFromFloating(f Floating) WithAttributesResponsiveFloating

NopWithAttributesResponsiveFromFloating wraps a Floating to provide a WithAttributesResponsiveFloating that does nothing.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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