Documentation
¶
Overview ¶
Package canvas provides IPC communication for TUI applications. It allows AI assistants to query and control TUI state via Unix sockets.
Index ¶
- func DefaultSocketDir() string
- func SocketPath(id string) string
- func Wrap(canvasID string, model tea.Model) tea.Model
- type BubbleTeaAdapter
- func (a *BubbleTeaAdapter) CanvasState() StatePayload
- func (a *BubbleTeaAdapter) CanvasView() string
- func (a *BubbleTeaAdapter) HandleCanvasInput(text string) error
- func (a *BubbleTeaAdapter) HandleCanvasKey(key string, r rune) error
- func (a *BubbleTeaAdapter) Init() tea.Cmd
- func (a *BubbleTeaAdapter) Update(msg tea.Msg) (tea.Model, tea.Cmd)
- func (a *BubbleTeaAdapter) View() string
- type Client
- type ErrorPayload
- type InputHandler
- type InputPayload
- type KeyHandler
- type KeyPayload
- type Message
- type MessageType
- type Server
- type StatePayload
- type StateProvider
- type ViewPayload
- type ViewProvider
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultSocketDir ¶
func DefaultSocketDir() string
DefaultSocketDir returns the default directory for canvas sockets
func SocketPath ¶
SocketPath returns the socket path for a canvas ID
Types ¶
type BubbleTeaAdapter ¶
type BubbleTeaAdapter struct {
// contains filtered or unexported fields
}
func (*BubbleTeaAdapter) CanvasState ¶
func (a *BubbleTeaAdapter) CanvasState() StatePayload
func (*BubbleTeaAdapter) CanvasView ¶
func (a *BubbleTeaAdapter) CanvasView() string
func (*BubbleTeaAdapter) HandleCanvasInput ¶
func (a *BubbleTeaAdapter) HandleCanvasInput(text string) error
func (*BubbleTeaAdapter) HandleCanvasKey ¶
func (a *BubbleTeaAdapter) HandleCanvasKey(key string, r rune) error
func (*BubbleTeaAdapter) Init ¶
func (a *BubbleTeaAdapter) Init() tea.Cmd
func (*BubbleTeaAdapter) View ¶
func (a *BubbleTeaAdapter) View() string
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client connects to a canvas server to query/control it
func NewClientWithSocket ¶
NewClientWithSocket creates a client with a custom socket path
func (*Client) GetState ¶
func (c *Client) GetState() (*StatePayload, error)
GetState queries the canvas for its current state
type ErrorPayload ¶
ErrorPayload contains error information
type InputHandler ¶
type InputHandler interface {
// HandleCanvasInput processes text input sent via IPC
HandleCanvasInput(text string) error
}
InputHandler is implemented by TUI models to receive text input
type InputPayload ¶
type InputPayload struct {
Text string `json:"text"`
}
InputPayload contains text input
type KeyHandler ¶
type KeyHandler interface {
// HandleCanvasKey processes a key sent via IPC
HandleCanvasKey(key string, r rune) error
}
KeyHandler is implemented by TUI models to receive key events
type KeyPayload ¶
type KeyPayload struct {
Key string `json:"key"` // e.g., "enter", "tab", "ctrl+c"
Rune rune `json:"rune,omitempty"` // for character input
}
KeyPayload contains a key to send
type Message ¶
type Message struct {
Type MessageType `json:"type"`
Payload json.RawMessage `json:"payload,omitempty"`
}
Message is the base IPC message structure
func NewMessage ¶
func NewMessage(t MessageType, payload any) (*Message, error)
NewMessage creates a new message with the given type and payload
func (*Message) ParsePayload ¶
ParsePayload unmarshals the payload into the given type
type MessageType ¶
type MessageType string
MessageType identifies the type of IPC message
const ( // Queries (AI → TUI) MsgGetState MessageType = "get_state" MsgGetView MessageType = "get_view" MsgSendKey MessageType = "send_key" MsgSendInput MessageType = "send_input" MsgClose MessageType = "close" // Responses (TUI → AI) MsgState MessageType = "state" MsgView MessageType = "view" MsgAck MessageType = "ack" MsgError MessageType = "error" // Events (TUI → AI, async) MsgReady MessageType = "ready" MsgUpdated MessageType = "updated" MsgSelected MessageType = "selected" MsgCancelled MessageType = "cancelled" )
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server handles IPC communication for a TUI
func (*Server) OnClose ¶
func (s *Server) OnClose(fn func())
OnClose sets a callback for when a close message is received
func (*Server) SendEvent ¶
func (s *Server) SendEvent(msgType MessageType, payload any) error
SendEvent sends an async event to any connected client
func (*Server) SocketPath ¶
SocketPath returns the path to the Unix socket
type StatePayload ¶
type StatePayload struct {
// Custom fields from the TUI's model
Custom map[string]any `json:"custom,omitempty"`
// Standard fields
Width int `json:"width,omitempty"`
Height int `json:"height,omitempty"`
Focused bool `json:"focused,omitempty"`
Mode string `json:"mode,omitempty"`
Input string `json:"input,omitempty"`
Cursor int `json:"cursor,omitempty"`
}
StatePayload contains the TUI's current state
type StateProvider ¶
type StateProvider interface {
// CanvasState returns the current state for IPC queries
CanvasState() StatePayload
}
StateProvider is implemented by TUI models to expose their state
type ViewPayload ¶
type ViewPayload struct {
Content string `json:"content"`
ANSI bool `json:"ansi"` // true if content contains ANSI codes
}
ViewPayload contains the rendered view
type ViewProvider ¶
type ViewProvider interface {
// CanvasView returns the current rendered view
CanvasView() string
}
ViewProvider is implemented by TUI models to expose their rendered view