📟 A Simple Terminal UI That Run On The Web
Checkout the demo from Github Pages
Install with npm
:
$ npm install term-web
Or install with yarn
:
$ yarn add term-web
import Term from 'term-web';
Or umd builds are also available:
<script src="path/to/term-web.js"></script>
Or from jsDelivr CDN:
<script src="https://cdn.jsdelivr.net/npm/term-web/dist/term-web.js"></script>
Will expose the global variable to window.Term
.
<div id="term"></div>
var term = new Term({
// ... options
container: '#term',
});
{
// Mounted dom element
container: '#term',
// Debug mode
debug: false,
// Initial size
width: 600,
height: 500,
// Custom actions
actions: [],
// Use the display recorder button
recorder: true,
// Is it draggable
draggable: true,
// Font size
fontSize: 13,
// Font family
fontFamily: 'monospace',
// Watermark image url
watermark: '',
// Font color
color: '#b0b2b6',
// Background color
background: 'rgb(42, 39, 52)',
// Title on the topbar
title: 'Term Web',
// Entered prefix
prefix: 'root@linux: ~ <d color="#00f501">$</d> ',
// Welcome Message
welcome: `Last login: ${new Date()}`,
// Loading tips
loading: (val) => '<d color="yellow">Loading...</d>',
// Pixel ratio
pixelRatio: window.devicePixelRatio,
// Callback when command is not found
notFound: (val) => `-bash: <d color='red'>${val}</d>: command not found`,
}
text
is the string to be displayed.isReplace
indicates whether to replace the previous record, default isfalse
;
text
is the string to be displayed.isReplace
indicates whether to replace the previous record, default isfalse
;
text
is the string to be displayed.isExecute
Whether to execute immediately after typing, default istrue
;
Clear all log
text
is the question string to be displayed.
term.ask('How are you ?').then((answer) => console.log(answer));
Output radio list
term.radio([
{
key: 1,
text: 'hi',
},
{
key: 0,
text: 'bye',
},
]).then((key) => {
console.log(key);
});
Output checkbox list
term.checkbox([
{
key: 1,
text: 'hi',
},
{
key: 0,
text: 'bye',
},
]).then((key) => {
console.log(key);
});
Modify font color
term.color = '#fff';
Modify background color
term.background = '#000';
Modify watermark image
term.watermark = 'img.png';
Modify terminal width
term.width = 500;
Modify terminal height
term.height = 500;
The output interface supports multiple styles through a html tag, currently does not support tag nesting effect
term.output('<d color="#666">some text</d>');
term.output('<d color="#fff" background="red">some text</d>');
Select the color attribute or fontColor attribute of the option by default
term.output('<d color="yellow" border>some text</d>');
Select the color attribute or fontColor attribute of the option by default
term.output('<d color="yellow" underline>some text</d>');
Select the color attribute or fontColor attribute of the option by default
term.output('<d color="yellow" del>some text</d>');
Link jump behavior
term.output('<d href="www.google.com">google</d>');
Term.font('Font Name', 'path/to/font.ttf').then((font) => {
var term = new Term({
fontFamily: font.family,
// ... options
});
});
We accept donations through these channels:
MIT © Harvey Zack