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
|
<span id="ps1_01"></span> <span id="cd"></span> <br>
<span id="ps1_02"></span> <span id="cat"></span> <br>
<span id="std_out_01"></span> <br>
<span id="ps1_03"></span> <span id="tree"></span> <br>
<span id="std_out_02"></span> <br>
<span id="ps1_04"></span>
<script type="text/javascript">
async function typewriter(text, elementId, waitAfter) {
var n = 0,
isTag = false
addText = "";
const el = document.getElementById(elementId);
const wait = () => new Promise(r => setTimeout(r, waitAfter));
const nowait = () => new Promise(r => r());
const render = () => el.innerHTML = (text.slice(0, n + 1) + addText);
const cursor = document.createElement('span');
cursor.id = "blink";
el.style.setProperty("--cursor-visibility", "visible");
while (n < text.length) {
if (text.charAt(n + 1) === "<") isTag = true;
if (text.charAt(n + 1) === ">") isTag = false;
if (isTag) {
n++;
continue;
}
requestAnimationFrame(render);
if (waitAfter === 0) {
await nowait();
} else {
await wait();
}
n++;
}
el.style.setProperty("--cursor-visibility", "collapse");
}
function parseDelay(d) {
const parsed = parseInt(d, 10);
if (isNaN(parsed)) return 0;
return parsed;
}
const ps1Delay = parseDelay("{{ .ps1delay }}"),
stdoutDelay = parseDelay("{{ .stdoutdelay }}"),
commandDelay = parseDelay("{{ .commanddelay }}");
const typeeffetct = async () => {
await typewriter("{{ .env }}", "ps1_01", ps1Delay); await typewriter("{{ .cd }}", "cd", commandDelay);
await typewriter("{{ .envWithDir }}", "ps1_02", ps1Delay); await typewriter("{{ .cat }}", "cat", commandDelay);
await typewriter("{{ .description }}", "std_out_01", stdoutDelay);
await typewriter("{{ .envWithDir }}", "ps1_03", ps1Delay); await typewriter("{{ .tree }}", "tree", commandDelay);
await typewriter("{{ .leaf }}", "std_out_02", stdoutDelay);
await typewriter("{{ .envWithDir }}", "ps1_04", ps1Delay);
return;
}
typeeffetct()
</script>
|