Repository navigation
grep: apply GREP_COLORS sl=, cx= and rv whole-line coloring - #257
yunusarda-sudo wants to merge 2 commits into
Conversation
Support whole-line colors from GREP_COLORS: sl= for selected lines, cx= for context lines, and rv to swap sl and cx when -v is specified. Wrap line content in the resolved line color, restore line color after match segments, and preserve uncolored output in -o mode. Fixes uutils#169 Signed-off-by: Yunus Arda Güney <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #257 +/- ##
==========================================
+ Coverage 97.22% 97.37% +0.14%
==========================================
Files 6 6
Lines 2270 2284 +14
Branches 245 251 +6
==========================================
+ Hits 2207 2224 +17
+ Misses 63 60 -3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Merging this PR will not alter performance1 warning
Comparing Footnotes
|
GNU grep's
GREP_COLORSsupports whole-line colors:sl=for selected lines,cx=for context lines, andrv, which swaps the two when-v(config.invert_match) is active.While
ColorConfig::from_envparsed and stored these values,OutputWriter::write_line_with_matchesinsrc/output.rspreviously did not emit them.Solution
OutputWriter::write_line_with_matches:line_colorbased onview.is_match,invert_match, andreverse_video:write_colored_prefix(line_color)at the start of the line content ifhas_line_color.write_colored_bytesresets styling, re-emitwrite_colored_prefix(line_color)so the remaining line segments stay colored.write_colored_suffix()before the line terminator ifhas_line_color.-omode.tests/test_grep.rs:grep_colors_selected_and_context_linecoveringsl=,cx=,rvwith-v,sl=withoutrv, and-o.Fixes #169