terminal kill runnig apps
This commit is contained in:
parent
644ebe1c05
commit
86793bfdc1
@ -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) {
|
||||||
|
case 259: // Backspace
|
||||||
|
if (this.runningPID > 0) return;
|
||||||
this.input = this.input.substr(0, this.input.length - 1);
|
this.input = this.input.substr(0, this.input.length - 1);
|
||||||
this.requestRender();
|
this.requestRender();
|
||||||
} else if (e.keyCode == 257) { // Enter
|
case 257: // Enter
|
||||||
|
if (this.runningPID > 0) return;
|
||||||
this.backlog.push("> " + this.input);
|
this.backlog.push("> " + this.input);
|
||||||
var command = this.input;
|
var command = this.input;
|
||||||
this.input = "";
|
this.input = "";
|
||||||
this.requestRender();
|
this.requestRender();
|
||||||
this.invokeCommand(command);
|
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();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user