added UIApp and renamed CLIBase
This commit is contained in:
parent
b54a25eec6
commit
cb1f892e6d
@ -2,18 +2,16 @@ package bin;
|
||||
|
||||
import kernel.peripherals.Peripherals.Peripheral;
|
||||
import lib.cli.TermHandle;
|
||||
import lib.cli.CLIBase;
|
||||
import lib.cli.CLIApp;
|
||||
|
||||
using tink.CoreApi;
|
||||
using Lambda;
|
||||
|
||||
class Disk extends CLIBase {
|
||||
class Disk extends CLIApp {
|
||||
|
||||
private var handle:TermHandle;
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
}
|
||||
public function new() {}
|
||||
|
||||
public function invoke(handle:TermHandle):Future<Bool> {
|
||||
this.handle = handle;
|
||||
|
@ -1,11 +1,14 @@
|
||||
package bin;
|
||||
|
||||
import lib.cli.TermHandle;
|
||||
import lib.cli.CLIBase;
|
||||
import lib.cli.CLIApp;
|
||||
|
||||
using tink.CoreApi;
|
||||
|
||||
class HelloWorld extends CLIBase {
|
||||
class HelloWorld extends CLIApp {
|
||||
|
||||
public function new() {}
|
||||
|
||||
public function invoke(handle: TermHandle):Future<Bool> {
|
||||
var world:String = "world";
|
||||
if (handle.args.length > 0) {
|
||||
|
@ -4,12 +4,15 @@ import kernel.peripherals.Peripherals.Peripheral;
|
||||
import kernel.net.Routing;
|
||||
import haxe.ds.ReadOnlyArray;
|
||||
import lib.cli.TermHandle;
|
||||
import lib.cli.CLIBase;
|
||||
import lib.cli.CLIApp;
|
||||
|
||||
using tink.CoreApi;
|
||||
|
||||
class Net extends CLIBase {
|
||||
class Net extends CLIApp {
|
||||
private var handle:TermHandle;
|
||||
|
||||
public function new() {}
|
||||
|
||||
public function invoke(handle:TermHandle):Future<Bool> {
|
||||
this.handle = handle;
|
||||
|
||||
|
@ -3,14 +3,12 @@ package bin;
|
||||
import kernel.peripherals.Peripherals.Peripheral;
|
||||
import kernel.peripherals.Side;
|
||||
import lib.cli.TermHandle;
|
||||
import lib.cli.CLIBase;
|
||||
import lib.cli.CLIApp;
|
||||
|
||||
using tink.CoreApi;
|
||||
|
||||
class Redstone extends CLIBase {
|
||||
public function new() {
|
||||
super();
|
||||
}
|
||||
class Redstone extends CLIApp {
|
||||
public function new() {}
|
||||
|
||||
public function invoke(handle:TermHandle):Future<Bool> {
|
||||
var subcommand = handle.args[0];
|
||||
|
@ -1,20 +1,24 @@
|
||||
package bin;
|
||||
|
||||
import lib.ui.UIApp;
|
||||
import lib.cli.TermHandle;
|
||||
import lib.cli.CLIBase;
|
||||
import lib.cli.CLIApp;
|
||||
import lib.Color;
|
||||
import kernel.ui.WindowContext;
|
||||
import kernel.ui.WindowManager;
|
||||
|
||||
class Terminal {
|
||||
using tink.CoreApi;
|
||||
|
||||
class Terminal extends UIApp {
|
||||
private var context:WindowContext;
|
||||
private var input:String = "";
|
||||
private var backlog:Array<String> = [];
|
||||
private var exitTrigger: Bool -> Void;
|
||||
|
||||
public function new() {}
|
||||
|
||||
public function execute() {
|
||||
this.context = WindowManager.instance.createNewContext();
|
||||
public function invoke(context: WindowContext): Future<Bool> {
|
||||
this.context = context;
|
||||
|
||||
this.context.onChar.handle(char -> {
|
||||
this.input += char;
|
||||
@ -37,6 +41,11 @@ class Terminal {
|
||||
|
||||
WindowManager.instance.focusContextToOutput(context, "main");
|
||||
this.redrawInput();
|
||||
|
||||
return new Future<Bool>(cb -> {
|
||||
this.exitTrigger = cb;
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
private function redrawBacklog() {
|
||||
@ -105,7 +114,7 @@ class Terminal {
|
||||
}
|
||||
});
|
||||
|
||||
var prog:CLIBase = getProgByName(commandName);
|
||||
var prog:CLIApp = getProgByName(commandName);
|
||||
|
||||
if (prog == null) {
|
||||
this.backlog.push("Command not found: " + commandName);
|
||||
@ -135,7 +144,7 @@ class Terminal {
|
||||
this.redrawBacklog();
|
||||
}
|
||||
|
||||
private function getProgByName(name:String):CLIBase {
|
||||
private function getProgByName(name:String):CLIApp {
|
||||
switch (name) {
|
||||
case "hello":
|
||||
return new HelloWorld();
|
||||
|
@ -2,7 +2,6 @@ package lib.cli;
|
||||
|
||||
using tink.CoreApi;
|
||||
|
||||
abstract class CLIBase {
|
||||
public function new() {};
|
||||
abstract class CLIApp {
|
||||
public abstract function invoke(handle: TermHandle): Future<Bool>;
|
||||
}
|
9
src/lib/ui/UIApp.hx
Normal file
9
src/lib/ui/UIApp.hx
Normal file
@ -0,0 +1,9 @@
|
||||
package lib.ui;
|
||||
|
||||
import kernel.ui.WindowContext;
|
||||
|
||||
using tink.CoreApi;
|
||||
|
||||
abstract class UIApp {
|
||||
public abstract function invoke(context: WindowContext): Future<Bool>;
|
||||
}
|
Loading…
Reference in New Issue
Block a user