#
new Web3osTerminal(optionsopt)
Web3os Terminal
Unless you have a reason to directly create a new Web3osTerminal(),
you should probably use the static Web3osTerminal.create method
Prompt Format
When setting #promptFormat, you may include these substitutions:
{cwd} - When the prompt is compiled, this will be replaced with the current working directory
Parameters:
Name |
Type |
Attributes |
Description |
options |
Object
|
<optional>
|
Options for the new terminal
Properties
Name |
Type |
Attributes |
Default |
Description |
kernel |
Web3osKernel
|
<optional>
|
globalThis.Kernel
|
The kernel for the terminal to attach to |
debug |
boolean
|
<optional>
|
false
|
Enable verbose logging |
customCommands |
Array.<CustomCommand>
|
|
|
An array of custom commands only for this terminal |
|
Properties
Name |
Type |
Description |
cmd |
string
|
The current user input |
cwd |
string
|
The current working directory |
env |
Object
|
The terminal's environment variables |
debug |
boolean
|
Enable verbose output |
execute |
function
|
Override command execution |
aliases |
Object
|
Map of command aliases |
history |
Array.<string>
|
The history of commands entered |
binSearchPath |
Array.<string>
|
An array of package scopes to search (in order) for executables |
customCommands |
Array.<CustomCommand>
|
An array of custom commands only for this terminal |
cursorPosition |
number
|
The current cursor position of the input string |
historyPosition |
number
|
The current position in the history array |
promptFormat |
string
|
The prompt format containing substitutions |
tabSelectMode |
boolean
|
Whether the prompt is cycling tab choices |
tabSelectChoices |
Array.<string>
|
The array of choices that match the user's input |
tabSelectCurrentChoice |
number
|
The current index of tabSelectChoices |
escapes |
Object
|
ANSI escapes via ansi-escape-sequences |
Extends
Methods
Create a new Web3os Terminal instance with addons:
xterm-addon-fit, xterm-addon-web-links, xterm-addon-attach
Parameters:
Name |
Type |
Description |
options |
Object
|
The options for the new terminal |
#
acceptTabSelection()
Accept the current tab completion option
#
cancelTabSelection()
#
interruptHandler(data)
Handle ESC and CTRL-C to return control of the terminal to the user.
This doesn't actually kill anything, but it will recover terminal input.
Parameters:
Name |
Type |
Description |
data |
Object
|
The data for the interrupt handler
Properties
Name |
Type |
Description |
key |
string
|
The ASCII representation of the key |
domEvent |
KeyboardEvent
|
The KeyboardEvent from the DOM listener |
|
#
isPrintable(event) → {boolean}
Check if the domEvent represents a printable character
Parameters:
Name |
Type |
Description |
event |
KeyboardEvent
|
The keyboard event |
Returns:
true if the event represents a printable character
-
Type
-
boolean
#
(async) keyHandler(data)
Handle the keypress event
Parameters:
Name |
Type |
Description |
data |
Object
|
The data for the key handler
Properties
Name |
Type |
Description |
key |
string
|
The ASCII representation of the key |
domEvent |
KeyboardEvent
|
The KeyboardEvent from the DOM listener |
|
#
listen()
Start listening for user input on the terminal
#
log(…args)
Log a message to the terminal
Parameters:
Name |
Type |
Attributes |
Description |
args |
any
|
<repeatable>
|
Strings or stringifiable object to log |
#
(async) paste(dataopt)
Handle pasting content from the clipboard
Parameters:
Name |
Type |
Attributes |
Default |
Description |
data |
string
|
<optional>
|
navigator.clipboard.readText()
|
Data to paste into the terminal |
#
prompt(valueopt)
Write the prompt to the terminal and listen for input
Parameters:
Name |
Type |
Attributes |
Description |
value |
string
|
<optional>
|
If passed, will update this terminal's promptFormat |
#
promptCompile() → {string}
Compile the prompt string (symbol replacement)
Returns:
prompt - The compiled prompt string
-
Type
-
string
#
run()
#
(async) tabCompletion()
#
unlisten()
Stop listening for user input
Type Definitions
#
CustomCommand
Properties
Name |
Type |
Description |
name |
string
|
The name to enter into the terminal to invoke this command |
run |
function
|
The function to execute when this command is invoked |
Example
{
name: 'smile',
run: (term, context) => console.log('😁', { term, context })
}