diff --git a/src/nat/ArchiveController.hx b/src/nat/ArchiveController.hx index 322f108..2a2258e 100644 --- a/src/nat/ArchiveController.hx +++ b/src/nat/ArchiveController.hx @@ -9,7 +9,8 @@ import uuid.Uuid; enum CommandArgType { SelectedEntry; SelectedEntries(min:Null, max:Null); - Text(minLength:Null, maxLength:Null); // max length is a float so Math.POSITIVE_INFINITY can be used + Text(maxLength:Null); // max length is a float so Math.POSITIVE_INFINITY can be used + VarText(maxLength:Null); Number(min:Null, max:Null, inStepsOf:Null); OneEntry; // This constructor must be disambiguated from the typedef "Entry" Entries(min:Null, max:Null); diff --git a/src/nat/ArchiveController.kiss b/src/nat/ArchiveController.kiss index 2691f8a..3a79fc6 100644 --- a/src/nat/ArchiveController.kiss +++ b/src/nat/ArchiveController.kiss @@ -13,17 +13,35 @@ (if !(<= min selectedEntries.length max) (ui.reportError "The requested command expects between $min and $max entries to be selected. You have selected: $selectedEntries.length") (continuation selectedEntries))) - ((Text minLength maxLength) - (unless minLength (set minLength 0)) + ((Text maxLength) (unless maxLength (set maxLength Math.POSITIVE_INFINITY)) (ui.enterText - "${arg.name} (${minLength}-${maxLength} characters):" + "${arg.name} (up to ${maxLength} characters):" (lambda :Void [text] - (if !(<= minLength text.length maxLength) - (ui.reportError "The requested command expected a string between $minLength and $maxLength characters long. You entered: $text.length characters") + (if !(<= text.length maxLength) + (ui.reportError "The requested command expected a string up to $maxLength characters long. You entered: $text.length characters") (continuation text))) - minLength maxLength)) + ((VarText maxLength) + (unless maxLength (set maxLength Math.POSITIVE_INFINITY)) + (let [collectedText + [] + &mut :Void->Void enterTextAgain + null + _enterTextAgain + ->:Void + (ui.enterText + "${arg.name} (up to ${maxLength} characters):" + (lambda :Void [text] + (if !text + (continuation collectedText) + (if !(<= text.length maxLength) + (ui.reportError "The requested command expected a list of strings up to $maxLength characters long. You entered: $text.length characters") + {(collectedText.push text) + (enterTextAgain)}))) + maxLength)] + (set enterTextAgain _enterTextAgain) + (enterTextAgain))) ((Number min max inStepsOf) (unless min (set min Math.NEGATIVE_INFINITY)) (unless max (set max Math.POSITIVE_INFINITY)) @@ -100,7 +118,8 @@ (exprCase type ((exprOr SelectedEntry OneEntry) `:nat.Entry ,name) ((exprOr (SelectedEntries _ _) (Entries _ _)) `:Array ,name) - ((Text _ _) `:String ,name) + ((Text _) `:String ,name) + ((VarText _) `:Array ,name) ((Number _ _ _) `:Float ,name))) commandArgs (for [name type] argPairs diff --git a/src/nat/ArchiveUI.hx b/src/nat/ArchiveUI.hx index 98cbd5d..3b15248 100644 --- a/src/nat/ArchiveUI.hx +++ b/src/nat/ArchiveUI.hx @@ -6,7 +6,7 @@ interface ArchiveUI { /** * Prompt the user to enter text */ - function enterText(prompt:String, resolve:(String) -> Void, minLength:Int, maxLength:Float):Void; + function enterText(prompt:String, resolve:(String) -> Void, maxLength:Float):Void; /** * Prompt the user to enter a number diff --git a/src/nat/CLI.kiss b/src/nat/CLI.kiss index e128691..28bc623 100644 --- a/src/nat/CLI.kiss +++ b/src/nat/CLI.kiss @@ -16,11 +16,11 @@ (defnew []) -(defmethod :Void enterText [prompt resolve minLength maxLength] +(defmethod :Void enterText [prompt resolve maxLength] (Sys.print "$prompt ") (loop (let [entered (.toString (.readLine (Sys.stdin)))] - (if !(<= minLength entered.length maxLength) + (if !(<= entered.length maxLength) (Sys.print "Try again? ") {(resolve entered) (break)})))) @@ -57,7 +57,7 @@ ([] (chooseEntry "name $name doesn't match any entries. Try again?" archive resolve)) // TODO disambiguate entries with the same names by listing stringified versions of them and using enterNumber (multipleEntries (throw "ambiguous between multiple entries")))))} - 0 Math.POSITIVE_INFINITY)) + Math.POSITIVE_INFINITY)) (defmethod :Void chooseEntries [prompt archive resolve min max] (_chooseEntries prompt archive resolve min max []))