Skip to content

Commit

Permalink
Added scrolling to terminal
Browse files Browse the repository at this point in the history
  • Loading branch information
Electogenius committed Dec 12, 2021
1 parent ce9b305 commit 6128e97
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
7 changes: 4 additions & 3 deletions cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ hmm.storage.cmd = {
help(c) {
`Built-in commands:
cd: change current directory
clear: clears screen
echo: displays text
err: displays an error
ls: lists folders and files in the current directory
Expand Down Expand Up @@ -72,14 +73,14 @@ wait: wait a certain amount of milliseconds
},
cd(){
c.eval('cwd=atob("'+btoa(hmm.pathToPath(e.join``,c.eval('cwd')))+'")')
,new Promise(r => r())
,0[0]
},
ls(){
var f=hmm.pathToJs(hmm.pathToPath(e.join``,c.eval('cwd')))
Object.keys(f).sort().forEach(c.echo)
,new Promise(r => r())
,0[0]
},
clear(){c.eval('lines=[];ty=-1'),0[0]}
clear(){c.eval('lines=[];ty=-1;yOffset=0'),0[0]}
}
for (const cmd in hmm.storage.cmd) {
hmm.storage.cmd[cmd] = String(hmm.storage.cmd[cmd])
Expand Down
14 changes: 10 additions & 4 deletions shmm.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
, hmm = window.parent.hmm
, v = { cmd: "", pathY: 0 }
, lines = []
, yOffset = 0
const ti = {//terminal interface
echo(t) {
tx = 0
Expand All @@ -28,10 +29,10 @@
y: ty
})
},
eval(c){return eval(c)}
eval(c) { return eval(c) }
}
function r(o) {
rText(o.t, o.fg, o.bg, o.x, o.y)
rText(o.t, o.fg, o.bg, o.x, o.y + yOffset)
}
requestAnimationFrame(function draw() {
clear()
Expand Down Expand Up @@ -83,9 +84,9 @@
x: tx,
y: ty + 1
})
tx=0
tx = 0
ty++
lines[2].bg="#333"
lines[2].bg = "#333"
hmm.$(v.cmd, ti)
.then(e => {
path = true
Expand All @@ -96,4 +97,9 @@
}
}
}
window.onwheel = window.onmousewheel = (ev) => {
yOffset -= ev.deltaY / 15
if (yOffset > 0) yOffset = 0
if (yOffset < -ty-1) yOffset = -ty-1
}
})()

0 comments on commit 6128e97

Please sign in to comment.