migrated the apps to processes
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
package bin;
|
||||
|
||||
import kernel.ps.Process;
|
||||
import kernel.ps.ProcessManager;
|
||||
import kernel.ps.ProcessHandle;
|
||||
import lib.ui.UIApp;
|
||||
import lib.cli.TermHandle;
|
||||
import lib.cli.CLIApp;
|
||||
import lib.Color;
|
||||
import kernel.ui.WindowContext;
|
||||
import kernel.ui.WindowManager;
|
||||
@@ -99,7 +100,17 @@ class Terminal extends UIApp {
|
||||
|
||||
var commandArgs:Array<String> = args.slice(1);
|
||||
var hadInput = false;
|
||||
var handle = new TermHandle(commandArgs, {
|
||||
|
||||
var ps = getProgByName(commandName);
|
||||
if (ps == null) {
|
||||
this.backlog.push("Unknown command: " + commandName);
|
||||
this.redrawBacklog();
|
||||
this.redrawInput();
|
||||
return;
|
||||
}
|
||||
|
||||
ProcessManager.run(ps,{
|
||||
args: commandArgs,
|
||||
onWrite: (s:String) -> {
|
||||
if (!hadInput) {
|
||||
this.backlog.push("");
|
||||
@@ -108,30 +119,16 @@ class Terminal extends UIApp {
|
||||
this.backlog[this.backlog.length - 1] += s;
|
||||
this.redrawBacklog();
|
||||
},
|
||||
onNewLine: () -> {
|
||||
this.backlog.push("");
|
||||
this.redrawBacklog();
|
||||
onExit: (success:Bool) -> {
|
||||
if (this.backlog[this.backlog.length - 1] == "") {
|
||||
this.backlog.pop();
|
||||
}
|
||||
|
||||
this.redrawInput();
|
||||
}
|
||||
});
|
||||
|
||||
var prog:CLIApp = getProgByName(commandName);
|
||||
|
||||
if (prog == null) {
|
||||
this.backlog.push("Command not found: " + commandName);
|
||||
this.redrawBacklog();
|
||||
return;
|
||||
}
|
||||
|
||||
this.context.setCursorBlink(false);
|
||||
|
||||
prog.invoke(handle).handle((exitCode) -> {
|
||||
// Cleanup extra newline
|
||||
if (this.backlog[this.backlog.length - 1] == "") {
|
||||
this.backlog.pop();
|
||||
}
|
||||
|
||||
this.redrawInput();
|
||||
});
|
||||
}
|
||||
|
||||
private function parseArgs(command:String):Array<String> {
|
||||
@@ -144,7 +141,7 @@ class Terminal extends UIApp {
|
||||
this.redrawBacklog();
|
||||
}
|
||||
|
||||
private function getProgByName(name:String):CLIApp {
|
||||
private function getProgByName(name:String):Process {
|
||||
switch (name) {
|
||||
case "hello":
|
||||
return new HelloWorld();
|
||||
|
||||
Reference in New Issue
Block a user