more autoexec

This commit is contained in:
minjaesong
2020-11-04 17:14:47 +09:00
parent ab0827b96c
commit 8643f354e6
3 changed files with 66 additions and 22 deletions

View File

@@ -1,3 +1,6 @@
echo "Hello, world!" echo "Starting TVDOS..."
fsh
command rem put set-xxx commands here:
rem this line specifies which shell to be presented after the boot precess:
command /fancy

View File

@@ -378,7 +378,7 @@ con.curs_set = function(arg) {
print(String.fromCharCode(27,91)+"?25"+(((arg|0) == 0) ? "l" : "h")); print(String.fromCharCode(27,91)+"?25"+(((arg|0) == 0) ? "l" : "h"));
}; };
con.reset_graphics = function() { con.reset_graphics = function() {
println(String.fromCharCode(27,91,109)); print(String.fromCharCode(27,91,109));
}; };
Object.freeze(con); Object.freeze(con);
// system management function // system management function

View File

@@ -3,14 +3,38 @@ let CURRENT_DRIVE = "A";
let executableExtensions = [".com",".bat",".js", ""]; Object.freeze(executableExtensions); let executableExtensions = [".com",".bat",".js", ""]; Object.freeze(executableExtensions);
let shell_pwd = []; let shell_pwd = [];
let goInteractive = false;
let goFancy = false;
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() {
print(CURRENT_DRIVE + ":\\" + shell_pwd.join("\\") + PROMPT_TEXT); if (goFancy) {
con.color_pair(239,161);
print(" "+CURRENT_DRIVE+":");
con.color_pair(161,253);
con.addch(16);
con.color_pair(0,253);
print(" \\"+shell_pwd.join("\\")+" ");
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);
} }
function greet() { function greet() {
println(welcome_text); if (goFancy) {
con.color_pair(0,253);
//print(welcome_text + " ".repeat(_fsh.scrwidth - welcome_text.length));
print(welcome_text + " ".repeat(80 - welcome_text.length));
con.color_pair(239,255);
println();
}
else
println(welcome_text);
} }
@@ -38,12 +62,12 @@ shell.parse = function(input) {
LIMBO -> QUOTE [label="\""] LIMBO -> QUOTE [label="\""]
LIMBO -> LIMBO [label="space"] LIMBO -> LIMBO [label="space"]
}*/ }*/
if (mode == "LITERAL") { if ("LITERAL" == mode) {
if (c == ' ') { if (' ' == c) {
tokens.push(stringBuffer); stringBuffer = ""; tokens.push(stringBuffer); stringBuffer = "";
mode = "LIMBO"; mode = "LIMBO";
} }
else if (c == '"') { else if ('"' == c) {
tokens.push(stringBuffer); stringBuffer = ""; tokens.push(stringBuffer); stringBuffer = "";
mode = "QUOTE"; mode = "QUOTE";
} }
@@ -51,8 +75,8 @@ shell.parse = function(input) {
stringBuffer += c; stringBuffer += c;
} }
} }
else if (mode == "LIMBO") { else if ("LIMBO" == mode) {
if (c == '"') { if ('"' == c) {
mode = "QUOTE"; mode = "QUOTE";
} }
else if (c != ' ') { else if (c != ' ') {
@@ -60,20 +84,20 @@ shell.parse = function(input) {
stringBuffer += c; stringBuffer += c;
} }
} }
else if (mode == "QUOTE") { else if ("QUOTE" == mode) {
if (c == '"') { if ('"' == c) {
tokens.push(stringBuffer); stringBuffer = ""; tokens.push(stringBuffer); stringBuffer = "";
mode = "LIMBO"; mode = "LIMBO";
} }
else if (c == '^') { else if ('^' == c) {
mode = "ESCAPE"; mode = "ESCAPE";
} }
else { else {
stringBuffer += c; stringBuffer += c;
} }
} }
else if (mode == "ESCAPE") { else if ("ESCAPE" == mode) {
TODO();
} }
i += 1; i += 1;
@@ -116,7 +140,7 @@ shell.coreutils = {
}; };
Object.freeze(shell.coreutils); Object.freeze(shell.coreutils);
shell.execute = function(line) { shell.execute = function(line) {
if (line.size == 0) return; if (0 == line.size) return;
let tokens = shell.parse(line); let tokens = shell.parse(line);
let cmd = tokens[0]; let cmd = tokens[0];
@@ -175,28 +199,43 @@ Object.freeze(shell);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (exec_args[1] !== undefined) { if (exec_args[1] !== undefined) {
// only meaningful switches would be either /c or /k anyway
let firstSwitch = exec_args[1].toLowerCase();
// command /c <commands> // command /c <commands>
// ^[0] ^[1] ^[2] // ^[0] ^[1] ^[2]
if (exec_args[1].toLowerCase() == "/c") { if ("/c" == firstSwitch) {
if (exec_args[2] == "") return 0; // no commands were given, just exit successfully if ("" == exec_args[2]) return 0; // no commands were given, just exit successfully
return shell.execute(exec_args[2]); return shell.execute(exec_args[2]);
} }
else if ("/k" == firstSwitch) {
if ("" == exec_args[2]) return 0; // no commands were given, just exit successfully
shell.execute(exec_args[2]);
goInteractive = true;
}
else if ("/fancy" == firstSwitch) {
goFancy = true;
goInteractive = true;
}
else { else {
printerrln("Invalid switch: "+exec_args[1]); printerrln("Invalid switch: "+exec_args[1]);
return 1; return 1;
} }
} }
else { else {
goInteractive = true;
}
if (goInteractive) {
con.reset_graphics(); con.reset_graphics();
println("Starting TVDOS...");
greet(); greet();
let cmdHistory = []; // zeroth element is the oldest let cmdHistory = []; // zeroth element is the oldest
let cmdHistoryScroll = 0; // 0 for outside-of-buffer, 1 for most recent let cmdHistoryScroll = 0; // 0 for outside-of-buffer, 1 for most recent
let cmdExit = false; let cmdExit = false;
while (!cmdExit) { while (!cmdExit) {
con.reset_graphics();
print_prompt_text(); print_prompt_text();
let cmdbuf = ""; let cmdbuf = "";
@@ -217,12 +256,14 @@ else {
} }
// enter // enter
else if (key === 10 || key === 13) { else if (key === 10 || key === 13) {
let errorlevel = 0;
println(); println();
try { try {
shell.execute(cmdbuf); errorlevel = shell.execute(cmdbuf);
} }
catch (e) { catch (e) {
printerrln(e); printerrln(e);
errorlevel = -128;
} }
finally { finally {
if (cmdbuf.trim().length > 0) if (cmdbuf.trim().length > 0)