-
Notifications
You must be signed in to change notification settings - Fork 0
/
Terminal.js
49 lines (44 loc) · 1.55 KB
/
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
const Terminal = ({widgets}) => {
let print = null, reset = null
widgets.register("Terminal", (box) => {
const div = document.createElement("div")
div.innerHTML = `
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/tailwindcss/dist/tailwind.min.css">
<div class="flex flex-col text-gray-100 text-sm subpixel-antialiased bg-gray-800 leading-normal overflow-auto h-48 scroll-gray h-full">
<div class="top flex items-center sticky top-0 left-0 bg-gray-800 px-5 pt-4 pb-2">
<div class="select-none">Terminal</div>
</div>
<div class="flex flex-col h-full px-5 text-xs terminal-lines"></div>
</div>
`
box.injectNode(div)
print = (text) => {
const line = document.createElement("div")
line.className = "flex mt-2 font-mono last:pb-4"
line.innerHTML = `
<span class="text-green-400 select-none">>>></span>
<p class="flex-1 items-center pl-2 whitespace-pre-line">${text}</p>
`
div.querySelector(".terminal-lines").appendChild(line)
}
reset = () => {
div.querySelector(".terminal-lines").textContent = ""
}
return () => {
print = null
}
})
return {
print: (text) => {
if (print !== null) {
print(text)
}
},
reset: () => {
if (reset !== null) {
reset()
}
}
}
}
export default Terminal