Skip to content

Conversation

@UdeshyaDhungana
Copy link
Contributor

@UdeshyaDhungana UdeshyaDhungana commented Nov 28, 2025

  • Add feature for Grep/Highlighting extension in emulated grep

Note

Adds --color (always|never|auto) to emulated grep with TTY-aware match highlighting and updates tests/utilities accordingly.

  • Grep core:
    • Add --color flag with modes always|never|auto and validate input.
    • Introduce EmulationOptions{ Stdin, EmulateInTTY } and update EmulateGrep(args, EmulationOptions) signature.
    • Enable match highlighting for stdin searches based on color mode and EmulateInTTY.
  • Highlighting:
    • Implement highlightMatches in internal/grep/stdin_search.go using utils.HighlightString for ANSI-wrapped matches.
  • Tests:
    • Extend stdin tests to cover color modes, TTY behavior, and multi-match highlighting.
    • Update test harnesses to pass EmulationOptions and compare against new highlighting behavior.
  • Utils:
    • Add utils.HighlightString for grep-style ANSI highlighting.

Written by Cursor Bugbot for commit 10422be. This will update automatically on new commits. Configure here.

@UdeshyaDhungana UdeshyaDhungana changed the title Make emulated grep support --color arg Make emulated grep support --color argument Nov 28, 2025
pattern: "\\d",
input: "a1b",
colorMode: "always",
expected: Result{ExitCode: 0, Stdout: []byte("a" + utils.HighlightString("1") + "b")},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to avoid logic in assertions - hardcode the expected bytes here. That way we're protected against accidental changes to the logic inside utils.HighlightString.

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.

3 participants