-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathshmm.js
executable file
·109 lines (109 loc) · 1.83 KB
/
shmm.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
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
//HmmOS shell
(() => {
let tx = 0
, ty = -1
, path = true
, cwd = "/"
, hmm = window.parent.hmm
, v = { cmd: "", pathY: 0 }
, lines = []
, yOffset = 0
const ti = {//terminal interface
echo(t) {
tx = 0
ty++
lines.push({
t,
fg: '#fff',
x: tx,
y: ty
})
},
err(t) {
tx = 0
ty++
lines.push({
t,
fg: '#f00',
x: tx,
y: ty
})
},
eval(c) { return eval(c) }
}
function r(o) {
rText(o.t, o.fg, o.bg, o.x, o.y + yOffset)
}
function quit() {
window.hmmWin.children[0].children[1].onclick({target: window.hmmWin.children[0].children[1]})
}
requestAnimationFrame(function draw() {
clear()
if (path) {
tx = 0
lines[0] = ({
t: cwd + " $",
fg: "#48f",
x: tx,
y: ty + 1
})
tx = cwd.length + 3
lines[1] = ({
t: v.cmd,
fg: "#fff",
x: tx,
y: ty + 1
})
tx += v.cmd.length
lines[2] = ({
t: " ",
fg: "#000",
bg: "#fff",
x: tx,
y: ty + 1
})//cursor
}
lines.forEach(r)
requestAnimationFrame(draw)
})
window.onkeydown = (ev) => {
if (path) {
if (ev.code == "Backspace") {
v.cmd = v.cmd.slice(0, -1)
} else if (ev.code == "Enter") {
//run command
path = false
tx = 0
lines.push({
t: cwd + " $",
fg: "#48f",
x: tx,
y: ty + 1
})
tx = cwd.length + 3
lines.push({
t: v.cmd,
fg: "#fff",
x: tx,
y: ty + 1
})
tx = 0
ty++
lines[2].bg = "#333"
hmm.$(v.cmd, ti)
.then(e => {
path = true
})
v.cmd = ''
} else {
v.cmd += (ev.key.length == 1) ? ev.key : ''
}
}
}
//todo make mobile friendly (if not possible render scroll arrows as part of shell)
window.onwheel = window.onmousewheel = (ev) => {
yOffset -= ev.deltaY / 15
if (yOffset > 0) yOffset = 0
if (yOffset < -ty-1) yOffset = -ty-1
}
})()