added UIApp and renamed CLIBase

This commit is contained in:
Djeeberjr 2023-01-28 03:55:32 +01:00
parent b54a25eec6
commit cb1f892e6d
7 changed files with 41 additions and 22 deletions

View File

@ -2,18 +2,16 @@ package bin;
import kernel.peripherals.Peripherals.Peripheral; import kernel.peripherals.Peripherals.Peripheral;
import lib.cli.TermHandle; import lib.cli.TermHandle;
import lib.cli.CLIBase; import lib.cli.CLIApp;
using tink.CoreApi; using tink.CoreApi;
using Lambda; using Lambda;
class Disk extends CLIBase { class Disk extends CLIApp {
private var handle:TermHandle; private var handle:TermHandle;
public function new() { public function new() {}
super();
}
public function invoke(handle:TermHandle):Future<Bool> { public function invoke(handle:TermHandle):Future<Bool> {
this.handle = handle; this.handle = handle;

View File

@ -1,11 +1,14 @@
package bin; package bin;
import lib.cli.TermHandle; import lib.cli.TermHandle;
import lib.cli.CLIBase; import lib.cli.CLIApp;
using tink.CoreApi; using tink.CoreApi;
class HelloWorld extends CLIBase { class HelloWorld extends CLIApp {
public function new() {}
public function invoke(handle: TermHandle):Future<Bool> { public function invoke(handle: TermHandle):Future<Bool> {
var world:String = "world"; var world:String = "world";
if (handle.args.length > 0) { if (handle.args.length > 0) {

View File

@ -4,12 +4,15 @@ import kernel.peripherals.Peripherals.Peripheral;
import kernel.net.Routing; import kernel.net.Routing;
import haxe.ds.ReadOnlyArray; import haxe.ds.ReadOnlyArray;
import lib.cli.TermHandle; import lib.cli.TermHandle;
import lib.cli.CLIBase; import lib.cli.CLIApp;
using tink.CoreApi; using tink.CoreApi;
class Net extends CLIBase { class Net extends CLIApp {
private var handle:TermHandle; private var handle:TermHandle;
public function new() {}
public function invoke(handle:TermHandle):Future<Bool> { public function invoke(handle:TermHandle):Future<Bool> {
this.handle = handle; this.handle = handle;

View File

@ -3,14 +3,12 @@ package bin;
import kernel.peripherals.Peripherals.Peripheral; import kernel.peripherals.Peripherals.Peripheral;
import kernel.peripherals.Side; import kernel.peripherals.Side;
import lib.cli.TermHandle; import lib.cli.TermHandle;
import lib.cli.CLIBase; import lib.cli.CLIApp;
using tink.CoreApi; using tink.CoreApi;
class Redstone extends CLIBase { class Redstone extends CLIApp {
public function new() { public function new() {}
super();
}
public function invoke(handle:TermHandle):Future<Bool> { public function invoke(handle:TermHandle):Future<Bool> {
var subcommand = handle.args[0]; var subcommand = handle.args[0];

View File

@ -1,20 +1,24 @@
package bin; package bin;
import lib.ui.UIApp;
import lib.cli.TermHandle; import lib.cli.TermHandle;
import lib.cli.CLIBase; import lib.cli.CLIApp;
import lib.Color; import lib.Color;
import kernel.ui.WindowContext; import kernel.ui.WindowContext;
import kernel.ui.WindowManager; import kernel.ui.WindowManager;
class Terminal { using tink.CoreApi;
class Terminal extends UIApp {
private var context:WindowContext; private var context:WindowContext;
private var input:String = ""; private var input:String = "";
private var backlog:Array<String> = []; private var backlog:Array<String> = [];
private var exitTrigger: Bool -> Void;
public function new() {} public function new() {}
public function execute() { public function invoke(context: WindowContext): Future<Bool> {
this.context = WindowManager.instance.createNewContext(); this.context = context;
this.context.onChar.handle(char -> { this.context.onChar.handle(char -> {
this.input += char; this.input += char;
@ -37,6 +41,11 @@ class Terminal {
WindowManager.instance.focusContextToOutput(context, "main"); WindowManager.instance.focusContextToOutput(context, "main");
this.redrawInput(); this.redrawInput();
return new Future<Bool>(cb -> {
this.exitTrigger = cb;
return null;
});
} }
private function redrawBacklog() { private function redrawBacklog() {
@ -105,7 +114,7 @@ class Terminal {
} }
}); });
var prog:CLIBase = getProgByName(commandName); var prog:CLIApp = getProgByName(commandName);
if (prog == null) { if (prog == null) {
this.backlog.push("Command not found: " + commandName); this.backlog.push("Command not found: " + commandName);
@ -135,7 +144,7 @@ class Terminal {
this.redrawBacklog(); this.redrawBacklog();
} }
private function getProgByName(name:String):CLIBase { private function getProgByName(name:String):CLIApp {
switch (name) { switch (name) {
case "hello": case "hello":
return new HelloWorld(); return new HelloWorld();

View File

@ -2,7 +2,6 @@ package lib.cli;
using tink.CoreApi; using tink.CoreApi;
abstract class CLIBase { abstract class CLIApp {
public function new() {};
public abstract function invoke(handle: TermHandle): Future<Bool>; public abstract function invoke(handle: TermHandle): Future<Bool>;
} }

9
src/lib/ui/UIApp.hx Normal file
View 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>;
}