Data update

This commit is contained in:
Ingy dot Net 2024-04-19 16:56:29 -07:00
parent 0df55f9f24
commit aec8ed51b6
1045 changed files with 18889 additions and 2777 deletions

View file

@ -6,6 +6,7 @@ string menuSelect(in string[] entries) {
pure nothrow {
try {
immutable n = input.to!int;
return typeof(return)((n >= 0 && n <= nEntries) ? n : -1);
} catch (Exception e) // Very generic
return typeof(return)(-1); // Not valid.
@ -19,8 +20,11 @@ string menuSelect(in string[] entries) {
foreach (immutable i, const entry; entries)
writefln(" %d) %s", i, entry);
"> ".write;
immutable input = readln.chomp;
immutable choice = validChoice(input, entries.length - 1);
immutable choice = validChoice(input, cast(int) (entries.length - 1));
if (choice.isNull)
"Wrong choice.".writeln;
else
@ -31,5 +35,6 @@ string menuSelect(in string[] entries) {
void main() {
immutable items = ["fee fie", "huff and puff",
"mirror mirror", "tick tock"];
writeln("You chose '", items.menuSelect, "'.");
}

View file

@ -1,15 +1,15 @@
val .select = f(.entries) {
if not isList(.entries): throw "invalid args"
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(f $"\.i:2;: \.e;", .entries, 1..len .entries)
writeln join "\n", map(fn(.e, .i) $"\.i:2;: \.e;", .entries, 1..len .entries)
val .idx = toNumber read(
val .idx = number read(
"Select entry #: ",
f(.x) {
if not matching(RE/^[0-9]+$/, .x): return false
val .y = toNumber .x
fn(.x) {
if not .x -> RE/^[0-9]+$/: return false
val .y = number .x
.y > 0 and .y <= len(.entries)
},
"invalid selection\n", -1,