mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-06-12 15:44:05 +09:00
less:u d commands, new app 'hexdump'
This commit is contained in:
@@ -29,6 +29,7 @@ let buf = "";
|
||||
let fileContent = filesystem.readAll(_G.shell.getCurrentDrive());
|
||||
let key = -1;
|
||||
let panSize = termW >> 1;
|
||||
let scrollSize = termH >> 3;
|
||||
|
||||
// initialise some helper variables
|
||||
let lineToBytes = [0];
|
||||
@@ -50,6 +51,12 @@ let cy = 1;
|
||||
let cx = 1;
|
||||
let char = -1;
|
||||
|
||||
let numbuf = 0;
|
||||
|
||||
let resetKeyReadStatus = function() {
|
||||
numbuf = 0;
|
||||
}
|
||||
|
||||
let repaint = function() {
|
||||
con.move(1,1); con.clear();
|
||||
|
||||
@@ -75,20 +82,23 @@ let repaint = function() {
|
||||
}
|
||||
|
||||
repaint();
|
||||
con.move(termH + 1, 1);
|
||||
print(":"+" ".repeat(termW - 2));
|
||||
con.move(termH + 1, 2);
|
||||
while (true) {
|
||||
// read a key
|
||||
con.mvaddch(termH + 1,1,58);
|
||||
con.move(termH + 1, 2);
|
||||
key = con.getch();
|
||||
// do something with key read
|
||||
/*Q*/if (key == 113 || key == 81) break;
|
||||
/*R*/else if (key == 114 || key == 82) repaint();
|
||||
/*up*/else if (key == 19 && scroll > 0) {
|
||||
scroll -= 1;
|
||||
/*up*/else if (key == 19) {
|
||||
scroll -= scrollSize;
|
||||
if (scroll < 0) scroll = 0;
|
||||
repaint();
|
||||
}
|
||||
/*down*/else if (key == 20 && scroll < lineToBytes.length - termH) {
|
||||
scroll += 1;
|
||||
/*down*/else if (key == 20) {
|
||||
scroll += scrollSize;
|
||||
if (scroll > lineToBytes.length - termH) scroll = lineToBytes.length - termH;
|
||||
repaint();
|
||||
}
|
||||
/*left*/else if (key == 21 && pan > 0) {
|
||||
@@ -99,6 +109,34 @@ while (true) {
|
||||
pan += panSize;
|
||||
repaint();
|
||||
}
|
||||
/*0-9*/else if (key >= 48 && key <= 57) {
|
||||
print(String.fromCharCode(key));
|
||||
numbuf = (numbuf * 10) + (key - 48);
|
||||
}
|
||||
/*bksp*/else if (key == 8) {
|
||||
if (numbuf > 0) print(String.fromCharCode(key));
|
||||
numbuf = (numbuf / 10)|0;
|
||||
}
|
||||
/*u*/else if (key == 117) {
|
||||
scroll -= numbuf;
|
||||
if (scroll < 0) scroll = 0;
|
||||
repaint();
|
||||
}
|
||||
/*d*/else if (key == 100) {
|
||||
scroll += numbuf;
|
||||
if (scroll > lineToBytes.length - termH) scroll = lineToBytes.length - termH;
|
||||
repaint();
|
||||
}
|
||||
|
||||
|
||||
if (!(key >= 48 && key <= 57 || key == 8)) {
|
||||
resetKeyReadStatus();
|
||||
con.move(termH + 1, 1);
|
||||
print(":"+" ".repeat(termW - 2));
|
||||
con.move(termH + 1, 2);
|
||||
}
|
||||
|
||||
serial.println("numbuf = "+numbuf);
|
||||
}
|
||||
|
||||
con.move(termH + 1, 1);
|
||||
|
||||
Reference in New Issue
Block a user