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