diff --git a/assets/disk0/tvdos/bin/edit.js b/assets/disk0/tvdos/bin/edit.js index 2670656..cac0fd4 100644 --- a/assets/disk0/tvdos/bin/edit.js +++ b/assets/disk0/tvdos/bin/edit.js @@ -16,12 +16,12 @@ let cursorRow = 0; let cursorCol = 0; let exit = false; let scene = -1; // -1: main, 0: filemenu, 1: editmenu , ... +let bulletinShown = false; // load existing file if it's there let editingExistingFile = filesystem.open(driveLetter, filePath, "R"); if (editingExistingFile) { textbuffer = filesystem.readAll(driveLetter).split("\n"); - serial.println(textbuffer); } let windowWidth = con.getmaxyx()[1]; @@ -218,8 +218,11 @@ function hitAny() { function appendText(code) { if (textbuffer[cursorRow] === undefined) textbuffer[cursorRow] = String.fromCharCode(code); - else - textbuffer[cursorRow] += String.fromCharCode(code); + else { + let s = textbuffer[cursorRow].substring(0); + textbuffer[cursorRow] = s.substring(0, cursorCol) + String.fromCharCode(code) + s.substring(cursorCol); + //textbuffer[cursorRow] += String.fromCharCode(code); + } cursorCol += 1; drawTextLine(cursorRow - scroll); @@ -247,19 +250,20 @@ function appendLine() { drawMain(); drawTextbuffer(); -let bulletinShown = false; - // show "welcome" message if (!editingExistingFile) displayBulletin(`New File`); -else +else { + // move to right end of the first line + cursorCol = textbuffer[0].length; + drawLnCol(); displayBulletin(`Read ${textbuffer.length} Lines`); - +} while (!exit) { let key = con.getch(); - serial.println(`[edit.js] keycode = ${key}`); + if (bulletinShown) dismissBulletin(); if (key == 24) // Ctrl-X exit = true; @@ -272,11 +276,13 @@ while (!exit) { else if (key == con.KEY_RETURN) { // Return appendLine(); } - else if (key >= 32) { // printables (excludes \n) - if (bulletinShown) { - dismissBulletin(); - } - + else if (key == con.KEY_LEFT && cursorCol > 0) { + cursorCol -= 1; drawLnCol(); gotoText(); + } + else if (key == con.KEY_RIGHT && cursorCol < textbuffer[cursorRow].length) { + cursorCol += 1; drawLnCol(); gotoText(); + } + else if (key >= 32 && key < 128) { // printables (excludes \n) appendText(key); } } diff --git a/assets/disk0/tvdos/tuidev/kyo_home.js b/assets/disk0/tvdos/tuidev/kyo_home.js index 7eea8cf..eb5dd73 100644 --- a/assets/disk0/tvdos/tuidev/kyo_home.js +++ b/assets/disk0/tvdos/tuidev/kyo_home.js @@ -3,17 +3,19 @@ let menu = [ {label:"BASIC",pwd:"\\",exec:"basic",args:""}, {label:"DOS",pwd:"\\",exec:"command",args:""}, - {label:"TEXT",pwd:"\\home",exec:"undefined",args:""}, + {label:"TEXT",pwd:"\\home",exec:"edit",args:""}, {label:"TELCOM",pwd:"\\home",exec:"undefined",args:""} ]; const MENU_COLS = 4; +const MENU_ROWS = 6; +const COL_SIZE = 10; function redraw() { con.clear(); - for (let i = 0; i < MENU_COLS*6; i++) { + for (let i = 0; i < MENU_COLS*MENU_ROWS; i++) { let m = menu[i]; - con.move(2+((i/MENU_COLS)|0),2+((i%MENU_COLS)*10)); + con.move(2+((i / MENU_COLS)|0),2+((i % MENU_COLS)*COL_SIZE)); print(m ? m.label : "-.-"); } }