22 lines
571 B
Plaintext
22 lines
571 B
Plaintext
val .select = impure fn(.entries) {
|
|
if .entries is not list: throw "invalid args"
|
|
if len(.entries) == 0: return ""
|
|
|
|
# print the menu
|
|
writeln join "\n", map(fn(.e, .i) $"\.i:2;: \.e;", .entries, 1..len .entries)
|
|
|
|
val .idx = number read(
|
|
"Select entry #: ",
|
|
fn(.x) {
|
|
if not .x -> RE/^[0-9]+$/: return false
|
|
val .y = number .x
|
|
.y > 0 and .y <= len(.entries)
|
|
},
|
|
"invalid selection\n", -1,
|
|
)
|
|
|
|
.entries[.idx]
|
|
}
|
|
|
|
writeln .select(["fee fie", "eat pi", "huff and puff", "tick tock"])
|