adding VarText and removing text minimum length
This commit is contained in:
@@ -9,7 +9,8 @@ import uuid.Uuid;
|
|||||||
enum CommandArgType {
|
enum CommandArgType {
|
||||||
SelectedEntry;
|
SelectedEntry;
|
||||||
SelectedEntries(min:Null<Int>, max:Null<Int>);
|
SelectedEntries(min:Null<Int>, max:Null<Int>);
|
||||||
Text(minLength:Null<Int>, maxLength:Null<Float>); // max length is a float so Math.POSITIVE_INFINITY can be used
|
Text(maxLength:Null<Float>); // max length is a float so Math.POSITIVE_INFINITY can be used
|
||||||
|
VarText(maxLength:Null<Float>);
|
||||||
Number(min:Null<Float>, max:Null<Float>, inStepsOf:Null<Float>);
|
Number(min:Null<Float>, max:Null<Float>, inStepsOf:Null<Float>);
|
||||||
OneEntry; // This constructor must be disambiguated from the typedef "Entry"
|
OneEntry; // This constructor must be disambiguated from the typedef "Entry"
|
||||||
Entries(min:Null<Int>, max:Null<Int>);
|
Entries(min:Null<Int>, max:Null<Int>);
|
||||||
|
@@ -13,17 +13,35 @@
|
|||||||
(if !(<= min selectedEntries.length max)
|
(if !(<= min selectedEntries.length max)
|
||||||
(ui.reportError "The requested command expects between $min and $max entries to be selected. You have selected: $selectedEntries.length")
|
(ui.reportError "The requested command expects between $min and $max entries to be selected. You have selected: $selectedEntries.length")
|
||||||
(continuation selectedEntries)))
|
(continuation selectedEntries)))
|
||||||
((Text minLength maxLength)
|
((Text maxLength)
|
||||||
(unless minLength (set minLength 0))
|
|
||||||
(unless maxLength (set maxLength Math.POSITIVE_INFINITY))
|
(unless maxLength (set maxLength Math.POSITIVE_INFINITY))
|
||||||
(ui.enterText
|
(ui.enterText
|
||||||
"${arg.name} (${minLength}-${maxLength} characters):"
|
"${arg.name} (up to ${maxLength} characters):"
|
||||||
(lambda :Void [text]
|
(lambda :Void [text]
|
||||||
(if !(<= minLength text.length maxLength)
|
(if !(<= text.length maxLength)
|
||||||
(ui.reportError "The requested command expected a string between $minLength and $maxLength characters long. You entered: $text.length characters")
|
(ui.reportError "The requested command expected a string up to $maxLength characters long. You entered: $text.length characters")
|
||||||
(continuation text)))
|
(continuation text)))
|
||||||
minLength
|
|
||||||
maxLength))
|
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)
|
((Number min max inStepsOf)
|
||||||
(unless min (set min Math.NEGATIVE_INFINITY))
|
(unless min (set min Math.NEGATIVE_INFINITY))
|
||||||
(unless max (set max Math.POSITIVE_INFINITY))
|
(unless max (set max Math.POSITIVE_INFINITY))
|
||||||
@@ -100,7 +118,8 @@
|
|||||||
(exprCase type
|
(exprCase type
|
||||||
((exprOr SelectedEntry OneEntry) `:nat.Entry ,name)
|
((exprOr SelectedEntry OneEntry) `:nat.Entry ,name)
|
||||||
((exprOr (SelectedEntries _ _) (Entries _ _)) `:Array<nat.Entry> ,name)
|
((exprOr (SelectedEntries _ _) (Entries _ _)) `:Array<nat.Entry> ,name)
|
||||||
((Text _ _) `:String ,name)
|
((Text _) `:String ,name)
|
||||||
|
((VarText _) `:Array<String> ,name)
|
||||||
((Number _ _ _) `:Float ,name)))
|
((Number _ _ _) `:Float ,name)))
|
||||||
commandArgs
|
commandArgs
|
||||||
(for [name type] argPairs
|
(for [name type] argPairs
|
||||||
|
@@ -6,7 +6,7 @@ interface ArchiveUI {
|
|||||||
/**
|
/**
|
||||||
* Prompt the user to enter text
|
* 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
|
* Prompt the user to enter a number
|
||||||
|
@@ -16,11 +16,11 @@
|
|||||||
|
|
||||||
(defnew [])
|
(defnew [])
|
||||||
|
|
||||||
(defmethod :Void enterText [prompt resolve minLength maxLength]
|
(defmethod :Void enterText [prompt resolve maxLength]
|
||||||
(Sys.print "$prompt ")
|
(Sys.print "$prompt ")
|
||||||
(loop
|
(loop
|
||||||
(let [entered (.toString (.readLine (Sys.stdin)))]
|
(let [entered (.toString (.readLine (Sys.stdin)))]
|
||||||
(if !(<= minLength entered.length maxLength)
|
(if !(<= entered.length maxLength)
|
||||||
(Sys.print "Try again? ")
|
(Sys.print "Try again? ")
|
||||||
{(resolve entered)
|
{(resolve entered)
|
||||||
(break)}))))
|
(break)}))))
|
||||||
@@ -57,7 +57,7 @@
|
|||||||
([] (chooseEntry "name $name doesn't match any entries. Try again?" archive resolve))
|
([] (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
|
// TODO disambiguate entries with the same names by listing stringified versions of them and using enterNumber
|
||||||
(multipleEntries (throw "ambiguous between multiple entries")))))}
|
(multipleEntries (throw "ambiguous between multiple entries")))))}
|
||||||
0 Math.POSITIVE_INFINITY))
|
Math.POSITIVE_INFINITY))
|
||||||
|
|
||||||
(defmethod :Void chooseEntries [prompt archive resolve min max]
|
(defmethod :Void chooseEntries [prompt archive resolve min max]
|
||||||
(_chooseEntries prompt archive resolve min max []))
|
(_chooseEntries prompt archive resolve min max []))
|
||||||
|
Reference in New Issue
Block a user