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