diff options
author | Lizzy Fleckenstein <lizzy@vlhl.dev> | 2023-12-23 04:46:51 +0100 |
---|---|---|
committer | Lizzy Fleckenstein <lizzy@vlhl.dev> | 2023-12-23 04:46:51 +0100 |
commit | 839891fc580f8deaf8f5b6ef3dece42e96c1acec (patch) | |
tree | 76f467ace389150765dfb338e85f864d1c80e9d8 /stage3/shell.c | |
parent | 51d877fb0f77a1c6b81fa88d5a1adbffc63b1de7 (diff) | |
download | cuddles-839891fc580f8deaf8f5b6ef3dece42e96c1acec.tar.xz |
splash texts
Diffstat (limited to 'stage3/shell.c')
-rw-r--r-- | stage3/shell.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/stage3/shell.c b/stage3/shell.c index 079580e..d64e5be 100644 --- a/stage3/shell.c +++ b/stage3/shell.c @@ -280,6 +280,34 @@ static void cmd_clocktest(str arg) } } +static void cmd_choose(str arg) +{ + str f = fs_read(arg); + + if (f.data == nil) { + print(S("choose: file not found: ")); + print(arg); + print(S("\n")); + } else { + str iter = f; + int choices = 0; + while (str_walk(&iter, S("\n")).len > 0) + choices++; + + if (choices > 0) { + iter = f; + int chosen = rand() % choices; + str line; + for (int i = 0; i < chosen; i++) + line = str_walk(&iter, S("\n")); + print(line); + print_char('\n'); + } + + free(f.data); + } +} + typedef struct { str name; void (*fn)(str arg); @@ -302,6 +330,7 @@ static command registry[] = { { S("cheese"), &cmd_cheese }, { S("watchdog"), &cmd_watchdog }, { S("clocktest"), &cmd_clocktest }, + { S("choose"), &cmd_choose }, }; void shell_run_cmd(str cmd) |