webshell

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package webshell is an in-memory terminal and a small fake shell for the browser build of tuios, where there is no kernel pty and no process to exec.

A Pty stands in for xpty.Pty: the window writes keystrokes to it and reads the guest's output back, exactly as it would with a real pseudo-terminal. Start runs a Go program in place of the command the window asked for. The package is pure Go and has no build tags, so it is tested natively.

Index

Constants

View Source
const (
	// EventCommandStart is a command line starting at the prompt. Data:
	// command, line, cwd.
	EventCommandStart = "shell.start"
	// EventCommand is a command line that finished. Data: command, line, cwd,
	// exitCode (an int).
	EventCommand = "shell.command"
	// EventCwd is the shell changing directory. Data: cwd.
	EventCwd = "shell.cwd"
	// EventAgentReport is the fake agent reporting its state, for tuios and
	// not for the page: the browser build turns it into app.AgentReportMsg.
	// Data: state, message, kind, harness.
	EventAgentReport = "agent.report"
	// EventTapePlay asks tuios to play a tape, from `tuios tape play`. The
	// browser build turns it into app.PlayTapeMsg. Data: name, script.
	EventTapePlay = "tape.play"
)

The events guests emit.

View Source
const AgentHarness = "claude-code"

AgentHarness is the harness id the fake agent reports as.

View Source
const ConfigPath = Home + "/.config/tuios/config.toml"

ConfigPath is the fake tuios config file.

View Source
const Home = "/home/guest"

Home is the fake user's home directory.

View Source
const ProjectDir = Home + "/projects/hello"

ProjectDir is the tiny Go project, which is also the fake git repository.

Variables

This section is empty.

Functions

func SetEventSink

func SetEventSink(fn func(Event))

SetEventSink installs the function guests report events to. The wasm entry point forwards them to the page.

func WriteConfig

func WriteConfig(theme, border, glyphs string)

WriteConfig rewrites the config file to match the looks the tour is showing, so cat config.toml shows what the reader picked.

Types

type Event

type Event struct {
	Type     string         `json:"type"`
	WindowID string         `json:"windowId,omitempty"`
	Data     map[string]any `json:"data,omitempty"`
}

Event is something a guest did that a guided tour may want to know about, such as a command the user ran at the fake shell.

type Program

type Program struct {
	Name    string
	Summary string
}

Program is one command the shell runs, for a launcher to list.

func Programs

func Programs() []Program

Programs lists the commands worth starting as a pane of their own: the full-screen and long-running ones. The browser build offers them in the tuios launcher in place of $PATH.

type Pty

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

Pty is an in-memory pseudo-terminal. It satisfies xpty.Pty.

func NewPty

func NewPty(cols, rows int) *Pty

NewPty makes a pty of the given size with nothing running on it.

func (*Pty) Close

func (p *Pty) Close() error

Close ends the guest and unblocks both directions.

func (*Pty) Fd

func (p *Pty) Fd() uintptr

Fd has no descriptor to return. term.IsTerminal says no to it.

func (*Pty) Name

func (p *Pty) Name() string

Name is what a tty(1) would print.

func (*Pty) Read

func (p *Pty) Read(b []byte) (int, error)

Read returns what the guest wrote.

func (*Pty) Resize

func (p *Pty) Resize(cols, rows int) error

Resize changes the size and tells the guest, the way SIGWINCH would.

func (*Pty) Size

func (p *Pty) Size() (int, int, error)

Size reports the current size.

func (*Pty) Start

func (p *Pty) Start(cmd *exec.Cmd) error

Start runs the program cmd names in place of cmd. Anything unknown runs the shell, since the window asked for the user's shell.

func (*Pty) Wait

func (p *Pty) Wait() error

Wait blocks until the guest exits, and returns nil for a zero status.

func (*Pty) Write

func (p *Pty) Write(b []byte) (int, error)

Write delivers input to the guest.

type TTY

type TTY struct {
	In <-chan []byte
	// contains filtered or unexported fields
}

TTY is what a guest program sees: input as chunks, output, and the size.

func (*TTY) Emit

func (t *TTY) Emit(typ string, data map[string]any)

Emit reports an event from this guest's window.

func (*TTY) Lay added in v0.10.1

func (t *TTY) Lay(lay func(cols int) []string)

Lay prints lines laid out for the pane width, each on a line of its own. When the pane changes width, the shell calls lay again to draw them for the new one, so lay must print nothing itself and give the same lines for the same width.

func (*TTY) Print

func (t *TTY) Print(s string)

Print writes a string.

func (*TTY) Printf

func (t *TTY) Printf(format string, args ...any)

Printf writes a formatted string.

func (*TTY) Resized

func (t *TTY) Resized() <-chan struct{}

Resized fires after the window changes size.

func (*TTY) Size

func (t *TTY) Size() (cols, rows int)

Size is the window size in cells.

Jump to

Keyboard shortcuts

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