mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-06-11 23:34:04 +09:00
default shell: testing coreutils with cd command
This commit is contained in:
@@ -10,7 +10,7 @@ _TVDOS.DRIVES["A"] = _BIOS.FIRST_BOOTABLE_PORT;
|
|||||||
|
|
||||||
_TVDOS.defaults = {
|
_TVDOS.defaults = {
|
||||||
path: [
|
path: [
|
||||||
""
|
"/tvdos/bin"
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
Object.freeze(_TVDOS);
|
Object.freeze(_TVDOS);
|
||||||
|
|||||||
@@ -1,16 +1,29 @@
|
|||||||
let PROMPT_TEXT = ">";
|
let PROMPT_TEXT = ">";
|
||||||
let CURRENT_DRIVE = "A";
|
let CURRENT_DRIVE = "A";
|
||||||
|
|
||||||
let shell_pwd = [""];
|
let shell_pwd = [];
|
||||||
|
|
||||||
const welcome_text = "TSVM Disk Operating System, version " + _TVDOS.VERSION;
|
const welcome_text = "TSVM Disk Operating System, version " + _TVDOS.VERSION;
|
||||||
|
|
||||||
function get_prompt_text() {
|
function print_prompt_text() {
|
||||||
return CURRENT_DRIVE + ":\\" + shell_pwd.join("\\") + PROMPT_TEXT;
|
//print(CURRENT_DRIVE + ":\\" + shell_pwd.join("\\") + PROMPT_TEXT);
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
function greet() {
|
function greet() {
|
||||||
println(welcome_text);
|
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();
|
println();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,7 +79,7 @@ shell.parse = function(input) {
|
|||||||
tokens.push(stringBuffer); stringBuffer = "";
|
tokens.push(stringBuffer); stringBuffer = "";
|
||||||
mode = "LIMBO";
|
mode = "LIMBO";
|
||||||
}
|
}
|
||||||
else if (c == '\\') {
|
else if (c == '^') {
|
||||||
mode = "ESCAPE";
|
mode = "ESCAPE";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -86,7 +99,30 @@ shell.parse = function(input) {
|
|||||||
|
|
||||||
return tokens;
|
return tokens;
|
||||||
}
|
}
|
||||||
if (exec_args !== undefined) return shell;
|
|
||||||
|
shell.coreutils = {
|
||||||
|
cd: function(args) {
|
||||||
|
if (args[1] === undefined) {
|
||||||
|
println(shell_pwd.join("\\"));
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
shell_pwd = args[1].split("\\");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Object.freeze(shell.coreutils);
|
||||||
|
shell.execute = function(line) {
|
||||||
|
if (line.size == 0) return;
|
||||||
|
let tokens = shell.parse(line);
|
||||||
|
let cmd = tokens[0].toLowerCase();
|
||||||
|
if (shell.coreutils[cmd] !== undefined) {
|
||||||
|
shell.coreutils[cmd](tokens);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
printerrln('Bad command or filename: "'+cmd+'"');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if (exec_args !== undefined) return Object.freeze(shell);
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@@ -98,7 +134,7 @@ 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
|
||||||
while (true) {
|
while (true) {
|
||||||
print(get_prompt_text());
|
print_prompt_text();
|
||||||
|
|
||||||
let cmdbuf = "";
|
let cmdbuf = "";
|
||||||
|
|
||||||
@@ -120,8 +156,7 @@ while (true) {
|
|||||||
else if (key === 10 || key === 13) {
|
else if (key === 10 || key === 13) {
|
||||||
println();
|
println();
|
||||||
try {
|
try {
|
||||||
let tokens = shell.parse(cmdbuf);
|
shell.execute(cmdbuf);
|
||||||
tokens.forEach(function(it) { println(it+"_"); });
|
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
printerrln(e);
|
printerrln(e);
|
||||||
|
|||||||
@@ -350,15 +350,15 @@ class GraphicsAdapter(val vm: VM, val lcdMode: Boolean = false, lcdInvert: Boole
|
|||||||
Color table for default palette
|
Color table for default palette
|
||||||
|
|
||||||
Black 240
|
Black 240
|
||||||
Red 160
|
Red 211
|
||||||
Green 30
|
Green 61
|
||||||
Yellow 230
|
Yellow 230
|
||||||
Blue 19
|
Blue 49
|
||||||
Magenta 199
|
Magenta 219
|
||||||
Cyan 74
|
Cyan 114
|
||||||
White 254
|
White 254
|
||||||
*/
|
*/
|
||||||
private val sgrDefault8ColPal = intArrayOf(240,160,30,230,19,199,74,254)
|
private val sgrDefault8ColPal = intArrayOf(240,211,61,230,49,219,114,254)
|
||||||
|
|
||||||
override fun sgrOneArg(arg: Int) {
|
override fun sgrOneArg(arg: Int) {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user