mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-03-07 19:51:51 +09:00
command.js: displaying errorlevel when app quit with error
This commit is contained in:
@@ -1,17 +1,17 @@
|
||||
println("JS Console");
|
||||
var _cmdHistory = []; // zeroth element is the oldest
|
||||
var _cmdHistoryScroll = 0; // 0 for outside-of-buffer, 1 for most recent
|
||||
let _cmdHistory = []; // zeroth element is the oldest
|
||||
let _cmdHistoryScroll = 0; // 0 for outside-of-buffer, 1 for most recent
|
||||
while (true) {
|
||||
print("JS> ");
|
||||
|
||||
var _cmdbuf = "";
|
||||
let _cmdbuf = "";
|
||||
|
||||
while (true) {
|
||||
var key = con.getch();
|
||||
let key = con.getch();
|
||||
|
||||
// printable chars
|
||||
if (key >= 32 && key <= 126) {
|
||||
var __sss = String.fromCharCode(key);
|
||||
let __sss = String.fromCharCode(key);
|
||||
_cmdbuf += __sss;
|
||||
print(__sss);
|
||||
}
|
||||
@@ -24,10 +24,11 @@ while (true) {
|
||||
else if (key === 10 || key === 13) {
|
||||
println();
|
||||
try {
|
||||
println(eval(_cmdbuf));
|
||||
let prg = eval("let _appStub=function(){"+_cmdbuf+"};_appStub;"); // making 'exec_args' a app-level global
|
||||
println(prg());
|
||||
}
|
||||
catch (e) {
|
||||
println(e);
|
||||
printerrln(e);
|
||||
}
|
||||
finally {
|
||||
if (_cmdbuf.trim().length > 0)
|
||||
@@ -42,7 +43,7 @@ while (true) {
|
||||
_cmdHistoryScroll += 1;
|
||||
|
||||
// back the cursor in order to type new cmd
|
||||
var __xx = 0;
|
||||
let __xx = 0;
|
||||
for (__xx = 0; __xx < _cmdbuf.length; __xx++) print(String.fromCharCode(8));
|
||||
_cmdbuf = _cmdHistory[_cmdHistory.length - _cmdHistoryScroll];
|
||||
// re-type the new command
|
||||
@@ -53,7 +54,7 @@ while (true) {
|
||||
else if (key === 20) {
|
||||
if (_cmdHistoryScroll > 0) {
|
||||
// back the cursor in order to type new cmd
|
||||
var __xx = 0;
|
||||
let __xx = 0;
|
||||
for (__xx = 0; __xx < _cmdbuf.length; __xx++) print(String.fromCharCode(8));
|
||||
_cmdbuf = _cmdHistory[_cmdHistory.length - _cmdHistoryScroll];
|
||||
// re-type the new command
|
||||
|
||||
@@ -126,5 +126,4 @@ var execApp = function(cmdsrc, args) {
|
||||
serial.println("TVDOS.SYS initialised, running boot script...");
|
||||
var _G = {};
|
||||
filesystem.open("A", "tvdos/bin/command.js", "R");
|
||||
let cmdsrc = filesystem.readAll("A");
|
||||
execApp(cmdsrc, ["", "/c", "\\AUTOEXEC.BAT"]);
|
||||
execApp(filesystem.readAll("A"), ["", "/c", "\\AUTOEXEC.BAT"]);
|
||||
|
||||
@@ -7,6 +7,8 @@ let goFancy = false;
|
||||
|
||||
let DEBUG_PRINT = true;
|
||||
|
||||
let errorlevel = 0;
|
||||
|
||||
const welcome_text = "TSVM Disk Operating System, version " + _TVDOS.VERSION;
|
||||
|
||||
function print_prompt_text() {
|
||||
@@ -17,13 +19,21 @@ function print_prompt_text() {
|
||||
con.addch(16);
|
||||
con.color_pair(0,253);
|
||||
print(" \\"+shell_pwd.join("\\").substring(1)+" ");
|
||||
if (errorlevel != 0) {
|
||||
con.color_pair(211,253);
|
||||
print("["+errorlevel+"] ");
|
||||
}
|
||||
con.color_pair(253,255);
|
||||
con.addch(16);
|
||||
con.addch(32);
|
||||
con.color_pair(239,255);
|
||||
}
|
||||
else
|
||||
print(CURRENT_DRIVE + ":\\" + shell_pwd.join("\\") + PROMPT_TEXT);
|
||||
else {
|
||||
if (errorlevel != 0)
|
||||
print(CURRENT_DRIVE + ":\\" + shell_pwd.join("\\") + " [" + errorlevel + "]" + PROMPT_TEXT);
|
||||
else
|
||||
print(CURRENT_DRIVE + ":\\" + shell_pwd.join("\\") + PROMPT_TEXT);
|
||||
}
|
||||
}
|
||||
|
||||
function greet() {
|
||||
@@ -298,7 +308,7 @@ shell.execute = function(line) {
|
||||
|
||||
if (!fileExists) {
|
||||
printerrln('Bad command or filename: "'+cmd+'"');
|
||||
return -1;
|
||||
return 127;
|
||||
}
|
||||
else {
|
||||
let prg = filesystem.readAll(CURRENT_DRIVE);
|
||||
@@ -383,14 +393,16 @@ if (goInteractive) {
|
||||
}
|
||||
// enter
|
||||
else if (key === 10 || key === 13) {
|
||||
let errorlevel = 0;
|
||||
println();
|
||||
try {
|
||||
errorlevel = 0; // reset the number
|
||||
errorlevel = shell.execute(cmdbuf);
|
||||
}
|
||||
catch (e) {
|
||||
printerrln(e);
|
||||
errorlevel = -128;
|
||||
printerrln("\n"+e);
|
||||
if (errorlevel === 0 || errorlevel === undefined) {
|
||||
errorlevel = 1; // generic failure
|
||||
}
|
||||
}
|
||||
finally {
|
||||
if (cmdbuf.trim().length > 0)
|
||||
|
||||
Reference in New Issue
Block a user