Add functions to NAT DummyUI and CLI
This commit is contained in:
@@ -4,6 +4,9 @@ import kiss.Prelude;
|
||||
import kiss.List;
|
||||
import sys.FileSystem;
|
||||
import nat.ArchiveController;
|
||||
import nat.systems.PlaygroundSystem;
|
||||
import nat.components.*;
|
||||
import haxe.ds.Option;
|
||||
|
||||
using StringTools;
|
||||
|
||||
|
@@ -1,16 +1,17 @@
|
||||
// External programs can load Lib.kiss with (loadFrom "nat-archive-tool" "src/nat/Lib.kiss")
|
||||
(load "Lib.kiss")
|
||||
|
||||
(let [[archiveDir] (Sys.args)
|
||||
controller
|
||||
(new ArchiveController
|
||||
(new Archive archiveDir)
|
||||
(new CLI))]
|
||||
(loop
|
||||
(Sys.print ">> ")
|
||||
(let [command
|
||||
(.trim (.toString (.readLine (Sys.stdin))))]
|
||||
(controller.tryRunCommand command))))
|
||||
(let [[archiveDir] (Sys.args)]
|
||||
(unless (= "_TEST_" archiveDir)
|
||||
(let [controller
|
||||
(new ArchiveController
|
||||
(new Archive archiveDir)
|
||||
(new CLI))]
|
||||
(loop
|
||||
(Sys.print ">> ")
|
||||
(let [command
|
||||
(.trim (.toString (.readLine (Sys.stdin))))]
|
||||
(controller.tryRunCommand command))))))
|
||||
|
||||
(prop &mut :ArchiveController controller)
|
||||
(prop :kiss_tools.KeyShortcutHandler<Entry> shortcutHandler null)
|
||||
@@ -26,7 +27,7 @@
|
||||
{(resolve entered)
|
||||
(break)}))))
|
||||
|
||||
(method :Void enterNumber [prompt :Float->Void resolve min max &opt inStepsOf]
|
||||
(method :Void enterNumber [prompt :Float->Void resolve :Float min :Float max &opt :Float inStepsOf]
|
||||
(Sys.print "$prompt ")
|
||||
(loop
|
||||
(let [entered (Std.parseFloat (.toString (.readLine (Sys.stdin))))]
|
||||
@@ -95,3 +96,24 @@
|
||||
(method :Void onSelectionChanged [:Array<Entry> selectedEntries :Array<Entry> _]
|
||||
(print "Selected:")
|
||||
(controller.PrintSelectedEntries selectedEntries))
|
||||
|
||||
(method :Void chooseBetweenStrings [prompt :Array<String> choices :String->Void resolve]
|
||||
(print prompt)
|
||||
(doFor [idx choice] (enumerate choices)
|
||||
(print "$(+ idx 1). $choice"))
|
||||
(enterNumber "Choice" ->num (resolve (nth choices (- (Std.int num) 1))) 1 choices.length 1))
|
||||
|
||||
(defAlias &ident neg Math.NEGATIVE_INFINITY)
|
||||
(defAlias &ident pos Math.POSITIVE_INFINITY)
|
||||
(method :Void choosePosition [prompt :Position->Void resolve]
|
||||
(enterNumber "x" ->x (enterNumber "y" ->y (enterNumber "z" ->z (resolve (objectWith x y z)) neg pos) neg pos) neg pos))
|
||||
|
||||
(method :Option<Position> cursorPosition [] None)
|
||||
|
||||
(method :Void showPrefixMap [:Map<String,String> map]
|
||||
(doFor =>key thing map
|
||||
(print "$key - $thing")))
|
||||
|
||||
(method :Void hidePrefixMap [])
|
||||
|
||||
(method :PlaygroundSystem playgroundSystem [] null)
|
@@ -32,6 +32,10 @@ class DummyUI implements ArchiveUI {
|
||||
resolve([]);
|
||||
}
|
||||
|
||||
public function chooseBetweenStrings(prompt:String, choices:Array<String>, resolve:String->Void) {
|
||||
resolve(choices[0]);
|
||||
}
|
||||
|
||||
public function handleChanges(archive:Archive, changeSet:ChangeSet) {}
|
||||
|
||||
public function displayMessage(message:String) {}
|
||||
@@ -45,6 +49,9 @@ class DummyUI implements ArchiveUI {
|
||||
public function cursorPosition():Option<Position> {
|
||||
return None;
|
||||
};
|
||||
public function choosePosition(prompt:String, resolve:Position->Void) {
|
||||
resolve({x: 0, y: 0, z: 0});
|
||||
}
|
||||
public function playgroundSystem():Null<PlaygroundSystem> {
|
||||
return null;
|
||||
}
|
||||
|
Reference in New Issue
Block a user