feat(fields): add the {lines} first-class line-count field (#114) - #282
Merged
Conversation
A per-text-file line count in the field vocabulary: {lines}, %{lines} in
-printf, and --template - wc -l style but also counting a final unterminated
line. Empty for a non-regular, unreadable, or binary file (grep/ripgrep's
NUL-byte-in-first-8KiB heuristic), so binaries render nothing rather than a
misleading count.
- xff/content: CountLines (pure, reuses the CollectLineMatches grep line
semantics via ForEachLine) + FileLineCount (reads via mbo::file::Artefact,
skips binary), next to the line-match logic they share.
- xff/fields: LinesField reads by path (like {hash}), gated on a regular-file
metadata type; registered in the field table + FieldDocs (so --help=fields,
man, and markdown list it by construction).
- Tests: CountLines/FileLineCount unit tests, LinesField render tests
(text/no-newline/empty/binary/unreadable/non-regular), and a CLI bashtest
driving -printf %{lines} end to end.
The aggregate side (sum + distribution across matches) is the histograms
work (#81), not part of this field.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a per-text-file line count as a first-class field, the prerequisite for the histograms
linesmetric (#81).What
{lines}in the field vocabulary: usable as{lines},-printf '%{lines}', and--template.wc -lstyle, but also counts a final line with no trailing newline.Where
xff/content:CountLines(pure; reuses theCollectLineMatchesgrep line semantics viaForEachLine) +FileLineCount(reads viambo::file::Artefact, skips binary) - co-located with the line-match logic they share.xff/fields:LinesFieldreads by path (like{hash}), gated on a regular-file metadata type; registered in the field table +FieldDocs, so--help=fields/ man / markdown list it by construction.Tests
CountLines/FileLineCount(empty, no-trailing-newline, CRLF, binary, unreadable).LinesField(text / no-newline / empty / binary / unreadable / non-regular).-printf '%{lines}'end to end.The aggregate side (sum + distribution across matches) is the histograms work (#81), not part of this field.
TODO.mdupdated accordingly.