-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.html
431 lines (409 loc) · 17.6 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Termo - An Easy to use terminal for your browser</title>
<link
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH"
crossorigin="anonymous"
/>
<script
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz"
crossorigin="anonymous"
></script>
<!-- include jquery -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<link rel="stylesheet" href="styles.css" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=Sono:[email protected]&display=swap" rel="stylesheet" />
<script src="dist/termo.min.js"></script>
<!-- Highlight.js CSS -->
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/styles/atom-one-dark.min.css"
/>
<!-- Highlight.js JS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/highlight.min.js"></script>
<link href="./_app/immutable/assets/incident.8576cc89.css" rel="stylesheet">
<!-- HEAD_svelte-1ov4qhs_START -->
<link rel="icon" href="https://termo.rajnandan.com/code.png" >
<meta name="description" content="Termo: A simple terminal emulator that can be used to create a terminal-like interface on your website."
>
<meta name="keywords" content="terminal, terminal emulator, xterm.js, stripe.dev, terminal-like interface, terminal-like, terminal interface, terminal for website, terminal for browser, terminal for web"
>
<meta name="og:description" content="Termo: A simple terminal emulator that can be used to create a terminal-like interface on your website."
>
<meta name="og:image" content="https://termo.rajnandan.com/og.png" >
<meta name="og:title" content="Termo: A simple easy to use terminal emulator for the browser">
<meta name="og:type" content="website" >
<meta name="og:site_name" content="Termo" >
<meta name="twitter:card" content="summary_large_image" >
<meta name="twitter:site" content="@_rajnandan_" >
<meta name="twitter:creator" content="@_rajnandan_" >
<meta name="twitter:image" content="https://termo.rajnandan.com/og.png" >
<meta name="twitter:title" content="Termo" >
<meta name="twitter:description" content="Termo: A simple terminal emulator that can be used to create a terminal-like interface on your website."
>
</head>
<body data-bs-theme="dark">
<div class="squares-pattern"></div>
<div class="container my-5" style="position: relative; max-width: 820px">
<h1 class="blur-card">Termo</h1>
<div class="col-lg-12 px-0 blur-card">
<p class="fs-5">
Termo is a simple terminal emulator that can be used to create a terminal-like interface on your
website. It is inspired by the terminal emulator in <a href="https://stripe.dev">stripe.dev</a>. It
is an wrapper on top of xterm.js.
</p>
<div class="d-flex gap-2">
<button id="fireup" class="button-68">Fire UP a Termo Or Press [C]</button>
<a class="button-68 gh" href="https://github.com/rajnandan1/termo">
<svg xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" fill="#fff" width="26" height="26" viewBox="0 0 64 64">
<path d="M32,10c12.15,0,22,9.85,22,22c0,9.768-6.369,18.045-15.179,20.916c0.002-0.008,0.006-0.021,0.006-0.021 s-1.485-0.696-1.453-1.938c0.035-1.367,0-4.556,0-5.727c0-2.01-1.272-3.434-1.272-3.434s9.977,0.112,9.977-10.533 c0-4.107-2.147-6.245-2.147-6.245s1.128-4.385-0.39-6.245c-1.701-0.184-4.749,1.626-6.05,2.472c0,0-2.062-0.846-5.492-0.846 c-3.43,0-5.492,0.846-5.492,0.846c-1.301-0.846-4.348-2.656-6.05-2.472c-1.518,1.86-0.39,6.245-0.39,6.245s-2.147,2.137-2.147,6.245 c0,10.645,9.977,10.533,9.977,10.533s-1.005,1.136-1.225,2.806c-0.696,0.236-1.721,0.528-2.549,0.528 c-2.165,0-3.812-2.105-4.416-3.078c-0.595-0.96-1.815-1.766-2.953-1.766c-0.749,0-1.115,0.375-1.115,0.803s1.05,0.727,1.743,1.521 c1.461,1.674,1.435,5.438,6.641,5.438c0.565,0,1.719-0.139,2.588-0.256c-0.005,1.185-0.007,2.436,0.012,3.167 c0.031,1.242-1.453,1.938-1.453,1.938s0.004,0.012,0.006,0.021C16.369,50.045,10,41.768,10,32C10,19.85,19.85,10,32,10z"></path>
</svg>
Clone from Github
</a>
</div>
</div>
<hr class="my-5" />
<section class="mt-4">
<h3>Installation</h3>
<ul class="nav nav-tabs" id="myTab" role="tablist">
<li class="nav-item">
<a
class="nav-link active"
id="cdn-tab"
data-bs-toggle="tab"
href="#cdn"
role="tab"
aria-controls="cdn"
aria-selected="true"
>CDN</a
>
</li>
<li class="nav-item">
<a
class="nav-link"
id="npm-tab"
data-bs-toggle="tab"
href="#npm"
role="tab"
aria-controls="npm"
aria-selected="false"
>NPM</a
>
</li>
<li class="nav-item">
<a
class="nav-link"
id="react-tab"
data-bs-toggle="tab"
href="#react"
role="tab"
aria-controls="react"
aria-selected="false"
>React</a
>
</li>
</ul>
<div class="tab-content border-start border-bottom border-end" id="myTabContent">
<div class="tab-pane fade show active p-4" id="cdn" role="tabpanel" aria-labelledby="cdn-tab">
<p class="">Include the following script tag in your HTML file.</p>
<pre><code class="language-html"><script src="https://cdn.jsdelivr.net/gh/rajnandan1/termo/dist/termo.min.js"></script></code></pre>
</div>
<div class="tab-pane fade p-4" id="npm" role="tabpanel" aria-labelledby="npm-tab">
<p>Install the package using npm.</p>
<pre><code class="language-bash">npm install @rajnandan1/termo</code></pre>
<p>Include / Import.</p>
<pre><code class="language-javascript">import Termo from '@rajnandan1/termo';</code></pre>
<p><em>Please note that termo is a client side library and it will not work in server side code.</em></p>
</div>
<div class="tab-pane fade p-4" id="react" role="tabpanel" aria-labelledby="react-tab">
<p>Sample React Code</p>
<pre><code class="language-javascript">import React, { useEffect, useRef } from 'react';
import logo from './logo.svg';
import './App.css';
import Termo from '@rajnandan1/termo';
function App() {
const myDemoTerminalRef = useRef(null);
useEffect(() => {
myDemoTerminalRef.current = new Termo({
title: 'bterm v1.0.022',
fontFamily: 'Sono',
theme: 'dark',
prompt: 'bterm@localhost:$',
});
myDemoTerminalRef.current.create();
return () => {
myDemoTerminalRef.current.destroy();
};
}, []);
const handleClick = () => {
myDemoTerminalRef.current.show();
};
return (
<div className="App">
<header className="App-header">
<button onClick={handleClick}>Show Terminal</button>
</header>
</div>
);
}
export default App;
</code></pre>
</div>
</div>
</section>
<section class="mt-4">
<h3>Quick Start</h3>
<p>Create a new instance of Termo by passing an object .</p>
<pre><code class="language-javascript">const myTermo = new termo({
title: "Termo",
welcomeMessage: "Welcome to Termo",
commands: [{
command: "hello",
description: "Says hello",
action: async (terminal, args) => terminal.write('\r\nHello! ' + args.join(' ')),
}],
});
myTermo.create();
myTermo.show();
</code></pre>
</section>
<section class="mt-4">
<h3>Complete Example</h3>
<p>Here is a complete example of how to create a terminal with a custom command.</p>
<pre><code class="language-javascript">import { termo } from 'termo';
let commands = [{
command: 'hello',
description: 'Says hello',
action: async (terminal, args) => terminal.write('\r\nHello! ' + args.join(' ')),
}, {
command: 'joke',
description: 'Hear a random joke from a random API',
action: (terminal, args) => {
terminal.write('\r\n' + 'Thinking of a joke...');
return new Promise(async (resolve, reject) => {
try {
const response = await fetch('https://official-joke-api.appspot.com/random_joke');
const data = await response.json();
terminal.write('\r\n' + data.setup);
setTimeout(() => {
resolve(terminal.write('\r\n' + data.punchline));
}, 2000);
} catch (error) {
terminal.write('\r\nFailed to fetch joke');
}
});
},
}, {
command: 'theme',
description: 'Change the website theme',
subCommands: [{
command: 'set',
description: 'Set the website theme to light or dark',
action: async (terminal, args) => {
let theme = args[0];
if (theme === 'light') {
document.body.setAttribute('data-bs-theme', 'light');
} else {
document.body.setAttribute('data-bs-theme', 'dark');
}
terminal.write('\r\nsetting theme to ' + args[0]);
},
},
{
command: 'list',
description: 'List all available themes',
action: async (terminal, args) => {
let list = ['light', 'dark'];
list.forEach((theme) => {
terminal.write('\r\n' + theme);
});
},
},
],
}];
let myDemoTerminal = new termo({
commands: commands,
title: 'Termo v0.0.2',
theme: 'dark',
prompt: '$',
});
myDemoTerminal.create();
myDemoTerminal.show();
</code></pre>
</section>
<section class="mt-4">
<h3>Options</h3>
<p>Termo accepts an object with the following options.</p>
<pre><code class="language-javascript">
/**
* Configuration options for initializing the terminal
* @interface InitOptions
*
* @property {boolean} [playSound=true] - Enable/disable terminal sound effects
* @property {string} [title='termo'] - Terminal window title
* @property {string} [welcomeMessage] - Initial message displayed when terminal opens
* @property {'light' | 'dark'} [theme='light'] - Terminal color theme
* @property {string} [fontFamily='Courier New, monospace'] - Font family for terminal text
* @property {string} [prompt='$'] - Terminal prompt character
* @property {Command[]} [commands=[]] - Array of available terminal commands
* @property {ITerminalOptions} [terminalOptions] - XTerm.js specific terminal options
*
* @example
* const options: InitOptions = {
* playSound: true,
* title: 'My Terminal',
* theme: 'dark',
* commands: [{
* command: 'hello',
* description: 'Says hello',
* action: async (terminal, args) => terminal.write('\r\nHello! ' + args.join(' ')),
* }]
* };
*/
export interface InitOptions {
playSound?: boolean;
title?: string;
welcomeMessage?: string;
theme?: 'light' | 'dark';
fontFamily?: string;
prompt?: string;
commands?: Command[];
terminalOptions?: ITerminalOptions;
}
</code></pre>
<h3 class="mt-4">Command</h3>
<p>Command object for defining terminal commands.</p>
<pre><code class="language-javascript">
/**
* Represents a terminal command with its description, action and optional subcommands
* @interface Command
*
* @property {string} command - The command name/identifier
* @property {string} description - Brief description of what the command does
* @property {function} action - Async function to execute when command is invoked
* @property {Command[]} [subCommands] - Optional array of nested subcommands
*
* @example
* const myCommand: Command = {
* command: 'git',
* description: 'Git version control',
* action: async (terminal, args) => {
* terminal.write('Executing git command...\r\n');
* },
* subCommands: [{
* command: 'status',
* description: 'Show working tree status',
* action: async (terminal) => {
* terminal.write('git status output...\r\n');
* }
* }]
* };
*/
export interface Command {
command: string;
description: string;
action: (terminal: Terminal, args: string[]) => Promise<void>;
subCommands?: Command[];
}
</code></pre>
</section>
<section class="mt-4">
<h3>API</h3>
<p>Termo exposes the following methods and variable.</p>
<pre><code class="language-javascript">const myTermo = new termo({
"title": "Termo",
});</code></pre>
<h4 class="mt-4">Methods</h4>
<p>Termo has the following methods.</p>
<pre><code class="language-javascript">/**
* Creates a new terminal instance with the specified options.
*
* This method initializes the terminal container, header, and various control buttons
* (resize, close). It also sets up event listeners for these buttons to handle terminal
* resizing and closing actions. The terminal is appended to the document body and made
* draggable.
*
* @throws {Error} If a terminal with the same title already exists.
*/
myTermo.create();</code></pre>
<pre><code class="language-javascript">/**
* Displays the terminal by applying a scale transformation to the container element.
* If the container exists, it plays the terminal open sound, sets the state to 'open',
* and focuses the terminal. If the container does not exist, it throws an error.
*
* @throws {Error} If the terminal container is not created.
*/
myTermo.show(); </code></pre>
<pre><code class="language-javascript">/**
* Hides the terminal by scaling down its container element.
* If the container exists, it plays the terminal close sound,
* scales the container to zero, and updates the state to 'minimized'.
* If the container does not exist, it throws an error.
*
* @throws {Error} If the terminal container is not created.
*/
myTermo.hide(); // Hides the terminal </code></pre>
<pre><code class="language-javascript">/**
* Sets the theme of the terminal.
*
* @param theme - The theme to set, either 'dark' or 'light'.
* @throws Will throw an error if the terminal container is not created.
*/
myTermo.setTheme(); </code></pre>
<pre><code class="language-javascript">/**
* Destroys the terminal instance by performing the following actions:
* - If the container exists:
* - Destroys the terminal manager.
* - Removes the container element from the document body.
* - Removes the associated stylesheet from the document head.
* - Sets the container to undefined.
* - Deletes the terminal manager.
* - Updates the state to 'destroyed'.
* - Sets the mode to 'floating'.
* - If the container does not exist, throws an error indicating that the terminal was not created.
*
* @throws {Error} If the terminal was not created.
*/
myTermo.destroy(); </code></pre>
<pre><code class="language-javascript">/**
* Adjusts the dimensions and position of the terminal container to dock it
* at the bottom right corner of the viewport.
*
* @throws {Error} Throws an error if the terminal container is not created.
*/
myTermo.dock();</code></pre>
<pre><code class="language-javascript">/**
* Adjusts the dimensions and position of the container element to float it
* at a specific size and position on the screen. If the container element
* is not available, an error is thrown.
*
* @throws {Error} If the container element is not created.
*/
myTermo.float(); </code></pre>
</section>
<section class="mt-4">
<h4>Variables</h4>
<p>Termo has the following variables.</p>
<pre><code class="language-javascript">/**
* @class Termo
* @property {InitOptions} options - The initialization options for the terminal.
* @property {'floating' | 'docked'} mode - The current mode of the terminal (floating or docked).
* @property {'minimized' | 'open' | 'destroyed' | 'initiated'} state - The current state of the terminal.
* @property {HTMLDivElement | undefined} container - The container element for the terminal.
* @property {TerminalManager | undefined} terminalManager - The terminal manager instance.
*/
</code></pre>
</section>
</div>
<script src="main.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/confetti.browser.min.js"></script>
</body>
</html>