improved terminal stuff
This commit is contained in:
parent
c6e5a836ea
commit
3cb1811dcb
@ -1,16 +1,17 @@
|
|||||||
package bin;
|
package bin;
|
||||||
|
|
||||||
|
using tink.CoreApi;
|
||||||
import lib.TermHandle;
|
import lib.TermHandle;
|
||||||
import lib.CLIBase;
|
import lib.CLIBase;
|
||||||
|
|
||||||
class HelloWorld extends CLIBase {
|
class HelloWorld extends CLIBase {
|
||||||
public function invoke(handle: TermHandle):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) {
|
||||||
world = handle.args[0];
|
world = handle.args[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
handle.write('Hello, $world!');
|
handle.write('Hello, $world!');
|
||||||
return true;
|
return Future.sync(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package bin;
|
package bin;
|
||||||
|
|
||||||
|
using tink.CoreApi;
|
||||||
|
|
||||||
import kernel.peripherals.Peripherals.Peripheral;
|
import kernel.peripherals.Peripherals.Peripheral;
|
||||||
import kernel.net.Routing;
|
import kernel.net.Routing;
|
||||||
import haxe.ds.ReadOnlyArray;
|
import haxe.ds.ReadOnlyArray;
|
||||||
@ -8,7 +10,7 @@ import lib.CLIBase;
|
|||||||
|
|
||||||
class Net extends CLIBase {
|
class Net extends CLIBase {
|
||||||
private var handle:TermHandle;
|
private var handle:TermHandle;
|
||||||
public function invoke(handle:TermHandle):Bool {
|
public function invoke(handle:TermHandle):Future<Bool> {
|
||||||
this.handle = handle;
|
this.handle = handle;
|
||||||
|
|
||||||
var subcommand = handle.args[0];
|
var subcommand = handle.args[0];
|
||||||
@ -16,27 +18,28 @@ class Net extends CLIBase {
|
|||||||
|
|
||||||
switch (subcommand) {
|
switch (subcommand) {
|
||||||
case "route":
|
case "route":
|
||||||
return route(subcommand_args);
|
return Future.sync(route(subcommand_args));
|
||||||
case "iface":
|
case "iface":
|
||||||
return iface(subcommand_args);
|
return Future.sync(iface(subcommand_args));
|
||||||
case "help":
|
case "help":
|
||||||
printHelp();
|
printHelp();
|
||||||
return true;
|
return Future.sync(true);
|
||||||
case "ping":
|
case "ping":
|
||||||
ping(subcommand_args);
|
return ping(subcommand_args);
|
||||||
|
case "proto":
|
||||||
|
return Future.sync(protos());
|
||||||
default:
|
default:
|
||||||
handle.writeLn("Unknown subcommand: " + subcommand);
|
handle.writeLn("Unknown subcommand: " + subcommand);
|
||||||
printHelp();
|
printHelp();
|
||||||
return false;
|
return Future.sync(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function printHelp() {
|
private function printHelp() {
|
||||||
handle.writeLn("net route");
|
handle.writeLn("net route");
|
||||||
handle.writeLn("net iface");
|
handle.writeLn("net iface");
|
||||||
handle.writeLn("net help");
|
handle.writeLn("net help");
|
||||||
|
handle.writeLn("net proto");
|
||||||
}
|
}
|
||||||
|
|
||||||
private function route(args:ReadOnlyArray<String>):Bool {
|
private function route(args:ReadOnlyArray<String>):Bool {
|
||||||
@ -59,18 +62,47 @@ class Net extends CLIBase {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function ping(args:ReadOnlyArray<String>) {
|
function ping(args:ReadOnlyArray<String>): Future<Bool> {
|
||||||
|
return new Future<Bool>(trigger -> {
|
||||||
if (args.length != 1) {
|
if (args.length != 1) {
|
||||||
handle.writeLn("Usage: net ping id");
|
handle.writeLn("Usage: net ping id");
|
||||||
|
trigger(false);
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var toID:Null<Int> = Std.parseInt(args[0]);
|
var toID:Null<Int> = Std.parseInt(args[0]);
|
||||||
|
|
||||||
if (toID == null) {
|
if (toID == null) {
|
||||||
handle.writeLn("Invalid ID");
|
handle.writeLn("Invalid ID");
|
||||||
|
trigger(false);
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// var result = kernel.net.Net.instance.ping(toID);
|
kernel.net.Net.instance.ping(toID).handle(result -> {
|
||||||
|
switch (result){
|
||||||
|
case Success(acc):
|
||||||
|
if (acc) {
|
||||||
|
handle.writeLn("Ping succeeded");
|
||||||
|
trigger(true);
|
||||||
|
} else {
|
||||||
|
handle.writeLn("Ping failed");
|
||||||
|
trigger(false);
|
||||||
|
}
|
||||||
|
case Failure(failure):
|
||||||
|
handle.writeLn("Ping failed: " + failure);
|
||||||
|
trigger(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function protos():Bool {
|
||||||
|
var protos = kernel.net.Net.instance.getActiveProtocols();
|
||||||
|
|
||||||
|
for (proto in protos) {
|
||||||
|
handle.writeLn(proto);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -115,14 +115,14 @@ class Terminal {
|
|||||||
|
|
||||||
this.context.setCursorBlink(false);
|
this.context.setCursorBlink(false);
|
||||||
|
|
||||||
prog.invoke(handle);
|
prog.invoke(handle).handle((exitCode) -> {
|
||||||
|
|
||||||
// Cleanup extra newline
|
// Cleanup extra newline
|
||||||
if (this.backlog[this.backlog.length - 1] == "") {
|
if (this.backlog[this.backlog.length - 1] == "") {
|
||||||
this.backlog.pop();
|
this.backlog.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.redrawInput();
|
this.redrawInput();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private function parseArgs(command:String):Array<String> {
|
private function parseArgs(command:String):Array<String> {
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package lib;
|
package lib;
|
||||||
|
|
||||||
|
using tink.CoreApi;
|
||||||
|
|
||||||
abstract class CLIBase {
|
abstract class CLIBase {
|
||||||
public function new() {};
|
public function new() {};
|
||||||
public abstract function invoke(handle: TermHandle): Bool;
|
public abstract function invoke(handle: TermHandle): Future<Bool>;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user