convert Terminal to Process

This commit is contained in:
Djeeberjr 2023-05-22 22:25:37 +02:00
parent 8dca828cf3
commit ec89107262

View File

@ -1,52 +1,56 @@
package bin;
import kernel.ps.ProcessHandle;
import kernel.ps.Process;
import kernel.ps.ProcessManager;
import kernel.ps.ProcessHandle;
import lib.ui.UIApp;
import lib.Color;
import kernel.ui.WindowContext;
import kernel.ui.WindowManager;
using tink.CoreApi;
class Terminal extends UIApp {
class Terminal implements Process {
private var context:WindowContext;
private var input:String = "";
private var backlog:Array<String> = [];
private var exitTrigger: Bool -> Void;
private var handle:ProcessHandle;
private var requestRender: () -> Void;
public function new() {}
public function invoke(context: WindowContext): Future<Bool> {
this.context = context;
public function run(handle: ProcessHandle): Void {
this.handle = handle;
var statelessContext = handle.createStatelessWindowContext();
this.context = statelessContext.ctx;
this.requestRender = statelessContext.requestRender;
statelessContext.setRenderFunc(this.render);
this.context.onChar.handle(char -> {
this.input += char;
this.redrawInput();
this.requestRender();
});
this.context.onKey.handle(e -> {
if (e.keyCode == 259) {
if (e.keyCode == 259) { // Backspace
this.input = this.input.substr(0, this.input.length - 1);
this.redrawInput();
} else if (e.keyCode == 257) {
this.requestRender();
} else if (e.keyCode == 257) { // Enter
this.backlog.push("> " + this.input);
var command = this.input;
this.input = "";
this.redrawBacklog();
this.redrawInput();
this.requestRender();
this.invokeCommand(command);
}
});
WindowManager.instance.focusContextToOutput(context, "main");
this.redrawInput();
this.requestRender();
}
return new Future<Bool>(cb -> {
this.exitTrigger = cb;
return null;
});
private function render() {
redrawBacklog();
redrawInput();
}
private function redrawBacklog() {
@ -117,14 +121,14 @@ class Terminal extends UIApp {
hadInput = true;
}
this.backlog[this.backlog.length - 1] += s;
this.redrawBacklog();
this.requestRender();
},
onExit: (success:Bool) -> {
if (this.backlog[this.backlog.length - 1] == "") {
this.backlog.pop();
}
this.redrawInput();
this.requestRender();
}
});