tapioca

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2025 License: MPL-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package tapioca defines some common components.

Index

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.

func NewID

func NewID() int64

NewID generates a new unique ID.

func RuneWidth

func RuneWidth(r rune) int

RuneWidth returns the display width of a rune, considering East Asian wide characters.

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

func (cb *CircularBuffer[T]) Reset()

Reset clears the buffer

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

func NewEntry(data string) *Entry

NewEntry creates a new Entry from the given string, parsing ANSI styles and handling East Asian wide characters.

func (*Entry) Lines

func (e *Entry) Lines(width int) int

Lines returns the number of lines the entry would occupy when wrapped at the given width

func (*Entry) String

func (e *Entry) String() string

String returns the plain text representation of the entry (without styles)

func (*Entry) StyledBlock added in v0.0.2

func (e *Entry) StyledBlock(width int) []string

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

func (e *Entry) StyledMove(startCol, width int) string

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

func (e *Entry) StyledShift(startCol, width int) string

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

func (e *Entry) StyledString() string

StyledString returns the styled text representation of the entry

func (*Entry) StyledWarps added in v0.0.2

func (e *Entry) StyledWarps(width int) []string

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.

func (*Entry) Width added in v0.0.2

func (e *Entry) Width() int

Width returns the display width of the entry, ANSI styles are ignored

For example, the width of "ab你好cd" is 8 (1+1+2+2+1+1)

type ResizeMsg

type ResizeMsg struct {
	Width  int
	Height int
}

ResizeMsg denotes the layout component is asking target to resize

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

type ScrollToMsg struct {
	X int
	Y int
}

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
}

type ToppingTestSpec added in v0.0.2

type ToppingTestSpec struct {
	Width  int
	Height int
	tea.Model
	EventLoopMaxTimes int
}

ToppingTestSpec is a specification for testing a huninn component.

Jump to

Keyboard shortcuts

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