terminal kill runnig apps

This commit is contained in:
Djeeberjr 2023-06-07 20:10:51 +02:00
parent 644ebe1c05
commit 86793bfdc1

View File

@ -1,5 +1,6 @@
package bin;
import kernel.log.Log;
import kernel.binstore.BinStore;
import kernel.ps.ProcessHandle;
import kernel.ps.Process;
@ -15,6 +16,7 @@ class Terminal implements Process {
private var backlog:Array<String> = [];
private var handle:ProcessHandle;
private var requestRender: () -> Void;
private var runningPID:PID = -1;
public function new() {}
@ -28,27 +30,41 @@ class Terminal implements Process {
statelessContext.setRenderFunc(this.render);
this.context.onChar.handle(char -> {
handle.addCallbackLink(this.context.onChar.handle(char -> {
if (this.runningPID > 0) return;
this.input += char;
this.requestRender();
});
}));
this.context.onKey.handle(e -> {
if (e.keyCode == 259) { // Backspace
this.input = this.input.substr(0, this.input.length - 1);
this.requestRender();
} else if (e.keyCode == 257) { // Enter
this.backlog.push("> " + this.input);
var command = this.input;
this.input = "";
this.requestRender();
this.invokeCommand(command);
handle.addCallbackLink(this.context.onKey.handle(e -> {
switch (e.keyCode) {
case 259: // Backspace
if (this.runningPID > 0) return;
this.input = this.input.substr(0, this.input.length - 1);
this.requestRender();
case 257: // Enter
if (this.runningPID > 0) return;
this.backlog.push("> " + this.input);
var command = this.input;
this.input = "";
this.requestRender();
this.invokeCommand(command);
case 269: // END
this.stopCurrentPS();
}
});
}));
this.requestRender();
}
private function stopCurrentPS() {
if (this.runningPID < 0) {
return;
}
ProcessManager.kill(this.runningPID);
}
private function render() {
redrawBacklog();
redrawInput();
@ -114,7 +130,7 @@ class Terminal implements Process {
return;
}
ProcessManager.run(ps,{
this.runningPID = ProcessManager.run(ps,{
args: commandArgs,
onWrite: (s:String) -> {
if (s == "") {
@ -138,6 +154,7 @@ class Terminal implements Process {
this.requestRender();
},
onExit: (success:Bool) -> {
this.runningPID = -1;
if (this.backlog[this.backlog.length - 1] == "") {
this.backlog.pop();
}