This terminal is intended to support the emulation of an interactive shell like many scripting languages or the operating systems themselves provide.
Note that it is now also easy to create custom styles for your terminal, see this page for more information on styling.
For this demonstration, some example commands have been implemented (you can write your own ones using Javascript):
help
and it will tell you that no help is
availale.
clear
and it will erase the terminal contents.
prompt "> "
to change the prompt symbol to
>
disable
to disable text input for two seconds
colors
to show all possible colors (ansi escaped)
In order to create a terminal, you need to include the w3term.js and w3term.css files in your HTML file. You can also use the minified versions inside the dist directory.
A terminal is created by calling the function w3term
with
a dom element as an argument (in this case a div).
Every element that is not a div is automatically converted into a div.
var term = w3term(document.getElementById("myId"),
{
prompt : "$ ",
processCommand : function(cmd) {
// implement your command logic here
}
}
);
term.w3term.println("Welcome to w3term"); // print some text into the terminal
The second parameter is an object that contains several options. It is optional and can be omitted if the terminal should be created with default options. A list of possible options is described below.
The following methods can be called via
element.w3term.<methodName>(...):
init(node, options)
node
options
[optional]prompt
:
(string) The prompt symbol
(default="> "
)
historySize
:
(int) The number of commands which can be stored
within the command history.
(default=100
)
processCommand
:
(function(cmd, term)) A handler function which
receives a command from the terminal and may
process them. The second parameter is optional
and will receive the terminal object which sent
the command.
(writes the command to the JS console
by default)
setInput(text)
text
clear()
println(text, escapeHtml)
text
escapeHtml
true
,
all HTML tags and characters will be escaped in order to
avoid undesirable code injection.
print(text, escapeHtml)
println
, but does not add a newline character
at the end of the text.
text
escapeHtml
true
,
all HTML tags and characters will be escaped in order to
avoid undesirable code injection.
disableInput()
terminal.enableInput()
scrollToBottom()