mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-06-10 23:04:04 +09:00
LESS with horizontal scroll
This commit is contained in:
@@ -22,23 +22,28 @@ if (!fileOpened) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let scroll = 0;
|
let scroll = 0;
|
||||||
|
let pan = -1;
|
||||||
let termW = con.getmaxyx()[1];
|
let termW = con.getmaxyx()[1];
|
||||||
let termH = con.getmaxyx()[0] - 1;
|
let termH = con.getmaxyx()[0] - 1;
|
||||||
let buf = "";
|
let buf = "";
|
||||||
let fileContent = filesystem.readAll(_G.shell.getCurrentDrive());
|
let fileContent = filesystem.readAll(_G.shell.getCurrentDrive());
|
||||||
let key = -1;
|
let key = -1;
|
||||||
|
let panSize = termW >> 1;
|
||||||
|
|
||||||
// initialise some helper variables
|
// initialise some helper variables
|
||||||
let lineToBytes = [0];
|
let lineToBytes = [0];
|
||||||
|
let maxPan = 0;
|
||||||
|
let maxPanCur = 0;
|
||||||
for (let i = 0; i < fileContent.length; i++) {
|
for (let i = 0; i < fileContent.length; i++) {
|
||||||
let char = fileContent.charCodeAt(i);
|
let char = fileContent.charCodeAt(i);
|
||||||
|
maxPanCur += 1;
|
||||||
if (char == 10 || char == 13) {
|
if (char == 10 || char == 13) {
|
||||||
lineToBytes.push(i + 1);
|
lineToBytes.push(i + 1);
|
||||||
|
if (maxPanCur > maxPan) maxPan = maxPanCur;
|
||||||
|
maxPanCur = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
serial.println(lineToBytes);
|
|
||||||
|
|
||||||
let startAddr = -1;
|
let startAddr = -1;
|
||||||
let paintCur = 0;
|
let paintCur = 0;
|
||||||
let cy = 1;
|
let cy = 1;
|
||||||
@@ -49,19 +54,21 @@ let repaint = function() {
|
|||||||
con.move(1,1); con.clear();
|
con.move(1,1); con.clear();
|
||||||
|
|
||||||
startAddr = lineToBytes[scroll];
|
startAddr = lineToBytes[scroll];
|
||||||
cy = 1; cx = 1; paintCur = 0;
|
cy = 1; cx = -pan; paintCur = 0;
|
||||||
while (cy <= termH) {
|
while (cy <= termH) {
|
||||||
char = fileContent.charCodeAt(startAddr + paintCur);
|
char = fileContent.charCodeAt(startAddr + paintCur);
|
||||||
if (isNaN(char)) break;
|
if (isNaN(char)) break;
|
||||||
if (cy <= termH) {
|
if (cy <= termH) {
|
||||||
con.move(cy, cx);
|
if (cx >= 0 && cx < termW) {
|
||||||
if (char != 10 && char != 13)
|
con.move(cy, cx);
|
||||||
con.addch(char);
|
if (char != 10 && char != 13)
|
||||||
|
con.addch(char);
|
||||||
|
}
|
||||||
cx += 1;
|
cx += 1;
|
||||||
}
|
}
|
||||||
if (char == 10 || char == 13) {
|
if (char == 10 || char == 13) {
|
||||||
cy += 1;
|
cy += 1;
|
||||||
cx = 1;
|
cx = -pan;
|
||||||
}
|
}
|
||||||
paintCur += 1;
|
paintCur += 1;
|
||||||
}
|
}
|
||||||
@@ -84,6 +91,14 @@ while (true) {
|
|||||||
scroll += 1;
|
scroll += 1;
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
/*left*/else if (key == 21 && pan > 0) {
|
||||||
|
pan -= panSize;
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
/*right*/else if (key == 22 && pan < maxPan - termW) {
|
||||||
|
pan += panSize;
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
con.move(termH + 1, 1);
|
con.move(termH + 1, 1);
|
||||||
|
|||||||
Reference in New Issue
Block a user