diff --git a/src/bin/Disk.hx b/src/bin/Disk.hx index 314654d..f40d0d4 100644 --- a/src/bin/Disk.hx +++ b/src/bin/Disk.hx @@ -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 { this.handle = handle; diff --git a/src/bin/HelloWorld.hx b/src/bin/HelloWorld.hx index 716cb41..2be0165 100644 --- a/src/bin/HelloWorld.hx +++ b/src/bin/HelloWorld.hx @@ -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 { var world:String = "world"; if (handle.args.length > 0) { diff --git a/src/bin/Net.hx b/src/bin/Net.hx index 4a16287..a5a2ec4 100644 --- a/src/bin/Net.hx +++ b/src/bin/Net.hx @@ -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 { this.handle = handle; diff --git a/src/bin/Redstone.hx b/src/bin/Redstone.hx index c5c32da..e099eb5 100644 --- a/src/bin/Redstone.hx +++ b/src/bin/Redstone.hx @@ -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 { var subcommand = handle.args[0]; diff --git a/src/bin/Terminal.hx b/src/bin/Terminal.hx index f5881e6..9e49195 100644 --- a/src/bin/Terminal.hx +++ b/src/bin/Terminal.hx @@ -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 = []; + private var exitTrigger: Bool -> Void; public function new() {} - public function execute() { - this.context = WindowManager.instance.createNewContext(); + public function invoke(context: WindowContext): Future { + 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(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(); diff --git a/src/lib/cli/CLIBase.hx b/src/lib/cli/CLIApp.hx similarity index 67% rename from src/lib/cli/CLIBase.hx rename to src/lib/cli/CLIApp.hx index 48cbbe8..7cb2950 100644 --- a/src/lib/cli/CLIBase.hx +++ b/src/lib/cli/CLIApp.hx @@ -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; } diff --git a/src/lib/ui/UIApp.hx b/src/lib/ui/UIApp.hx new file mode 100644 index 0000000..4a3224f --- /dev/null +++ b/src/lib/ui/UIApp.hx @@ -0,0 +1,9 @@ +package lib.ui; + +import kernel.ui.WindowContext; + +using tink.CoreApi; + +abstract class UIApp { + public abstract function invoke(context: WindowContext): Future; +}