Documentation
¶
Overview ¶
Package sip serves Bubble Tea applications through a web browser.
Sip provides a simple way to make any Bubble Tea TUI application accessible through a web browser with full terminal emulation, mouse support, and hardware-accelerated rendering via xterm.js.
Basic usage:
server := sip.NewServer(sip.DefaultConfig())
server.Serve(context.Background(), func(sess sip.Session) (tea.Model, []tea.ProgramOption) {
pty := sess.Pty()
return myModel{width: pty.Width, height: pty.Height}, nil
})
Or with a ProgramHandler for more control:
server.ServeWithProgram(ctx, func(sess sip.Session) *tea.Program {
return tea.NewProgram(myModel{}, sip.MakeOptions(sess)...)
})
Index ¶
Constants ¶
const ( MsgInput = '0' // Terminal input (client -> server) MsgOutput = '1' // Terminal output (server -> client) MsgResize = '2' // Resize terminal MsgPing = '3' // Ping MsgPong = '4' // Pong MsgTitle = '5' // Set window title MsgOptions = '6' // Configuration options MsgClose = '7' // Session closed (server -> client) )
Message types for WebSocket/WebTransport communication.
Variables ¶
This section is empty.
Functions ¶
func MakeOptions ¶
func MakeOptions(sess Session) []tea.ProgramOption
MakeOptions returns tea.ProgramOptions configured for the web session. On Unix, this uses the PTY slave file for proper raw mode support. On Windows, this uses the Session's Reader/Writer interface with pipes.
func SetLogLevel ¶
SetLogLevel sets the logging verbosity for the sip package.
Types ¶
type CertInfo ¶
CertInfo holds generated certificate information.
func GenerateSelfSignedCert ¶
GenerateSelfSignedCert generates a self-signed TLS certificate for WebTransport. The certificate is valid for 10 days (Chrome requires < 14 days for serverCertificateHashes).
type CommandHandler ¶ added in v0.1.8
type CommandHandler struct {
// contains filtered or unexported fields
}
CommandHandler creates command sessions for each browser connection.
type Config ¶
type Config struct {
// Host to bind to (default: "localhost")
Host string
// Port to listen on (default: "7681")
Port string
// ReadOnly disables input from clients when true
ReadOnly bool
// MaxConnections limits concurrent connections (0 = unlimited)
MaxConnections int
// IdleTimeout for connections (0 = no timeout)
IdleTimeout time.Duration
// AllowOrigins for CORS (empty = all origins allowed)
AllowOrigins []string
// TLSCert path to TLS certificate (enables HTTPS)
TLSCert string
// TLSKey path to TLS private key
TLSKey string
// Debug enables verbose logging
Debug bool
}
Config holds the web server configuration.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns sensible default configuration.
type Handler ¶
type Handler func(sess Session) (tea.Model, []tea.ProgramOption)
Handler is the function Bubble Tea apps implement to hook into sip. This will create a new tea.Program for every browser connection and start it with the tea.ProgramOptions returned.
type OptionsMessage ¶
type OptionsMessage struct {
ReadOnly bool `json:"readOnly"`
}
OptionsMessage is sent to configure the terminal.
type ProgramHandler ¶
ProgramHandler allows creating custom tea.Program instances. Use this for more control over program initialization. Make sure to use MakeOptions to properly configure I/O.
type ResizeMessage ¶
ResizeMessage is sent when the terminal should be resized.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server represents the web terminal server.
func (*Server) Serve ¶
Serve starts the server and serves the Bubble Tea application. The handler is called for each new browser session to create a model. This method blocks until the context is cancelled.
func (*Server) ServeCommand ¶ added in v0.1.8
ServeCommand starts the server and runs the specified command for each connection. This is used by the CLI to wrap arbitrary commands and expose them via the browser.
func (*Server) ServeWithProgram ¶
func (s *Server) ServeWithProgram(ctx context.Context, handler ProgramHandler) error
ServeWithProgram starts the server with a custom ProgramHandler. Use this for more control over tea.Program creation.
type Session ¶
type Session interface {
// Pty returns the pseudo-terminal information for this session.
Pty() Pty
// Context returns the session's context, which is cancelled when the
// session ends.
Context() context.Context
// Read reads input from the web terminal.
Read(p []byte) (n int, err error)
// Write writes output to the web terminal.
Write(p []byte) (n int, err error)
// Fd returns the file descriptor for TTY detection.
// This is required for Bubble Tea to properly detect terminal mode.
Fd() uintptr
// PtySlave returns the underlying PTY slave file for direct I/O.
// Bubble Tea requires the actual *os.File to set raw mode properly.
PtySlave() *os.File
// WindowChanges returns a channel that receives window size changes.
WindowChanges() <-chan WindowSize
}
Session represents a web terminal session, similar to ssh.Session in Wish. It provides access to terminal dimensions and other session metadata.
type WindowSize ¶
WindowSize represents a terminal window size change.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
sip
command
Command sip wraps any CLI command and exposes it through a web browser.
|
Command sip wraps any CLI command and exposes it through a web browser. |
|
examples
|
|
|
simple
command
Simple example showing how to serve a Bubble Tea app through the browser.
|
Simple example showing how to serve a Bubble Tea app through the browser. |