@wasmer/wasm-terminal
Do you want to run a full terminal with WebAssembly files? This is your package!
import { WasmTerminal } from "@wasmer/wasm-terminal"
.new WasmTerminal(jsObject: WasmTerminalConfig): WasmTerminal
Constructor that returns an instance of the
WasmTerminal
.{
// Function that is called whenever a command is entered and returns a Promise,
// It takes in the name of the command being run, and expects a Uint8Array of a Wasm Binary, or a
// CallbackCommand (see the api below) to be returned.
fetchCommand: (options: {
args: string,
env?: {[key: string]: string}
}) => Promise<Uint8Array | CallbackCommand>
// Only for Optimized Bundles: URL to the /node_modules/wasm-terminal/workers/process.worker.js . This is used by the shell to
// to spawn web workers in Comlink, for features such as piping, /dev/stdin reading, and general performance enhancements.
processWorkerUrl?: string;
}
callbackCommands
are functions that can be returned in the fetchCommand
config property. They are simply Javascript callbacks that take in the command name, command arguments, environment variables, and return a Promise
that resolves stdout
.Since these callback commands handle
stdin
and stdout
, they can be used as normal commands that can be piped!export type CallbackCommand = (options: {
args: string,
env?: {[key: string]: string}
}) => Promise<string | undefined>;
wasmTerminal.open(containerElement: Element): void
wasmTerminal.fit()
: voidResizes the terminal to fit the size of its container.
wasmTerminal.focus()
: voidGives the
wasmTerminal
element focus, and allows input into the shell.wasmTerminal.print(message: string)
: voidPrints text to the
wasmTerminal
.Useful for things such as showing a welcome message before the
wasmTerminal
is opened.wasmTerminal.scrollToCursor()
:voidScrolls the terminal cursor into view.
wasmTerminal.runCommand(commandString: string)
: voidRuns the supplied string as if it had been entered as a command, typed into the Wasm terminal.
import { fetchCommandFromWAPM } from "@wasmer/wasm-terminal";
fetchCommandFromWAPM(options: {
args: string,
env?: {[key: string]: string}
}): Promise<Uint8Array>
Exported function from the
@wasmer/wasm-terminal
package. This function is meant to be returned in the fetchCommand
config property of the WasmTerminal
Class. This takes in the name of command, the command arguments, and the environment variables, and returns a Promise
that resolves a Uint8Array
of binary Wasm bytes from WAPM.Last modified 1yr ago