mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-06-08 22:34:03 +09:00
fixing edit.js wip
This commit is contained in:
@@ -229,17 +229,21 @@ function writeout() {
|
|||||||
// KEYBOARDING FUNCTIONS //
|
// KEYBOARDING FUNCTIONS //
|
||||||
|
|
||||||
function hitCtrlS() {
|
function hitCtrlS() {
|
||||||
sys.poke(-40, 1);
|
sys.poke(-40, 255);
|
||||||
return (sys.peek(-41) == 47 && (sys.peek(-42) == 129 || sys.peek(-42) == 130));
|
return (sys.peek(-41) == 47 && (sys.peek(-42) == 129 || sys.peek(-42) == 130));
|
||||||
}
|
}
|
||||||
function hitCtrlX() {
|
function hitCtrlQ() {
|
||||||
sys.poke(-40, 1);
|
sys.poke(-40, 255);
|
||||||
return (sys.peek(-41) == 52 && (sys.peek(-42) == 129 || sys.peek(-42) == 130));
|
return (sys.peek(-41) == 45 && (sys.peek(-42) == 129 || sys.peek(-42) == 130));
|
||||||
}
|
}
|
||||||
function hitAny() {
|
function hitAny() {
|
||||||
sys.poke(-40, 1);
|
sys.poke(-40, 255);sys.spin();
|
||||||
return sys.peek(-41) != 0;
|
return sys.peek(-41) != 0;
|
||||||
}
|
}
|
||||||
|
function getch() {
|
||||||
|
sys.poke(-40, 255);
|
||||||
|
return sys.peek(-41);
|
||||||
|
}
|
||||||
|
|
||||||
function insertChar(code, row, col) {
|
function insertChar(code, row, col) {
|
||||||
if (textbuffer[row] === undefined)
|
if (textbuffer[row] === undefined)
|
||||||
@@ -427,74 +431,83 @@ else {
|
|||||||
}
|
}
|
||||||
|
|
||||||
while (!exit) {
|
while (!exit) {
|
||||||
let key = con.getch();
|
let key = getch();
|
||||||
|
// TODO: either implement the new strobing-getch() by yourself or modify the sys.getch() so that CTRL-alph would return correct numbers
|
||||||
|
if (key != 0) {
|
||||||
|
|
||||||
if (bulletinShown) dismissBulletin();
|
serial.println(`getch = ${key}`)
|
||||||
|
|
||||||
if (key == 17) // Ctrl-Q
|
if (bulletinShown) dismissBulletin();
|
||||||
exit = true;
|
|
||||||
else if (key == 19 && !bulletinShown) {
|
|
||||||
writeout();
|
|
||||||
displayBulletin(`Wrote ${textbuffer.length} lines`);
|
|
||||||
}
|
|
||||||
else if (key == con.KEY_BACKSPACE) { // Bksp
|
|
||||||
backspaceOnce();
|
|
||||||
drawLnCol(); gotoText();
|
|
||||||
}
|
|
||||||
else if (key == con.KEY_RETURN) { // Return
|
|
||||||
appendLine(); drawLnCol(); gotoText();
|
|
||||||
}
|
|
||||||
else if (key == con.KEY_LEFT) {
|
|
||||||
cursoringCol = cursorCol - 1;
|
|
||||||
if (cursoringCol < 0) cursoringCol = 0;
|
|
||||||
cursorMoveRelative(-1,0);
|
|
||||||
}
|
|
||||||
else if (key == con.KEY_RIGHT) {
|
|
||||||
cursoringCol = cursorCol + 1;
|
|
||||||
if (cursoringCol > textbuffer[cursorRow].length) cursoringCol = textbuffer[cursorRow].length;
|
|
||||||
cursorMoveRelative(1,0);
|
|
||||||
}
|
|
||||||
else if (key == con.KEY_UP) {
|
|
||||||
cursorMoveRelative(0,-1);
|
|
||||||
}
|
|
||||||
else if (key == con.KEY_DOWN) {
|
|
||||||
cursorMoveRelative(0,1);
|
|
||||||
}
|
|
||||||
else if (key == con.KEY_PAGE_UP) {
|
|
||||||
cursorMoveRelative(0, -paintHeight + scrollPeek);
|
|
||||||
}
|
|
||||||
else if (key == con.KEY_PAGE_DOWN) {
|
|
||||||
cursorMoveRelative(0, paintHeight - scrollPeek);
|
|
||||||
}
|
|
||||||
else if (key == con.KEY_HOME) {
|
|
||||||
cursoringCol = 0;
|
|
||||||
cursorMoveRelative(-BIG_STRIDE, 0);
|
|
||||||
}
|
|
||||||
else if (key == con.KEY_END) {
|
|
||||||
cursoringCol = textbuffer[cursorRow].length;
|
|
||||||
cursorMoveRelative(BIG_STRIDE, 0);
|
|
||||||
}
|
|
||||||
else if (key == con.KEY_TAB) { // insert spaces appropriately
|
|
||||||
let tabsize = TAB_SIZE - (cursorCol % TAB_SIZE);
|
|
||||||
|
|
||||||
for (let k = 0; k < tabsize; k++) {
|
sys.poke(-40, 255)
|
||||||
insertChar(32, cursorRow, cursorCol);
|
serial.println(`strobe: ${sys.peek(-41)}\t${sys.peek(-42)}`)
|
||||||
|
|
||||||
|
|
||||||
|
if (hitCtrlQ()) // Ctrl-Q
|
||||||
|
exit = true;
|
||||||
|
else if (hitCtrlS() && !bulletinShown) {
|
||||||
|
writeout();
|
||||||
|
displayBulletin(`Wrote ${textbuffer.length} lines`);
|
||||||
|
}
|
||||||
|
else if (key == con.KEY_BACKSPACE) { // Bksp
|
||||||
|
backspaceOnce();
|
||||||
|
drawLnCol(); gotoText();
|
||||||
|
}
|
||||||
|
else if (key == con.KEY_RETURN) { // Return
|
||||||
|
appendLine(); drawLnCol(); gotoText();
|
||||||
|
}
|
||||||
|
else if (key == con.KEY_LEFT) {
|
||||||
|
cursoringCol = cursorCol - 1;
|
||||||
|
if (cursoringCol < 0) cursoringCol = 0;
|
||||||
|
cursorMoveRelative(-1,0);
|
||||||
|
}
|
||||||
|
else if (key == con.KEY_RIGHT) {
|
||||||
|
cursoringCol = cursorCol + 1;
|
||||||
|
if (cursoringCol > textbuffer[cursorRow].length) cursoringCol = textbuffer[cursorRow].length;
|
||||||
|
cursorMoveRelative(1,0);
|
||||||
|
}
|
||||||
|
else if (key == con.KEY_UP) {
|
||||||
|
cursorMoveRelative(0,-1);
|
||||||
|
}
|
||||||
|
else if (key == con.KEY_DOWN) {
|
||||||
|
cursorMoveRelative(0,1);
|
||||||
|
}
|
||||||
|
else if (key == con.KEY_PAGE_UP) {
|
||||||
|
cursorMoveRelative(0, -paintHeight + scrollPeek);
|
||||||
|
}
|
||||||
|
else if (key == con.KEY_PAGE_DOWN) {
|
||||||
|
cursorMoveRelative(0, paintHeight - scrollPeek);
|
||||||
|
}
|
||||||
|
else if (key == con.KEY_HOME) {
|
||||||
|
cursoringCol = 0;
|
||||||
|
cursorMoveRelative(-BIG_STRIDE, 0);
|
||||||
|
}
|
||||||
|
else if (key == con.KEY_END) {
|
||||||
|
cursoringCol = textbuffer[cursorRow].length;
|
||||||
|
cursorMoveRelative(BIG_STRIDE, 0);
|
||||||
|
}
|
||||||
|
else if (key == con.KEY_TAB) { // insert spaces appropriately
|
||||||
|
let tabsize = TAB_SIZE - (cursorCol % TAB_SIZE);
|
||||||
|
|
||||||
|
for (let k = 0; k < tabsize; k++) {
|
||||||
|
insertChar(32, cursorRow, cursorCol);
|
||||||
|
// identical to con.KEY_RIGHT
|
||||||
|
cursoringCol = cursorCol + 1;
|
||||||
|
if (cursoringCol > textbuffer[cursorRow].length) cursoringCol = textbuffer[cursorRow].length;
|
||||||
|
cursorMoveRelative(1,0);
|
||||||
|
// end of con.KEY_RIGHT
|
||||||
|
}
|
||||||
|
drawTextLineAbsolute(cursorRow, scrollHor); drawLnCol(); gotoText();
|
||||||
|
}
|
||||||
|
else if (key >= 32 && key < 128) { // printables (excludes \n)
|
||||||
|
insertChar(key, cursorRow, cursorCol);
|
||||||
// identical to con.KEY_RIGHT
|
// identical to con.KEY_RIGHT
|
||||||
cursoringCol = cursorCol + 1;
|
cursoringCol = cursorCol + 1;
|
||||||
if (cursoringCol > textbuffer[cursorRow].length) cursoringCol = textbuffer[cursorRow].length;
|
if (cursoringCol > textbuffer[cursorRow].length) cursoringCol = textbuffer[cursorRow].length;
|
||||||
cursorMoveRelative(1,0);
|
cursorMoveRelative(1,0);
|
||||||
// end of con.KEY_RIGHT
|
// end of con.KEY_RIGHT
|
||||||
|
drawTextLineAbsolute(cursorRow, scrollHor); drawLnCol(); gotoText();
|
||||||
}
|
}
|
||||||
drawTextLineAbsolute(cursorRow, scrollHor); drawLnCol(); gotoText();
|
|
||||||
}
|
|
||||||
else if (key >= 32 && key < 128) { // printables (excludes \n)
|
|
||||||
insertChar(key, cursorRow, cursorCol);
|
|
||||||
// identical to con.KEY_RIGHT
|
|
||||||
cursoringCol = cursorCol + 1;
|
|
||||||
if (cursoringCol > textbuffer[cursorRow].length) cursoringCol = textbuffer[cursorRow].length;
|
|
||||||
cursorMoveRelative(1,0);
|
|
||||||
// end of con.KEY_RIGHT
|
|
||||||
drawTextLineAbsolute(cursorRow, scrollHor); drawLnCol(); gotoText();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user