From 6128e9752495a3defc3b4b5fb81d1d2f69a54252 Mon Sep 17 00:00:00 2001 From: Electogenius <69585636+Electogenius@users.noreply.github.com> Date: Sun, 12 Dec 2021 17:55:16 +0530 Subject: [PATCH] Added scrolling to terminal --- cmd.js | 7 ++++--- shmm.js | 14 ++++++++++---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/cmd.js b/cmd.js index a0228c7..e6f5bfd 100644 --- a/cmd.js +++ b/cmd.js @@ -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 @@ -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]) diff --git a/shmm.js b/shmm.js index 4b97a36..b96f1cb 100644 --- a/shmm.js +++ b/shmm.js @@ -7,6 +7,7 @@ , hmm = window.parent.hmm , v = { cmd: "", pathY: 0 } , lines = [] + , yOffset = 0 const ti = {//terminal interface echo(t) { tx = 0 @@ -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() @@ -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 @@ -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 + } })() \ No newline at end of file