-
Notifications
You must be signed in to change notification settings - Fork 0
/
my-terminal.js
58 lines (42 loc) · 1.46 KB
/
my-terminal.js
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
const commands = {};
const term = $('body').terminal(commands);
const greetings = ` ______ _ __ ____ __ ____ ___
/_ __/__ _________ ___ (_)___ ____ _/ / / __ \\____ _____/ /_/ __/___ / (_)___
/ / / _ \\/ ___/ __ \`__ \\/ / __ \\/ __ \`/ / / /_/ / __ \\/ ___/ __/ /_/ __ \\/ / / __ \\
/ / / __/ / / / / / / / / / / / /_/ / / / ____/ /_/ / / / /_/ __/ /_/ / / / /_/ /
/_/ \\___/_/ /_/ /_/ /_/_/_/ /_/\\__,_/_/ /_/ \\____/_/ \\__/_/ \\____/_/_/\\____/`
const term = $('body').terminal(commands, {
greetings
});
const font = 'Slant';
figlet.defaults({ fontPath: 'https://unpkg.com/figlet/fonts/' });
figlet.preloadFonts([font], ready);
const term = $('body').terminal(commands, {
greetings: false
});
term.pause();
function ready() {
term.echo(() => render('Terminal Portfolio')).resume();
}
function render(text) {
const cols = term.cols();
return trim(figlet.textSync(text, {
font: font,
width: cols,
whitespaceBreak: true
}));
}
function trim(str) {
return str.replace(/[\n\s]+$/, '');
}
function rainbow(string) {
return lolcat.rainbow(function(char, color) {
char = $.terminal.escape_brackets(char);
return `[[;${hex(color)};]${char}]`;
}, string).join('\n');
}
function hex(color) {
return '#' + [color.red, color.green, color.blue].map(n => {
return n.toString(16).padStart(2, '0');
}).join('');
}