Help us shape the future of Go! Take the 2026 Go Developer Survey

vm

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: BSD-3-Clause Imports: 25 Imported by: 0

Documentation

Overview

Package vm holds the dashboard's viewmodels: pure Go state over the engine.Engine interface, natively testable, with no widget in sight. The views (package ui) bind to the observables here and call the actions; every action goes through the engine's API, so the terminal and any other client see its effect, and each one names the wctr command line it stands for.

Threading: observables are touched on one goroutine only, the UI's. Work that waits on the engine runs on its own goroutine and hands its result back through the post function the App is given (an mvvm.Queue's Post in the browser, drained at the start of each frame).

Index

Constants

View Source
const (
	ViewContainers = iota
	ViewImages
	ViewVolumes
	ViewNetworks
	ViewTerminal
	ViewSurfaces
	NumViews
)

The views, in navigation order.

View Source
const (
	ColName = iota
	ColImage
	ColState
	ColStatus
	ColCreated
	ColID
	NumContainerCols
)

Container table columns.

View Source
const (
	ColRef = iota
	ColImageID
	ColDigest
	ColSize
	ColImageCreated
	NumImageCols
)

Image table columns.

View Source
const (
	PointerDown = "pointer-down"
	PointerUp   = "pointer-up"
	PointerMove = "pointer-move"
	KeyDown     = "key-down"
	KeyUp       = "key-up"
)

The kinds of a surface input event (go-wasmcontainers/gpu webgpu.InputKinds).

View Source
const (
	DefaultSurfaceW, DefaultSurfaceH = 640, 480
	MaxSurfaceW, MaxSurfaceH         = 1920, 1080
	MaxSurfaces                      = 16
)

Surface limits: the size a surface opens at when it says none, the largest one accepted, how many panes there can be, and how many presentation times the frame-rate window keeps.

View Source
const (
	VolumesUnknown = iota
	VolumesUnsupported
	VolumesSupported
)

Volume support, as the engine answered.

View Source
const MaxContainers = 2000

MaxContainers bounds the rows the dashboard keeps.

View Source
const MaxHistory = 60

MaxHistory bounds the memory readings kept for the sparkline.

View Source
const MaxImages = 2000

MaxImages bounds the rows kept.

View Source
const PollInterval = 2 * time.Second

PollInterval is how often the dashboard refreshes when the engine has no event stream.

Variables

View Source
var (
	ReconnectDelay    = 200 * time.Millisecond
	MaxReconnectDelay = 5 * time.Second
)

Reconnection delays of the event stream: the first retry, and the most it backs off to while the stream keeps ending without an event.

View Source
var Builtins = []cli.Candidate{
	{Value: "wctr", Description: "the container CLI"},
	{Value: "help", Description: "what this terminal does"},
	{Value: "clear", Description: "clear the screen"},
}

Builtins are the shell's own words, for completion.

View Source
var ContainerColumns = [NumContainerCols]string{"Name", "Image", "State", "Status", "Created", "ID"}

ContainerColumns are the column titles.

View Source
var ImageColumns = [NumImageCols]string{"Repository:Tag", "Image ID", "Digest", "Size", "Created"}

ImageColumns are the column titles.

View Source
var NetworkColumns = []string{"Name", "ID", "Driver", "Subnet", "Containers"}

NetworkColumns are the column titles.

View Source
var ShellCmd = []string{"/bin/sh"}

ShellCmd is what Open runs in the container. (An exec into a container that has started but has no process yet waits for it in the engine, v0.29.1, so there is nothing to retry here.)

View Source
var ViewNames = [NumViews]string{"Containers", "Images", "Volumes", "Networks", "Terminal", "Surfaces"}

ViewNames are the navigation labels.

View Source
var VolumeColumns = []string{"Name", "Driver", "Mountpoint", "Created", "Size", "Used by"}

VolumeColumns are the column titles.

Functions

func Ago

func Ago(now, t time.Time) string

Ago renders the time since t the way `wctr ps` does.

func Clean

func Clean(s string, max int) string

Clean makes a container-provided string safe to show as one line of text: control characters (C0, DEL, C1) and Unicode format characters (bidi overrides, zero-width joiners) become U+FFFD or are dropped, and the result is bounded to max runes. Names, labels, commands and images all come from the container's side; nothing of theirs is interpreted.

func Line

func Line(args ...string) string

Line renders "wctr <args...>" with each argument quoted.

func Quote

func Quote(s string) string

Quote quotes one word for a POSIX shell when it needs it, so a command line shown as a teaching aid can be pasted as is.

func RelayOrigin added in v0.5.0

func RelayOrigin(s string) (string, error)

RelayOrigin turns what the user typed into the relay's origin, https://host[:port]. A wss:// address names the same relay (its data channel) and maps to https://. Anything else is refused: another scheme, a user or password, a path, a query, a fragment, a host a name cannot be, a port out of range — the origin goes into the engine worker's URL and its CSP, so it must be exactly an origin.

func ShortID

func ShortID(id string) string

ShortID is the 12-character form of an ID (a "sha256:" prefix dropped).

func Size

func Size(n int64) string

Size renders bytes the way `wctr images` does.

func Sync

func Sync[T comparable](l *mvvm.ObservableList[T], want []T, key func(T) string)

Sync makes l equal to want with as few list events as it can: rows are matched by key, a row that did not change emits nothing, a changed one one Set, a moved one one Move. A refresh that finds the engine as it was therefore costs no event and no redraw. Keys must be unique in want.

func ToSurface added in v0.8.0

func ToSurface(img Box, w, h, px, py int) (x, y float64, ok bool)

ToSurface maps canvas pixel (px, py) to surface pixels, for a surface of w×h drawn in img: the centre of the canvas pixel, scaled. A point outside the image (the letterbox, or outside the pane) is not the surface's: ok is false.

Types

type App

type App struct {

	// View is the navigation selection (ViewContainers ...).
	View *mvvm.Observable[int]
	// LastCommand is the wctr command line the last action stands for.
	LastCommand *mvvm.Observable[string]
	// Error is the last failure, "" when the last action succeeded.
	Error *mvvm.Observable[string]
	// EngineVersion, Summary and Storage feed the status bar.
	EngineVersion *mvvm.Observable[string]
	Summary       *mvvm.Observable[string]
	Storage       *mvvm.Observable[string]
	// Live says how the dashboard keeps up: "live (events)" or polling.
	Live *mvvm.Observable[string]

	Containers *Containers
	Images     *Images
	Volumes    *Volumes
	Networks   *Networks
	Class      *Class
	Surfaces   *Surfaces
	Detail     *Detail
	Terminal   *Terminal
	// ExecShell is the shell inside the shown container (`wctr exec -it`).
	ExecShell *ExecShell

	// Refreshed counts completed refreshes (tests wait on it).
	Refreshed *mvvm.Observable[int]
	// Pending counts actions under way (the view shows it busy).
	Pending *mvvm.Observable[int]
	// contains filtered or unexported fields
}

App is the dashboard's root viewmodel.

func NewApp

func NewApp(eng engine.Engine, cli *CLI, post func(func())) *App

NewApp builds the viewmodels over eng. cli is the wctr command tree (for the command lines shown), post runs a function on the UI goroutine.

func (*App) CLI

func (a *App) CLI() *CLI

CLI is the wctr command tree the command lines are checked against.

func (*App) Do

func (a *App) Do(line string, fn func(ctx context.Context) error)

Do runs an action against the engine in the background: line is the wctr command line it stands for (shown, and echoed in the terminal when asked), fn the API calls. The dashboard refreshes when it is done.

func (*App) Refresh

func (a *App) Refresh()

Refresh re-reads the engine in the background and applies what changed. Calls while one is running coalesce into one more.

func (*App) Refreshing

func (a *App) Refreshing() bool

Refreshing reports whether a refresh is under way (or queued).

func (*App) RunLive

func (a *App) RunLive(ctx context.Context, interval time.Duration)

RunLive keeps the dashboard current until ctx ends. It follows the engine's event stream (GET /events), refreshing on each event. When the stream ends — the engine cuts off a slow reader, or the connection breaks — it resynchronises (a full refresh) and reconnects from the time of the last event it saw, backing off while the stream keeps failing. An engine that serves no event stream is polled every interval instead.

func (*App) SetClock

func (a *App) SetClock(now func() time.Time)

SetClock replaces the clock (tests).

type Box added in v0.8.0

type Box struct{ X, Y, W, H int }

Box is a rectangle in canvas pixels.

func Fit added in v0.8.0

func Fit(b Box, w, h int) Box

Fit is the largest box of aspect w:h centred in b: where a surface's frame is drawn in its pane (letterboxed), and where its input is read.

type CLI

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

CLI knows which commands the wctr in use has, so the dashboard shows the command line a button stands for, or, where wctr has no such command yet, the API call it makes.

func NewCLI

func NewCLI(root *cobra.Command) *CLI

NewCLI reads the command tree of root (wctr's cli.RootCmd).

func (*CLI) Equivalent

func (c *CLI) Equivalent(api string, args ...string) string

Equivalent is the command line for the wctr command args[0], or, when wctr has no such command, the API call (method and path) with a note.

func (*CLI) Has

func (c *CLI) Has(name string) bool

Has reports whether wctr has the command name.

type Class added in v0.5.0

type Class struct {

	// Available says whether this page can join a class at all.
	Available *mvvm.Observable[bool]
	// Open is the dialog's visibility.
	Open *mvvm.Observable[bool]
	// RelayInput, Name and Code are the dialog's fields.
	RelayInput, Name, Code *mvvm.Observable[string]
	// Relay is the relay the engine runs with ("" none: the dialog asks
	// for one first).
	Relay *mvvm.Observable[string]
	// Status is the last report; Busy while a join or leave is under way.
	Status *mvvm.Observable[ClassStatus]
	Busy   *mvvm.Observable[bool]
	// Error is the dialog's message.
	Error *mvvm.Observable[string]
	// contains filtered or unexported fields
}

Class is the "Join class" dialog and status. The join code is a secret: it lives in Code only until Join, is never part of a command line, a message, a log or the test hook, and is cleared whether or not the join succeeds.

func (*Class) Cancel added in v0.5.0

func (c *Class) Cancel()

Cancel closes the dialog and forgets the code.

func (*Class) ChangeRelay added in v0.5.0

func (c *Class) ChangeRelay()

ChangeRelay forgets the relay (the engine restarts without it).

func (*Class) Continue added in v0.5.0

func (c *Class) Continue()

Continue validates the relay address and restarts the engine with it.

func (*Class) Join added in v0.5.0

func (c *Class) Join()

Join sends the code and the name. The code leaves Code at once.

func (*Class) Leave added in v0.5.0

func (c *Class) Leave()

Leave leaves the class.

func (*Class) Report added in v0.5.0

func (c *Class) Report(st ClassStatus)

Report applies a status from the engine. Every string is the engine's and is cleaned; an error never carries the code (the engine's rule, and the code is not kept here to leak).

func (*Class) SetHost added in v0.5.0

func (c *Class) SetHost(h ClassHost)

SetHost connects the page; nil leaves the feature unavailable.

func (*Class) Show added in v0.5.0

func (c *Class) Show()

Show opens the dialog.

func (*Class) Summary added in v0.5.0

func (c *Class) Summary() string

Summary is the one-line status ("" when not in a class).

type ClassHost added in v0.5.0

type ClassHost interface {
	// Relay is the relay origin the engine was started with ("" none).
	Relay() string
	// UseRelay remembers origin (not a secret) and restarts the engine
	// with it ("" forgets it); the page reloads.
	UseRelay(origin string) error
	// Join sends the join code, once, with the name asked for.
	Join(code, name string) error
	// Leave leaves the class.
	Leave() error
}

ClassHost is the page around the dashboard, which owns the engine worker: the relay it was started with, restarting it with another, and the join and leave messages. Status reports come back through App.Class.Report. A host that cannot join a class is nil.

type ClassStatus added in v0.5.0

type ClassStatus struct {
	// State is "joined", "left", "error", or "" before any report.
	State                                 string
	Relay, Label, Domain, Network, Subnet string
	Error                                 string
}

ClassStatus is what the engine reports about the class (the engine worker's {t:"class"} message).

type ContainerRow

type ContainerRow struct {
	ID, Name, Image, Command string
	State, Status, Created   string
	CreatedAt                int64
}

ContainerRow is one container as the table shows it. Every string is already cleaned (see Clean).

func (ContainerRow) Cells

func (r ContainerRow) Cells() []string

Cells is the row as table cells, in ContainerColumns order.

func (ContainerRow) ExitCode

func (r ContainerRow) ExitCode() (int, bool)

ExitCode parses the exit status out of an "Exited (N) …" status.

func (ContainerRow) Ref

func (r ContainerRow) Ref() string

Ref is the name the command lines use: the name, else the short ID.

func (ContainerRow) Running

func (r ContainerRow) Running() bool

Running reports whether the container runs.

func (ContainerRow) Short

func (r ContainerRow) Short() string

Short is the 12-character ID.

type Containers

type Containers struct {

	// Rows are the containers shown (filtered, sorted).
	Rows *mvvm.ObservableList[ContainerRow]
	// ShowAll shows stopped containers too (`wctr ps -a`).
	ShowAll *mvvm.Observable[bool]
	// Search filters by name, image, ID or command.
	Search *mvvm.Observable[string]
	// SortCol / SortAsc order the rows.
	SortCol *mvvm.Observable[int]
	SortAsc *mvvm.Observable[bool]
	// Selected is the selected container's ID ("" for none).
	Selected *mvvm.Observable[string]
	// contains filtered or unexported fields
}

Containers is the containers view.

func (*Containers) Counts

func (c *Containers) Counts() (running, total int)

Counts is how many containers run and exist.

func (*Containers) Find

func (c *Containers) Find(id string) (ContainerRow, bool)

Find returns the row of the container with id (any shown or hidden).

func (*Containers) Remove

func (c *Containers) Remove(r ContainerRow)

Remove removes the container (forced when it runs).

func (*Containers) RemoveLine

func (c *Containers) RemoveLine(r ContainerRow) string

RemoveLine is rm, forced for a running container.

func (*Containers) Restart

func (c *Containers) Restart(r ContainerRow)

Restart stops the container if it runs and starts it again.

func (*Containers) RestartLine

func (c *Containers) RestartLine(r ContainerRow) string

RestartLine is `wctr restart`.

func (*Containers) Start

func (c *Containers) Start(r ContainerRow)

Start starts the container.

func (*Containers) StartLine

func (c *Containers) StartLine(r ContainerRow) string

StartLine, StopLine, RestartLine and RemoveLine are the command lines the actions stand for.

func (*Containers) Stop

func (c *Containers) Stop(r ContainerRow)

Stop stops the container; the engine answers once it has exited, so the refresh that follows shows it stopped.

func (*Containers) StopLine

func (c *Containers) StopLine(r ContainerRow) string

StopLine is `wctr stop` (a wasm guest has no signals: it stops at once).

type Detail

type Detail struct {

	// ID is the container shown ("" for none).
	ID    *mvvm.Observable[string]
	Title *mvvm.Observable[string]
	State *mvvm.Observable[string]
	Tree  *mvvm.ObservableList[InspectNode]
	Env   *mvvm.ObservableList[string]
	// Mounts lists "source -> destination"; empty with a note when none.
	Mounts *mvvm.ObservableList[string]
	// Networks lists "network address (dns names)", one per network the
	// container is on (addresses while it runs).
	Networks *mvvm.ObservableList[string]
	// Follow streams new log output as it comes (`wctr logs -f`).
	Follow *mvvm.Observable[bool]
	// LogsLine is the command line the logs pane stands for.
	LogsLine *mvvm.Observable[string]

	// LogOut receives log output (already demultiplexed; stderr in red)
	// and LogReset clears the log pane; both are set by the view and
	// called on the UI goroutine.
	LogOut   func([]byte)
	LogReset func()

	// Stats: Memory is the share of the memory limit in use (0..1, -1 when
	// unknown), MemoryText the same in bytes, MemHistory the last readings
	// (bytes, oldest first, bounded), CPU "--" (the engine does not measure
	// it) with CPUNote saying why, and the other counters as text.
	Memory     *mvvm.Observable[float64]
	MemoryText *mvvm.Observable[string]
	MemHistory *mvvm.ObservableList[float64]
	CPU        *mvvm.Observable[string]
	CPUNote    *mvvm.Observable[string]
	Counters   *mvvm.Observable[string]
	StatsLine  *mvvm.Observable[string]
	// contains filtered or unexported fields
}

Detail is the container detail pane: inspect tree, environment, mounts, logs.

func (*Detail) Close

func (d *Detail) Close()

Close stops the log stream and clears the pane.

func (*Detail) Open

func (d *Detail) Open(id string)

Open shows container id: inspects it and streams its logs.

type ExecShell added in v0.7.0

type ExecShell struct {

	// Line is the command line this stands for; Status says how it goes:
	// starting, running, "exited with status N", or the engine's error.
	Line    *mvvm.Observable[string]
	Status  *mvvm.Observable[string]
	Running *mvvm.Observable[bool]
	// Container is the ID of the container the shell is in ("" none).
	Container *mvvm.Observable[string]

	// Out receives the output and Reset clears the terminal; both are set
	// by the view and called on the UI goroutine.
	Out   func([]byte)
	Reset func()
	// contains filtered or unexported fields
}

ExecShell is an interactive shell inside a container (`wctr exec -it CONTAINER sh`): POST /containers/{id}/exec with a terminal, then /exec/{id}/start with the keys as stdin and the raw output streamed back. The engine does the line discipline and echo; the view's terminal shows the output (its screen discards every OSC/DCS/APC string) and hands the keys back as bytes.

func (*ExecShell) Close added in v0.7.0

func (sh *ExecShell) Close()

Close hangs up the shell, if one runs.

func (*ExecShell) Input added in v0.7.0

func (sh *ExecShell) Input(keys string)

Input sends keys (the terminal's bytes) to the shell. Keys typed before it runs wait (bounded); past the bound they are dropped, and said so.

func (*ExecShell) Open added in v0.7.0

func (sh *ExecShell) Open(id, name string)

Open starts a shell in container id (shown as name), at the terminal's size. A shell already running there is kept.

func (*ExecShell) Resize added in v0.7.0

func (sh *ExecShell) Resize(cols, rows int)

Resize follows the terminal's size, and tells a running shell.

type Frame added in v0.6.0

type Frame interface{ Close() }

Frame is one presented image of a GPU surface: an ImageBitmap in the browser. Whoever holds it closes it, exactly once.

type ImageRow

type ImageRow struct {
	Ref, ID, Digest, Size, Created string
	SizeBytes, CreatedAt           int64
	Containers                     int64
}

ImageRow is one repository:tag of an image, as `wctr images` lists it.

func (ImageRow) Cells

func (r ImageRow) Cells() []string

Cells is the row as table cells, in ImageColumns order.

func (ImageRow) Key

func (r ImageRow) Key() string

Key identifies the row (one image can carry several tags).

type Images

type Images struct {
	Rows     *mvvm.ObservableList[ImageRow]
	Search   *mvvm.Observable[string]
	Selected *mvvm.Observable[string] // row Key

	// PullRef is the pull dialog's reference; Pulling says a pull runs;
	// PullLog is its progress, one line per message.
	PullRef *mvvm.Observable[string]
	Pulling *mvvm.Observable[bool]
	PullLog *mvvm.ObservableList[string]

	Run *RunForm
	// contains filtered or unexported fields
}

Images is the images view, with its pull and run dialogs.

func (*Images) Find

func (im *Images) Find(key string) (ImageRow, bool)

Find returns the row with key.

func (*Images) Pull

func (im *Images) Pull()

Pull pulls PullRef, streaming progress into PullLog.

func (*Images) PullLine

func (im *Images) PullLine() string

PullLine is the pull dialog's command line.

func (*Images) Remove

func (im *Images) Remove(r ImageRow, force bool)

Remove removes the image by its reference (by ID when it has none).

func (*Images) RemoveLine

func (im *Images) RemoveLine(r ImageRow, force bool) string

RemoveLine is the command line of Remove.

type InspectNode

type InspectNode struct {
	Depth      int
	Key, Value string
	// Branch is an object or array (its children follow it, one deeper).
	Branch bool
}

InspectNode is one line of the inspect tree, in document order.

func InspectTree

func InspectTree(doc []byte) ([]InspectNode, error)

InspectTree flattens a JSON document into tree lines, keeping the document's key order; values are cleaned, the tree is bounded.

type KeyModifiers added in v0.8.0

type KeyModifiers struct{ Alt, Ctrl, Meta, Shift bool }

KeyModifiers are the modifier keys of a key event.

type NetworkRow added in v0.5.0

type NetworkRow struct {
	Name, ID, Driver, Subnet string
	// Containers is how many containers are attached, Attached who they
	// are and their addresses ("web 10.42.0.2, db 10.42.0.3").
	Containers int
	Attached   string
}

NetworkRow is one network.

func (NetworkRow) Cells added in v0.5.0

func (r NetworkRow) Cells() []string

Cells is the row as table cells.

type Networks added in v0.5.0

type Networks struct {
	Rows      *mvvm.ObservableList[NetworkRow]
	Supported *mvvm.Observable[int]
	// Message explains an empty or unavailable view.
	Message *mvvm.Observable[string]
	// Selected is the selected network's name.
	Selected *mvvm.Observable[string]
	// NewName is the create field.
	NewName *mvvm.Observable[string]
	// Inspect is the selected network's inspect document as a tree.
	Inspect *mvvm.ObservableList[InspectNode]
	// contains filtered or unexported fields
}

Networks is the networks view: list, create, inspect, remove, each naming its `wctr network …` line. An engine that does not serve GET /networks gets a message saying so, never invented rows.

func (*Networks) Create added in v0.5.0

func (n *Networks) Create()

Create creates a network named NewName (an in-engine bridge).

func (*Networks) CreateLine added in v0.5.0

func (n *Networks) CreateLine() string

CreateLine is the create field's command line.

func (*Networks) Find added in v0.5.0

func (n *Networks) Find(name string) (NetworkRow, bool)

Find returns the row of the network name.

func (*Networks) InspectLine added in v0.5.0

func (n *Networks) InspectLine(name string) string

InspectLine is the command line the inspect pane stands for.

func (*Networks) Remove added in v0.5.0

func (n *Networks) Remove(name string)

Remove removes a network.

func (*Networks) RemoveLine added in v0.5.0

func (n *Networks) RemoveLine(name string) string

RemoveLine is the command line of Remove.

type RunForm

type RunForm struct {

	// Image, Name, Command (shell words), Env (one KEY=value per line or
	// comma), Entrypoint, Workdir and Memory mirror wctr run's arguments.
	Image, Name, Command, Env   *mvvm.Observable[string]
	Entrypoint, Workdir, Memory *mvvm.Observable[string]
	// Volumes are the -v mounts: NAME:/path[:ro], comma or line separated.
	Volumes    *mvvm.Observable[string]
	AutoRemove *mvvm.Observable[bool]
	// Line is the command line the form stands for, Error what is wrong
	// with it ("" when it can run).
	Line, Error *mvvm.Observable[string]
	// Started is the ID of the last container the form started.
	Started *mvvm.Observable[string]
	// contains filtered or unexported fields
}

RunForm is the run dialog: the options of `wctr run -d`.

func (*RunForm) Request

func (f *RunForm) Request() (name string, req api.ContainerCreateRequest, line string, err error)

Request is what the form asks the engine for, and the equivalent command line; err says what is wrong with the form.

func (*RunForm) Reset

func (f *RunForm) Reset(image string)

Reset prefills the form for image.

func (*RunForm) Start

func (f *RunForm) Start() bool

Start creates and starts the container, pulling the image first when the engine does not have it, as wctr run does.

type Shell

type Shell interface {
	Run(ctx context.Context, line string, out io.Writer) (code int, clear bool)
}

Shell runs one command line, writing its output to out, and returns the exit status and whether the screen should be cleared. The playground's session has this shape; WctrShell is the dashboard's own.

type SurfaceInput added in v0.8.0

type SurfaceInput struct {
	Surface                uint32
	Kind                   string
	X, Y                   float64 // pointers: surface pixels
	Code, Text             string  // keys: KeyboardEvent.code, the text it produces
	Alt, Ctrl, Meta, Shift bool
}

SurfaceInput is one event for a surface's guest: {t:"input", ...}, which the engine worker hands to webgpu.SurfaceInput.

type SurfaceRow added in v0.6.0

type SurfaceRow struct {
	ID     uint32
	Title  string
	Status string
	W, H   int
	// Closed: the guest closed the surface; the pane keeps its last frame,
	// greyed, until it is dismissed.
	Closed bool
	// Shown: a frame has been presented (the pane has an image to draw).
	Shown bool
}

SurfaceRow is one surface pane.

type Surfaces added in v0.6.0

type Surfaces struct {

	// Rows are the panes, by surface ID.
	Rows *mvvm.ObservableList[SurfaceRow]
	// contains filtered or unexported fields
}

Surfaces holds the GPU surfaces the engine reports: the panes, and the newest frame of each until it is presented. Every frame it is given is closed and acknowledged exactly once: presented, replaced by a newer one, for a surface that is unknown or closed, or out of order. The engine paces its guest on those acknowledgements, so none may be lost.

func (*Surfaces) Close added in v0.6.0

func (s *Surfaces) Close(id uint32)

Close marks a surface closed; its pane keeps the last frame, greyed.

func (*Surfaces) Dismiss added in v0.6.0

func (s *Surfaces) Dismiss(id uint32) bool

Dismiss removes a pane, and reports whether there was one (the view then forgets its image).

func (*Surfaces) FPS added in v0.6.0

func (s *Surfaces) FPS(id uint32) int

FPS is how many frames were presented in the last second.

func (*Surfaces) Find added in v0.6.0

func (s *Surfaces) Find(id uint32) (SurfaceRow, bool)

Find returns the pane of surface id.

func (*Surfaces) FlushMoves added in v0.8.0

func (s *Surfaces) FlushMoves()

FlushMoves sends the pointer moves that waited for this frame.

func (*Surfaces) Frame added in v0.6.0

func (s *Surfaces) Frame(id uint32, seq uint64, w, h int, f Frame)

Frame takes frame seq of surface id. Only the newest is kept: an older one still waiting is closed and acknowledged as dropped, and so is a frame for a surface that is unknown or closed, or one that does not come after the last.

func (*Surfaces) Has added in v0.6.0

func (s *Surfaces) Has(id uint32) bool

Has reports whether surface id has a pane (whatever the rows show while they are being rewritten).

func (*Surfaces) IDs added in v0.6.0

func (s *Surfaces) IDs() []uint32

IDs are the surfaces with a pane, in order.

func (*Surfaces) Key added in v0.8.0

func (s *Surfaces) Key(id uint32, kind, code, text string, m KeyModifiers)

Key sends a key event to surface id: its code, the text it produces (bounded; "" when it is too long), and the modifiers.

func (*Surfaces) Open added in v0.6.0

func (s *Surfaces) Open(id uint32, container string, pid uint32, w, h int)

Open adds the pane of a surface (or reopens one with the same ID).

func (*Surfaces) Pointer added in v0.8.0

func (s *Surfaces) Pointer(id uint32, kind string, img Box, px, py int)

Pointer sends a pointer event at canvas pixel (px, py) to surface id, drawn in img; outside the image it is dropped. Moves are coalesced: the last one waits for FlushMoves (once a frame), and any other event sends the waiting move first, so the guest sees them in order.

func (*Surfaces) Presented added in v0.6.0

func (s *Surfaces) Presented(id uint32, seq uint64, w, h int)

Presented acknowledges frame seq of surface id, drawn, and counts it in the frame rate.

func (*Surfaces) Resize added in v0.6.0

func (s *Surfaces) Resize(id uint32, w, h int)

Resize changes a surface's size.

func (*Surfaces) SetAck added in v0.6.0

func (s *Surfaces) SetAck(ack func(surface uint32, seq uint64))

SetAck sets how a frame is acknowledged to the engine ({t:"frame-ack"}).

func (*Surfaces) SetInput added in v0.8.0

func (s *Surfaces) SetInput(send func(SurfaceInput))

SetInput sets where surface input goes (the engine worker); nil drops it.

func (*Surfaces) Take added in v0.6.0

func (s *Surfaces) Take(id uint32) (f Frame, seq uint64, w, h int, ok bool)

Take hands over the frame waiting for surface id, with its size; the caller draws it, closes it, and calls Presented.

type Terminal

type Terminal struct {

	// Out receives everything to draw and Clear clears the screen; both
	// are set by Attach and called on the UI goroutine.
	Out   func(string)
	Clear func()
	// ShowActions echoes each dashboard action's command line here.
	ShowActions *mvvm.Observable[bool]
	// Running says a command runs (only Ctrl-C reaches it).
	Running *mvvm.Observable[bool]
	// contains filtered or unexported fields
}

Terminal is the terminal view's model: the engine's line editor (cli/lineedit, the one the playground uses) in front of a Shell. Input arrives as the bytes a terminal sends; output goes to Out (the view's terminal widget, which is safe for untrusted output by construction).

Keys are handled on the terminal's own goroutine, never the UI's: Tab completion asks the engine (container names) and must not block the page's event loop, which is what delivers the engine's answer.

func (*Terminal) Attach

func (t *Terminal) Attach(out func(string), clear func())

Attach connects the view and starts the terminal: greeting, prompt, and the goroutine that handles keys. Called on the UI goroutine.

func (*Terminal) Input

func (t *Terminal) Input(data string)

Input queues what the user typed. It never blocks (keys past a full queue are dropped).

func (*Terminal) Resize

func (t *Terminal) Resize(cols int)

Resize tells the editor the terminal's width. It never blocks the caller (the UI goroutine): the key goroutine may hold the editor while a completion waits for the engine.

func (*Terminal) SetShell

func (t *Terminal) SetShell(s Shell, complete lineedit.Completer)

SetShell sets what runs the lines and what completes them (nil: no completion).

type VolumeRow

type VolumeRow struct {
	Name, Driver, Mountpoint, Created, Size string
	// Used is how many containers reference it ("" when unknown).
	Used string
}

VolumeRow is one volume.

func (VolumeRow) Cells

func (r VolumeRow) Cells() []string

Cells is the row as table cells.

type Volumes

type Volumes struct {
	Rows      *mvvm.ObservableList[VolumeRow]
	Supported *mvvm.Observable[int]
	// Message explains an empty or unavailable view.
	Message *mvvm.Observable[string]
	// Selected is the selected volume's name.
	Selected *mvvm.Observable[string]
	// NewName is the create field.
	NewName *mvvm.Observable[string]
	// Inspect is the selected volume's inspect document as a tree.
	Inspect *mvvm.ObservableList[InspectNode]
	// Notice is the last prune's result.
	Notice *mvvm.Observable[string]
	// contains filtered or unexported fields
}

Volumes is the volumes view: list, create, inspect, remove, prune, each naming its `wctr volume …` line. An engine that does not serve GET /volumes gets a message saying so, never invented rows.

func (*Volumes) Create added in v0.3.0

func (v *Volumes) Create()

Create creates a volume named NewName (the engine names it when empty).

func (*Volumes) CreateLine added in v0.3.0

func (v *Volumes) CreateLine() string

CreateLine is the create field's command line.

func (*Volumes) Find added in v0.3.0

func (v *Volumes) Find(name string) (VolumeRow, bool)

Find returns the row of the volume name.

func (*Volumes) Prune added in v0.3.0

func (v *Volumes) Prune(all bool)

Prune removes unused volumes (anonymous ones, or with all every unused one) and says what it reclaimed.

func (*Volumes) PruneLine added in v0.3.0

func (v *Volumes) PruneLine(all bool) string

PruneLine is the command line of Prune.

func (*Volumes) Remove added in v0.3.0

func (v *Volumes) Remove(name string, force bool)

Remove removes a volume.

func (*Volumes) RemoveLine added in v0.3.0

func (v *Volumes) RemoveLine(name string, force bool) string

RemoveLine is the command line of Remove.

type WctrShell

type WctrShell struct {
	// Root returns a fresh wctr command tree (cli.RootCmd with a Client
	// that speaks to the engine).
	Root func() *cobra.Command
}

WctrShell runs `wctr …` lines through wctr's command tree in-process.

func (WctrShell) Run

func (s WctrShell) Run(ctx context.Context, line string, out io.Writer) (int, bool)

Run implements Shell.

Jump to

Keyboard shortcuts

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