mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-06-11 07:14:04 +09:00
edit.js can write file to disk
This commit is contained in:
@@ -43,6 +43,8 @@ function reset_status() {
|
|||||||
cursorCol = 0;
|
cursorCol = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DRAWING FUNCTIONS //
|
||||||
|
|
||||||
function drawInit() {
|
function drawInit() {
|
||||||
windowWidth = con.getmaxyx()[1];
|
windowWidth = con.getmaxyx()[1];
|
||||||
windowHeight = con.getmaxyx()[0];
|
windowHeight = con.getmaxyx()[0];
|
||||||
@@ -51,7 +53,18 @@ function drawInit() {
|
|||||||
paintHeight = windowHeight-2;
|
paintHeight = windowHeight-2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function drawLnCol() {
|
||||||
|
con.curs_set(0);
|
||||||
|
con.color_pair(COL_BACK, COL_TEXT);
|
||||||
|
let lctxt = `${String.fromCharCode(25)}${cursorRow+1}:${cursorCol+1}`;
|
||||||
|
for (let i = 0; i < lctxt.length; i++) {
|
||||||
|
con.mvaddch(1, windowWidth- lctxt.length + i, lctxt.charCodeAt(i));
|
||||||
|
}
|
||||||
|
con.color_pair(COL_TEXT, COL_BACK);
|
||||||
|
}
|
||||||
|
|
||||||
function drawMain() {
|
function drawMain() {
|
||||||
|
con.curs_set(0);
|
||||||
drawInit();
|
drawInit();
|
||||||
con.clear();
|
con.clear();
|
||||||
|
|
||||||
@@ -89,16 +102,13 @@ function drawMain() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// print status line
|
// print status line
|
||||||
con.color_pair(COL_BACK, COL_TEXT);
|
drawLnCol();
|
||||||
let lctxt = `${String.fromCharCode(25)}${cursorRow+1}:${cursorCol+1}`;
|
|
||||||
for (let i = 0; i < lctxt.length; i++) {
|
|
||||||
con.mvaddch(1, windowWidth- lctxt.length + i, lctxt.charCodeAt(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
con.move(2,5); con.color_pair(COL_TEXT, COL_BACK);
|
con.move(2,5); con.color_pair(COL_TEXT, COL_BACK);
|
||||||
}
|
}
|
||||||
|
|
||||||
function drawMenubarBase(index) {
|
function drawMenubarBase(index) {
|
||||||
|
con.curs_set(0);
|
||||||
drawInit();
|
drawInit();
|
||||||
con.clear();
|
con.clear();
|
||||||
|
|
||||||
@@ -135,6 +145,7 @@ function drawMenubarBase(index) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function drawTextLine(paintRow) {
|
function drawTextLine(paintRow) {
|
||||||
|
con.curs_set(0);
|
||||||
for(let x = 0; x < paintWidth; x++) {
|
for(let x = 0; x < paintWidth; x++) {
|
||||||
let charCode = (undefined === textbuffer[scroll + paintRow]) ? 0 : textbuffer[scroll + paintRow].charCodeAt(x)|0; // or-zero to convert NaN into 0
|
let charCode = (undefined === textbuffer[scroll + paintRow]) ? 0 : textbuffer[scroll + paintRow].charCodeAt(x)|0; // or-zero to convert NaN into 0
|
||||||
con.mvaddch(2+paintRow, 5+x, charCode);
|
con.mvaddch(2+paintRow, 5+x, charCode);
|
||||||
@@ -142,6 +153,7 @@ function drawTextLine(paintRow) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function drawTextbuffer() {
|
function drawTextbuffer() {
|
||||||
|
con.curs_set(0);
|
||||||
for (let k = 0; k < paintHeight; k++) {
|
for (let k = 0; k < paintHeight; k++) {
|
||||||
drawTextLine(k)
|
drawTextLine(k)
|
||||||
}
|
}
|
||||||
@@ -149,11 +161,12 @@ function drawTextbuffer() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function displayBulletin(text) {
|
function displayBulletin(text) {
|
||||||
|
con.curs_set(0);
|
||||||
bulletinShown = true;
|
bulletinShown = true;
|
||||||
let txt = text.substring(0, windowWidth - 10);
|
let txt = text.substring(0, windowWidth - 10);
|
||||||
con.move(windowHeight - 1, (windowWidth - txt.length) / 2);
|
con.move(windowHeight - 1, (windowWidth - txt.length) / 2);
|
||||||
con.color_pair(COL_BACK, COL_TEXT);
|
con.color_pair(COL_BACK, COL_TEXT);
|
||||||
print(`[${txt}]`);
|
print(` ${txt} `);
|
||||||
con.color_pair(COL_TEXT, COL_BACK);
|
con.color_pair(COL_TEXT, COL_BACK);
|
||||||
gotoText();
|
gotoText();
|
||||||
}
|
}
|
||||||
@@ -165,8 +178,20 @@ function dismissBulletin() {
|
|||||||
|
|
||||||
function gotoText() {
|
function gotoText() {
|
||||||
con.move(2 + cursorRow, 5 + cursorCol);
|
con.move(2 + cursorRow, 5 + cursorCol);
|
||||||
|
con.curs_set(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// FUNCTIONING FUNCTIONS (LOL) //
|
||||||
|
|
||||||
|
function writeout() {
|
||||||
|
var driveLetter = _G.shell.getCurrentDrive();
|
||||||
|
filesystem.open(driveLetter, filename, "W");
|
||||||
|
filesystem.write(driveLetter, textbuffer.join('\n'));
|
||||||
|
}
|
||||||
|
|
||||||
|
// KEYBOARDING FUNCTIONS //
|
||||||
|
|
||||||
function hitCtrlS() {
|
function hitCtrlS() {
|
||||||
sys.poke(-40, 1);
|
sys.poke(-40, 1);
|
||||||
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));
|
||||||
@@ -188,6 +213,7 @@ function appendText(code) {
|
|||||||
|
|
||||||
cursorCol += 1;
|
cursorCol += 1;
|
||||||
drawTextLine(cursorRow - scroll);
|
drawTextLine(cursorRow - scroll);
|
||||||
|
drawLnCol();
|
||||||
gotoText();
|
gotoText();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,15 +222,21 @@ drawMain();
|
|||||||
drawTextbuffer();
|
drawTextbuffer();
|
||||||
|
|
||||||
let bulletinShown = false;
|
let bulletinShown = false;
|
||||||
|
|
||||||
|
// TODO for existing file, show [ Read $n Lines ]
|
||||||
|
// TODO for new file, show [ New File ]
|
||||||
|
displayBulletin(`Wrote ${textbuffer.length} Lines`);
|
||||||
|
|
||||||
while (!exit) {
|
while (!exit) {
|
||||||
let key = con.getch();
|
let key = con.getch();
|
||||||
|
|
||||||
serial.println(key);
|
serial.println(`[edit.js] keycode = ${key}`);
|
||||||
|
|
||||||
if (key == 24) // Ctrl-X
|
if (key == 24) // Ctrl-X
|
||||||
exit = true;
|
exit = true;
|
||||||
else if (key == 19 && !bulletinShown) {
|
else if (key == 19 && !bulletinShown) {
|
||||||
displayBulletin(`Wrote ${100 + ((Math.random() * 900)|0)} lines`);
|
writeout();
|
||||||
|
displayBulletin(`Wrote ${textbuffer.length} lines`);
|
||||||
}
|
}
|
||||||
else if (key >= 32) { // printables (excludes \n)
|
else if (key >= 32) { // printables (excludes \n)
|
||||||
if (bulletinShown) {
|
if (bulletinShown) {
|
||||||
|
|||||||
Reference in New Issue
Block a user