Read the command line
You'll pass flags to the task list after --, read them in a loader and hand them to the page as props. The loader runs once, when the terminal opens. It starts from the list you built in 610.
Before you start
Install from crates.io. You need no Node and no package manager.
cargo install snapfire_compiler
cargo install snapfire_fsr_cli
fsr --version
Every command and screenshot on this page was captured with fsr 0.x.
Everything after -- is the app's#
fsr dev app --terminal reads its own flags up to --. The rest of the line goes to your app:
The terminal turns that line into params, a map of strings:
| You type | params gets |
|---|---|
--file work.json | file is "work.json" |
--limit=2 | limit is "2" |
--all with no value after it | all is "true" |
notes.txt with no flag before it | "0" is "notes.txt", the next one "1" |
Every value is a string. Convert a number yourself.
Write the loader#
Create app/routes/page.loader.ts beside the page:
;
This is the same loader a web page has. On the web it runs for each request. In the terminal it runs once, before the first frame. What it returns becomes the root page's props.
Take the props#
The page destructures what the loader returned. RootProps from @generated/client is the type of those props:
;
;
;
;
;
shown is the first limit tasks. The rows, the down arrow and the line under the rows read it.
Run it#
With no flags the loader's defaults apply:
╭──────────────────────────────────────────╮
│ Tasks tasks.json 2 open │
│ │
│ > Write the README │
│ Tag a release │
│ Answer the open issues │
│ │
│ up and down move, space marks one done │
│ Ctrl-C quits │
╰──────────────────────────────────────────╯
Quit and pass both flags:
╭──────────────────────────────────────────╮
│ Tasks work.json 2 open │
│ │
│ > Write the README │
│ Tag a release │
│ │
│ 1 more not shown │
│ up and down move, space marks one done │
│ Ctrl-C quits │
╰──────────────────────────────────────────╯
--limit=1 works too and leaves one row with 2 more not shown. The name does nothing yet. In the next step it picks the file the list is saved to.
Next up: 630. Save to a file.