Documentation
¶
Overview ¶
Package tapioca defines some common components.
Index ¶
- func IsThisTopping(spec ToppingTestSpec) string
- func NewID() int64
- func RuneWidth(r rune) int
- type CircularBuffer
- func (cb *CircularBuffer[T]) Append(item T)
- func (cb *CircularBuffer[T]) Capacity() int
- func (cb *CircularBuffer[T]) GetAll() []T
- func (cb *CircularBuffer[T]) Prepend(item T)
- func (cb *CircularBuffer[T]) Reset()
- func (cb *CircularBuffer[T]) Resize(newSize int)
- func (cb *CircularBuffer[T]) Size() int
- type Entry
- func (e *Entry) Lines(width int) int
- func (e *Entry) String() string
- func (e *Entry) StyledBlock(width int) []string
- func (e *Entry) StyledMove(startCol, width int) string
- func (e *Entry) StyledShift(startCol, width int) string
- func (e *Entry) StyledString() string
- func (e *Entry) StyledWarps(width int) []string
- func (e *Entry) Width() int
- type ResizeMsg
- type ScrollBeginMsg
- type ScrollBottomMsg
- type ScrollController
- type ScrollDownMsg
- type ScrollEndMsg
- type ScrollLeftMsg
- type ScrollRightMsg
- type ScrollToMsg
- type ScrollTopMsg
- type ScrollUpMsg
- type Scrollable
- func (s *Scrollable) HandleEvent(msg tea.Msg)
- func (s *Scrollable) Height() int
- func (s *Scrollable) ScrollDown(lines int)
- func (s *Scrollable) ScrollLeft(cols int)
- func (s *Scrollable) ScrollRight(cols int)
- func (s *Scrollable) ScrollTo(col, row int)
- func (s *Scrollable) ScrollToBegin()
- func (s *Scrollable) ScrollToBottom()
- func (s *Scrollable) ScrollToEnd()
- func (s *Scrollable) ScrollToTop()
- func (s *Scrollable) ScrollUp(lines int)
- func (s *Scrollable) Width() int
- func (s *Scrollable) X() int
- func (s *Scrollable) Y() int
- type StyledRune
- type ToppingTestSpec
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsThisTopping ¶ added in v0.0.2
func IsThisTopping(spec ToppingTestSpec) string
IsThisTopping is a test helper to check if a given huninn component fulfills the basic requirements.
It returns an empty string if all is good, otherwise a descriptive error message.
Check [Component] for the requirements.
Types ¶
type CircularBuffer ¶
type CircularBuffer[T any] struct { // contains filtered or unexported fields }
CircularBuffer is a generic circular buffer implementation.
func NewCircularBuffer ¶
func NewCircularBuffer[T any](size int) *CircularBuffer[T]
NewCircularBuffer creates a new CircularBuffer with the given size.
func (*CircularBuffer[T]) Append ¶
func (cb *CircularBuffer[T]) Append(item T)
Append adds an item to the end of the buffer, removing the oldest item if full
func (*CircularBuffer[T]) Capacity ¶
func (cb *CircularBuffer[T]) Capacity() int
Capacity returns the maximum number of elements the buffer can hold
func (*CircularBuffer[T]) GetAll ¶
func (cb *CircularBuffer[T]) GetAll() []T
GetAll returns all elements in the buffer in order from oldest to newest
func (*CircularBuffer[T]) Prepend ¶
func (cb *CircularBuffer[T]) Prepend(item T)
Prepend adds an item to the start of the buffer, removing the oldest item if full
func (*CircularBuffer[T]) Resize ¶
func (cb *CircularBuffer[T]) Resize(newSize int)
Resize changes the capacity of the buffer, preserving existing elements
func (*CircularBuffer[T]) Size ¶
func (cb *CircularBuffer[T]) Size() int
Size returns the number of elements currently in the buffer
type Entry ¶
type Entry struct {
// contains filtered or unexported fields
}
Entry represents a text entry with styled runes and provides methods to compute its display width, handle line wrapping, and retrieve styled substrings.
func NewEntry ¶
NewEntry creates a new Entry from the given string, parsing ANSI styles and handling East Asian wide characters.
func (*Entry) Lines ¶
Lines returns the number of lines the entry would occupy when wrapped at the given width
func (*Entry) StyledBlock ¶ added in v0.0.2
StyledBlock returns the entry split into lines, each line wrapped at the given width and padded with spaces to ensure each line is exactly width characters wide
For width <= 0, it resets to 1.
For width == 1 with wide characters, the lines contain wide character will have a width of 2.
func (*Entry) StyledMove ¶ added in v0.0.2
StyledMove returns a styled substring of the entry, as if viewport is moving over the entry.
startCol and width are in terms of display width, not string length. For example:
(0, 4): start from 0, and 4 columns wide for "01三五七89" it returns "01三" (三 is 2 columns wide) for "0123456789" it returns "0123" (-1, 5): start from -1, and 5 columns wide for "01三五七89" it returns " 01三" (pad one space at beginning) for "0123456789" it returns " 01234" (pad one space at beginning) (8, 4): start from 8, and 4 columns wide for "01三五七89" it returns "89 " (pad two space at end) for "0123456789" it returns "89 " (pad two space at end)
func (*Entry) StyledShift ¶
StyledShift returns a styled substring of the entry, starting at startCol
startCol and width are in terms of display width, not string length. For example:
(0, 4): start from 0, and 4 columns wide for "01三五七89" it returns "01三" (三 is 2 columns wide) for "0123456789" it returns "0123" (1, 4): start from 1, and 4 columns wide for "01三五七89" it returns "1三 " (五 is cutted) for "0123456789" it returns "1234"
It will not shift across entry boundary, so if the requested position is larger than the entry width, it will return the whole entry.
func (*Entry) StyledString ¶ added in v0.0.2
StyledString returns the styled text representation of the entry
func (*Entry) StyledWarps ¶ added in v0.0.2
StyledWarps returns the entry split into lines, each line wrapped at the given width without any padding.
For width <= 0, it resets to 1.
For width == 1 with wide characters, the lines contain wide character will have a width of 2.
type ScrollBeginMsg ¶
type ScrollBeginMsg struct{}
ScrollBeginMsg tells the component to scroll to the beginning of the line
type ScrollBottomMsg ¶
type ScrollBottomMsg struct{}
ScrollBottomMsg tells the component to scroll to the bottom of the component
type ScrollController ¶ added in v0.0.2
type ScrollController interface {
X() int
Y() int
Width() int
Height() int
ScrollUp(lines int)
ScrollDown(lines int)
ScrollToTop()
ScrollToBottom()
ScrollLeft(cols int)
ScrollRight(cols int)
ScrollToBegin()
ScrollToEnd()
ScrollTo(col, row int)
}
ScrollController defines the interface for controlling scrolling behavior in a UI component. IT DOES NOT TRIGGER A RENDER UPDATE.
type ScrollDownMsg ¶
type ScrollDownMsg uint
ScrollDownMsg tells the component to scroll down (towards bottom of component)
type ScrollEndMsg ¶
type ScrollEndMsg struct{}
ScrollEndMsg tells the component to scroll to the end of the line
type ScrollLeftMsg ¶
type ScrollLeftMsg uint
ScrollLeftMsg tells the component to scroll left (towards start of line)
type ScrollRightMsg ¶
type ScrollRightMsg uint
ScrollRightMsg tells the component to scroll right (towards end of line)
type ScrollToMsg ¶ added in v0.0.2
ScrollToMsg tells the component to scroll to the specified column and row
type ScrollTopMsg ¶
type ScrollTopMsg struct{}
ScrollTopMsg tells the component to scroll to the top of the component
type ScrollUpMsg ¶
type ScrollUpMsg uint
ScrollUpMsg tells the component to scroll up (toward top of component)
type Scrollable ¶ added in v0.0.2
type Scrollable struct {
// contains filtered or unexported fields
}
Scrollable provides a basic implementation of the ScrollController interface.
It handles ResizeMsg and Scroll*Msg messages to update its state.
func NewScrollable ¶ added in v0.0.2
func NewScrollable(maxW, maxH func() int) Scrollable
func (*Scrollable) HandleEvent ¶ added in v0.0.2
func (s *Scrollable) HandleEvent(msg tea.Msg)
func (*Scrollable) Height ¶ added in v0.0.2
func (s *Scrollable) Height() int
func (*Scrollable) ScrollDown ¶ added in v0.0.2
func (s *Scrollable) ScrollDown(lines int)
func (*Scrollable) ScrollLeft ¶ added in v0.0.2
func (s *Scrollable) ScrollLeft(cols int)
func (*Scrollable) ScrollRight ¶ added in v0.0.2
func (s *Scrollable) ScrollRight(cols int)
func (*Scrollable) ScrollTo ¶ added in v0.0.2
func (s *Scrollable) ScrollTo(col, row int)
func (*Scrollable) ScrollToBegin ¶ added in v0.0.2
func (s *Scrollable) ScrollToBegin()
func (*Scrollable) ScrollToBottom ¶ added in v0.0.2
func (s *Scrollable) ScrollToBottom()
func (*Scrollable) ScrollToEnd ¶ added in v0.0.2
func (s *Scrollable) ScrollToEnd()
func (*Scrollable) ScrollToTop ¶ added in v0.0.2
func (s *Scrollable) ScrollToTop()
func (*Scrollable) ScrollUp ¶ added in v0.0.2
func (s *Scrollable) ScrollUp(lines int)
func (*Scrollable) Width ¶ added in v0.0.2
func (s *Scrollable) Width() int
func (*Scrollable) X ¶ added in v0.0.2
func (s *Scrollable) X() int
func (*Scrollable) Y ¶ added in v0.0.2
func (s *Scrollable) Y() int
type StyledRune ¶
type StyledRune struct {
Rune rune
Style *style
}