-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathterminal.js
More file actions
80 lines (68 loc) · 1.76 KB
/
terminal.js
File metadata and controls
80 lines (68 loc) · 1.76 KB
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
const appHistory = ReactRouter.useRouterHistory(History.createHashHistory)({queryKey: false})
var TerminalHandler = function() {
var self = this;
self.help = function() {
var message = `
Commands:
${format_text('help', 'b')}: list these commands
${format_text('about', 'b')}: about
${format_text('work', 'b')}: not a NEET
${format_text('projects', 'b')}: stuff i did for funsies
`;
this.echo(message);
}
function execute(cmd) {
return function() {
appHistory.push(cmd);
};
}
var commands = ['about', 'work', 'projects'];
for (var i in commands) {
self[commands[i]] = execute(commands[i]);
}
};
function intro(term) {
function press_enter() {
var e = $.Event('keydown');
e.which = 13;
e.keyCode = 13;
$(term).trigger(e);
}
function typed(message, delay) {
var prompt = term.get_prompt();
var c = 0;
if (message.length > 0) {
var interval = setInterval(function() {
term.insert(message[c++]);
if (c == message.length) {
clearInterval(interval);
// execute in next interval
setTimeout(function() {
// swap command with prompt
term.set_command(message);
press_enter();
}, delay);
}
}, delay);
}
}
typed('help', 100);
}
function format_text(text, options, color) {
return `[[${options};${color};]${text}]`;
}
var handler = new TerminalHandler();
$(function($) {
options = {
height: '500px',
prompt: function(cb) {
var options = 'b';
var color = '#ff00ff';
var prompt_str = format_text('~/', options, color) + '$ ';
cb(prompt_str);
},
greetings: false,
onInit: intro,
};
$('#terminal').terminal(handler, options);
});