web

package
v0.0.0-...-8cefc6a Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Rendered for js/wasm

Overview

Package web mounts a websh shell onto a DOM element.

websh's parts — the interpreter, the applets, the filesystem — are libraries, and assembling a working terminal out of them takes a couple of hundred lines of line editor, stdin plumbing and raw-mode switching. That assembly is the same every time, so it lives here rather than being copied into every program that wants a shell on a page.

A Session is a widget: hand it an element and it fills it. Nothing here knows whether that element is the whole page or the body of a draggable window, and nothing needs to — the terminal observes its own container.

Index

Constants

This section is empty.

Variables

View Source
var Builtins = []string{
	"cd", "pwd", "echo", "printf", "read", "exit", "export", "unset",
	"source", "test", "true", "false", "set", "shift", "local",
	"declare", "eval", "alias", "unalias", "type", "return", "break",
	"continue", "pushd", "popd", "dirs", "let", "getopts", "wait",
	"jobs", "kill", "disown", "fg", "bg", "enable", "compgen", "history",
	"builtin", "umask", "times", "trap", "shopt", "mapfile", "readarray",
}

Builtins are the interpreter's own commands, which completion offers alongside the applets.

Functions

This section is empty.

Types

type Options

type Options struct {
	// FS is the filesystem the shell runs over. Nil creates a fresh
	// in-memory one and seeds it. Passing an existing one is how several
	// sessions come to share files — and how a caller supplies a filesystem
	// restored from somewhere persistent.
	FS afero.Fs

	// Host is the name in the prompt. Empty means "websh".
	Host string

	// Greeting is written once, before the first prompt.
	Greeting string

	// Scrollback is the number of lines kept. Zero means 2000.
	Scrollback int

	// NoWebGL forces the DOM renderer.
	NoWebGL bool

	// AfterCommand runs after each command line finishes, on the shell's
	// goroutine. It is where a caller flushes the filesystem somewhere
	// durable, which has to happen after a command rather than during one.
	AfterCommand func()
}

Options configure a Session. The zero value is usable.

type Session

type Session struct {
	Term   *xterm.Terminal
	Shell  *shell.Shell
	Editor *shell.LineEditor
	// contains filtered or unexported fields
}

Session is a terminal with a shell attached, mounted on an element.

func NewSession

func NewSession(el js.Value, opt Options) (*Session, error)

NewSession builds a terminal on el and starts a shell on it.

func (*Session) Close

func (s *Session) Close()

Close tears the session down. The filesystem outlives it, so files written here are still there for whatever opens next.

func (*Session) Prompt

func (s *Session) Prompt() string

Prompt is the current prompt string, colors and all.

func (*Session) Submit

func (s *Session) Submit(line string)

Submit runs a line as though it had been typed at the prompt: it is echoed where the typing would have appeared, remembered in the history, and run.

It is what a link into a page needs — "open this and run that" — and the echo is the point rather than a side effect. A command that arrives from a URL should be visible in the scrollback, so that what ran is on the screen and not only in the address bar.

The send is on its own goroutine because the line channel is small and the run loop may be busy; blocking here would block whatever called it, which on this platform is usually the browser's event loop.

func (*Session) WritePrompt

func (s *Session) WritePrompt()

WritePrompt draws the prompt.

Jump to

Keyboard shortcuts

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