tui

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewTUILogger

func NewTUILogger(eventBus runner.EventBus, level slog.Level) *slog.Logger

NewTUILogger creates a logger that sends logs to both the TUI and stderr.

func NewTUILoggerWithFallback

func NewTUILoggerWithFallback(eventBus runner.EventBus, level slog.Level, fallback slog.Handler) *slog.Logger

NewTUILoggerWithFallback creates a logger that sends logs to the TUI and also to a text handler for debugging.

Types

type ChatHandler

type ChatHandler interface {
	DirectChat(content string) (response string, model string, tokens int, err error)
}

ChatHandler is the interface for sending chat messages. This is implemented by the Runner/MessageHandler.

type ChatResponseMsg

type ChatResponseMsg struct {
	Content string
	Model   string
	Tokens  int
	Error   error
}

ChatResponseMsg is sent when a direct chat response is received.

type EventMsg

type EventMsg struct {
	Event runner.Event
}

EventMsg wraps a runner.Event for Bubble Tea's message system.

type LogHandler

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

LogHandler is an slog.Handler that emits LogEvents to an EventBus. It also forwards logs to an underlying handler if provided.

func NewLogHandler

func NewLogHandler(eventBus runner.EventBus, underlying slog.Handler, level slog.Level) *LogHandler

NewLogHandler creates a new LogHandler that emits to the given EventBus. If underlying is provided, logs are also forwarded there.

func (*LogHandler) Enabled

func (h *LogHandler) Enabled(_ context.Context, level slog.Level) bool

Enabled reports whether the handler handles records at the given level.

func (*LogHandler) Handle

func (h *LogHandler) Handle(ctx context.Context, r slog.Record) error

Handle processes a log record.

func (*LogHandler) WithAttrs

func (h *LogHandler) WithAttrs(attrs []slog.Attr) slog.Handler

WithAttrs returns a new handler with the given attributes.

func (*LogHandler) WithGroup

func (h *LogHandler) WithGroup(name string) slog.Handler

WithGroup returns a new handler with the given group name.

type MessagingHandler

type MessagingHandler interface {
	PublishMessage(topic string, data []byte) error
	RequestMessage(topic string, data []byte) ([]byte, error)
	WatchTopic(topic string, callback WatchCallback) error
	StopWatching() error
	WatchingTopic() string
}

MessagingHandler is the interface for sending messages to topics. This is implemented by the Runner/MessageHandler.

type MessagingResponseMsg

type MessagingResponseMsg struct {
	Response []byte
	Error    error
}

MessagingResponseMsg is sent when a messaging request response is received.

type Model

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

Model is the root Bubble Tea model for the TUI.

func NewModel

func NewModel(cfg *config.Config, eventBus runner.EventBus, serverAddr string) Model

NewModel creates a new root Model.

func (Model) Init

func (m Model) Init() tea.Cmd

Init implements tea.Model.

func (*Model) SetChatHandler

func (m *Model) SetChatHandler(h ChatHandler)

SetChatHandler sets the handler for sending chat messages.

func (*Model) SetMessagingHandler

func (m *Model) SetMessagingHandler(h MessagingHandler)

SetMessagingHandler sets the handler for sending messages to topics.

func (*Model) SetProgram

func (m *Model) SetProgram(p *tea.Program)

SetProgram sets the tea.Program reference for sending async messages.

func (Model) Update

func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update implements tea.Model.

func (Model) View

func (m Model) View() string

View implements tea.Model.

type Options

type Options struct {
	Config           *config.Config
	EventBus         runner.EventBus
	ChatHandler      ChatHandler
	MessagingHandler MessagingHandler
	ServerAddr       string // Athyr server address
}

Options configures the TUI.

type SetChatHandlerMsg

type SetChatHandlerMsg struct {
	Handler ChatHandler
}

SetChatHandlerMsg is sent to set the chat handler from outside the event loop.

type SetMessagingHandlerMsg

type SetMessagingHandlerMsg struct {
	Handler MessagingHandler
}

SetMessagingHandlerMsg is sent to set the messaging handler from outside the event loop.

type TUI

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

TUI wraps the Bubble Tea program and provides a high-level interface.

func New

func New(opts Options) (*TUI, error)

New creates a new TUI instance.

func (*TUI) Quit

func (t *TUI) Quit()

Quit gracefully quits the TUI.

func (*TUI) Run

func (t *TUI) Run() error

Run starts the TUI and blocks until it exits.

func (*TUI) Send

func (t *TUI) Send(msg tea.Msg)

Send sends a message to the TUI program. This can be used to inject events from outside.

func (*TUI) SetChatHandler

func (t *TUI) SetChatHandler(h ChatHandler)

SetChatHandler sets the chat handler after creation. This sends a message through Bubble Tea's event loop to ensure the handler is set on the actual model instance being used.

func (*TUI) SetMessagingHandler

func (t *TUI) SetMessagingHandler(h MessagingHandler)

SetMessagingHandler sets the messaging handler after creation. This sends a message through Bubble Tea's event loop to ensure the handler is set on the actual model instance being used.

type WatchCallback

type WatchCallback func(timestamp time.Time, content string)

WatchCallback is the function signature for receiving watch messages.

type WatchMessageMsg

type WatchMessageMsg struct {
	Timestamp time.Time
	Content   string
}

WatchMessageMsg is sent when a message is received on a watched topic.

type WatchStatusMsg

type WatchStatusMsg struct {
	Topic string // Empty if stopped
	Error error  // Non-nil if failed
}

WatchStatusMsg is sent when watch status changes (started, stopped, error).

type WindowSizeMsg

type WindowSizeMsg struct {
	Width  int
	Height int
}

WindowSizeMsg wraps terminal size updates.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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