Skip to content

Add --slurp flag to read the input stream as one array - #126

Open
ChrisJr404 wants to merge 1 commit into
ynqa:mainfrom
ChrisJr404:add-slurp-flag
Open

Add --slurp flag to read the input stream as one array#126
ChrisJr404 wants to merge 1 commit into
ynqa:mainfrom
ChrisJr404:add-slurp-flag

Conversation

@ChrisJr404

Copy link
Copy Markdown

Closes #29.

jq has a --slurp mode that folds a whole stream of values into one array so the filter runs against the array as a whole. This adds the same option to jnv as -s/--slurp.

Right now feeding JSON Lines runs the filter once per value. With --slurp the input becomes a single array first, so length, add, sort_by(...) and friends see the whole thing.

The fold happens once, just after the input is read and before it reaches the viewer and the completion loader, so nothing downstream changed. It honors max_streams like the normal path does, so I moved the config load a few lines up to have that value on hand (that also means a broken config is reported before we read stdin).

There was no test target yet, so I added the first unit tests, covering the slurp helper for empty input, JSON Lines, a single value, the max_streams bound and invalid input. cargo fmt --check, cargo clippy, cargo test and cargo build all pass. I couldn't drive the full TUI headless, so the wiring is covered by compilation and those tests rather than a live run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ENH: Add -s slurp mode, turning json-lines into an array

1 participant