pearl

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: 11 Imported by: 0

Documentation

Overview

Package pearl provides some huninn components.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddTaskMsg

type AddTaskMsg struct {
	TaskListID int64
	ID         string
	Desc       string
}

AddTaskMsg is a message to add a new task.

If the id already exists, the task will not be added.

type Block

type Block struct {
	tapioca.Scrollable
	// contains filtered or unexported fields
}

Block is a component that displays lines of text with scrollable capabilities.

func NewBlock

func NewBlock() *Block

NewBlock creates a new Block component with horizontal and vertical scrolling enabled.

func (*Block) Init

func (b *Block) Init() tea.Cmd

func (*Block) SetContent added in v0.0.2

func (b *Block) SetContent(data ...string)

SetContent sets the content of the Block to the provided lines of text.

You should use it only when you are handling an event message.

func (*Block) Setter

func (b *Block) Setter(send func(tea.Msg)) func(...string)

Setter returns a function that sends a BlockSetContentMsg to update the Block's content.

func (*Block) Update

func (b *Block) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (*Block) UpdateInto

func (b *Block) UpdateInto(msg tea.Msg) (*Block, tea.Cmd)

func (*Block) View

func (b *Block) View() string

type BlockSetContentMsg

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

BlockSetContentMsg is a message type used to set the content of a Block component.

type BufferedBlock added in v0.0.2

type BufferedBlock struct {
	tapioca.Scrollable
	// contains filtered or unexported fields
}

BufferedBlock is the default implementation of a huninn component that provides scrollable text display functionality.

If you need proper control over text display, you might want to take a look at tapioca.Entry.

func NewBufferedBlock added in v0.0.2

func NewBufferedBlock(size int, hScroll, vScroll bool) *BufferedBlock

NewBufferedBlock creates a new component with the specified entry capacity. The size parameter determines how many entries the circular buffer can hold. When the buffer is full, adding new entries will overwrite the oldest ones.

func (*BufferedBlock) Append added in v0.0.2

func (c *BufferedBlock) Append(str string)

Append adds a new entry to the end of the virtual screen. In a log panel context, this would add a new log message at the bottom (older messages are shown by default since the viewport starts at position 0,0).

func (*BufferedBlock) Capacity added in v0.0.2

func (c *BufferedBlock) Capacity() int

Capacity returns the maximum number of entries the component can hold.

func (*BufferedBlock) Clear added in v0.0.2

func (c *BufferedBlock) Clear()

Clear removes all entries from the component.

func (*BufferedBlock) Entries added in v0.0.2

func (c *BufferedBlock) Entries() []*tapioca.Entry

Entries returns all entries currently stored in the component.

func (*BufferedBlock) Init added in v0.0.2

func (c *BufferedBlock) Init() tea.Cmd

Init implements the tea.Model interface.

func (*BufferedBlock) Prepend added in v0.0.2

func (c *BufferedBlock) Prepend(str string)

Prepend adds a new entry to the beginning of the virtual screen. In a log panel context, this would add a new log message at the top (newer messages are shown by default since the viewport starts at position 0,0).

func (*BufferedBlock) ResizeBuffer added in v0.0.2

func (c *BufferedBlock) ResizeBuffer(newSize int)

ResizeBuffer changes the capacity of the entries buffer to newSize.

func (*BufferedBlock) Update added in v0.0.2

func (c *BufferedBlock) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update implements the tea.Model interface. It handles ResizeMsg and scroll-related messages. When embedding this Component in your own model, you should forward ResizeMsg and scroll messages to this method while handling your own messages separately.

func (*BufferedBlock) UpdateInto added in v0.0.2

func (c *BufferedBlock) UpdateInto(msg tea.Msg) (*BufferedBlock, tea.Cmd)

UpdateInto is identical to Update, but returns a *Component instead of a tea.Model.

This is useful when embedding this Component in your own model, as it avoids the need for type assertions.

func (*BufferedBlock) View added in v0.0.2

func (c *BufferedBlock) View() string

View implements the tea.Model interface. It returns a string representation of the current viewport, applying the current scroll position and wrapping behavior based on the component's configuration.

type LogMsg

type LogMsg []byte

LogMsg denotes a logger has written a log message to LogPanel.

type LogPanel

type LogPanel struct {
	// if true, new log messages are placed at the top
	// by default, new log messages are placed at the bottom
	Reverse bool
	// contains filtered or unexported fields
}

LogPanel displays log messages in an area.

You must create LogPanel with NewLogPanel().

LogPanel does not support manually scrolling.

func NewLogPanel

func NewLogPanel(size int) *LogPanel

NewLogPanel creates a new LogPanel.

func (*LogPanel) CreateWriter

func (lp *LogPanel) CreateWriter(send func(tea.Msg), also io.Writer) io.Writer

CreateWriter returns an io.Writer that writes log messages to the given LogPanel.

The send function is used to send LogMsg messages to the Bubble Tea program.

If also is not nil, the returned io.Writer also writes to also.

You can use LogPanelWriter like this:

var logPanel *pearl.LogPanel
var logFile *os.File
...
logger := log.New(pearl.LogPanelWriter(logPanel, send, logFile), "", log.LstdFlags)
logger.Println("This log message is written to both logPanel and logFile")

func (*LogPanel) Init

func (lp *LogPanel) Init() tea.Cmd

func (*LogPanel) ScrollController added in v0.0.2

func (lp *LogPanel) ScrollController() tapioca.ScrollController

func (*LogPanel) Update

func (lp *LogPanel) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (*LogPanel) UpdateInto

func (lp *LogPanel) UpdateInto(msg tea.Msg) (*LogPanel, tea.Cmd)

UpdateInto is identical to Update, but returns *LogPanel instead of tea.Model.

func (*LogPanel) View

func (lp *LogPanel) View() string

type RemoveTaskMsg

type RemoveTaskMsg struct {
	TaskListID int64
	ID         string
}

RemoveTaskMsg is a message to remove a task.

If the id does not exist, the message will be ignored.

type Span added in v0.0.2

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

Span is a single line text box that can be used to display a single entry of text.

It warps the content to fit the width of the box, and truncates the content to fit the height of the box.

func NewSpan added in v0.0.2

func NewSpan() *Span

NewSpan creates a new Span.

func (*Span) Init added in v0.0.2

func (s *Span) Init() tea.Cmd

func (*Span) SetContent added in v0.0.2

func (s *Span) SetContent(data string)

SetContent sets the content of the span.

You should use it only when you are handling an event message.

func (*Span) Setter added in v0.0.2

func (s *Span) Setter(f func(tea.Msg)) func(string)

Setter returns a function that can be used to set the content of the span by sending a SpanSetContentMsg to bubble tea program.

func (*Span) Update added in v0.0.2

func (s *Span) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (*Span) UpdateInto added in v0.0.2

func (s *Span) UpdateInto(msg tea.Msg) (*Span, tea.Cmd)

UpdateInto is identical to Update but returns a *Span instead of tea.Model to prevent type assertion.

func (*Span) View added in v0.0.2

func (s *Span) View() string

type SpanSetContentMsg added in v0.0.2

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

type TaskController

type TaskController interface {
	SetDesc(desc string)
	SetState(state TaskState, progress float64)
	Done()
	Fail()
	Remove()
}

TaskController is used to control what info is shown for a task.

type TaskList

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

TaskList is a component that manages and displays a list of tasks with their states.

You might send task message by your own, or use TaskManager.

func NewTaskList

func NewTaskList() *TaskList

NewTaskList creates a new TaskList component.

func (*TaskList) CreateManager

func (tl *TaskList) CreateManager(send func(tea.Msg)) TaskManager

CreateManager creates a new TaskManager.

func (*TaskList) ID

func (t *TaskList) ID() int64

func (*TaskList) Init

func (l *TaskList) Init() tea.Cmd

func (*TaskList) Update

func (l *TaskList) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (*TaskList) View

func (l *TaskList) View() string

type TaskManager

type TaskManager interface {
	AddTask(desc, id string) TaskController
}

TaskManager is used to create and manage tasks.

func NopTaskManager added in v0.0.2

func NopTaskManager() TaskManager

NopTaskManager returns a TaskManager that does nothing.

This can be useful when you have to support both a UI and a non-UI mode.

type TaskState

type TaskState int

TaskState represents the current state of a task.

const (
	TaskPending TaskState = iota // task is pending
	TaskRunning                  // task is currently running
	TaskDone                     // task has completed successfully
	TaskFailed                   // task has failed

)

func (TaskState) IsValid

func (s TaskState) IsValid() bool

type UpdateTaskDescMsg

type UpdateTaskDescMsg struct {
	TaskListID int64
	ID         string
	Desc       string
}

UpdateTaskDescMsg is a message to update the description of a task.

If the id does not exist, the message will be ignored.

type UpdateTaskStateMsg

type UpdateTaskStateMsg struct {
	TaskListID int64
	ID         string
	State      TaskState

	// ignored if State is not TaskRunning
	// value between 0.0 and 1.0
	// if > 1.0, it will be set to 1.0
	// if < 0.0, hide progress counter
	Progress float64
}

UpdateTaskStateMsg is a message to update the state of a task.

If the id does not exist, the message will be ignored.

Jump to

Keyboard shortcuts

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