-
Notifications
You must be signed in to change notification settings - Fork 538
fix(paging): skip pager when stdout is not a terminal #2152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
HaleTom
wants to merge
5
commits into
dandavison:main
Choose a base branch
from
HaleTom:null-in-null-out
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+70
−0
Open
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0a6938e
fix(paging): skip pager when stdout is piped
HaleTom 3dc15fe
fixup: address Copilot review feedback (PR #2152)
HaleTom 5ba138c
fix: address Copilot review feedback on tests/empty_stdin.rs
HaleTom 36a8308
fix: use PathBuf for cross-platform path construction in delta_bin()
HaleTom 3fad53f
fix(tests): use var_os for CARGO_BIN_EXE_delta lookup
HaleTom File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| # Production-ready bar for this PR | ||
|
|
||
| 1. **Empty stdin produces zero output** — `printf '' | delta | wc -c` must be 0, no phantom blank line. | ||
| 2. **Normal diff pipeline unchanged** — `git diff | delta` must still work identically (pager still starts when stdout is a terminal). | ||
| 3. **`--paging=always` overrides terminal check** — user's explicit `--paging=always` is still honored even with piped stdout. | ||
| 4. **No regression in existing tests** — the 434 passing tests must still pass. | ||
| 5. **ANSI escape sequences not emitted spuriously** — the fix must not introduce new ANSI output on empty stdin or normal diff pipelines. | ||
| 6. **Terminal detection path correct** — `io::stdout().is_terminal()` is the right check for paging decision. | ||
| 7. **Changes minimal and scoped** — only the paging decision is touched, no unrelated refactoring. | ||
|
|
||
| # Findings | ||
|
|
||
| ## 1. Correctness & functional completeness | ||
|
|
||
| - No issues found in this area based on the diff and reviewed context. | ||
|
|
||
| ## 2. Architecture & boundary integrity | ||
|
|
||
| - No issues found in this area based on the diff and reviewed context. | ||
|
|
||
| ## 3. Code clarity, clean code & maintainability | ||
|
|
||
| - No issues found in this area based on the diff and reviewed context. | ||
|
|
||
| ## 4. Comments & code documentation | ||
|
|
||
| - No issues found in this area based on the diff and reviewed context. | ||
|
|
||
| ## 5. Tests & validation | ||
|
|
||
| ### [RESOLVED] No test coverage for the new terminal-detection branch | ||
| - Type: Unverified concern | ||
| - Evidence: Test infrastructure uses `capture_output=Some(...)` which takes the `PagingMode::Capture` path at `src/main.rs:152`. The new `else if` at `src/main.rs:153` is never exercised in tests. | ||
| - Why it matters: A future refactor of the paging logic could break this path without detection. | ||
| - Recommendation: Add a test that runs delta with piped stdin and piped stdout and asserts zero output. This can be done via a shell-based integration test or by refactoring `run_app` to accept a flag for testing. | ||
| - Resolution: Added `main_tests::test_no_output_on_empty_stdin_when_stdout_piped` and `main_tests::test_empty_stdin_does_not_hang_with_paging_always` to `src/main.rs` (lines 311+). These spawn the delta binary as a subprocess with piped stdin/stdout, exercising the terminal-detection branch directly. Both tests pass. | ||
| - Confidence: Low → High (resolved) | ||
|
|
||
| ## 6. Performance | ||
|
|
||
| - No issues found in this area based on the diff and reviewed context. | ||
|
|
||
| ## 7. Operational risk | ||
|
|
||
| ### [NON-BLOCKING] `--paging=always` + piped stdout still affected by LESSOPEN | ||
| - Type: Plausible risk | ||
| - Evidence: `src/main.rs:153` | ||
| - Why it matters: If a user explicitly sets `--paging=always` and pipes output to another process, the pager still starts. The `LESSOPEN=highlight-less-wrapper` pipeline could still emit the ANSI escape on empty stdin. This is the same behavior as before the fix — not a regression. The `Always` path is an explicit user opt-in. | ||
| - Recommendation: No action needed. Document in the issue that `--paging=never` is recommended when piping delta output. | ||
| - Confidence: Medium | ||
|
|
||
| ## 8. Adversarial review | ||
|
|
||
| - No issues found in this area based on the diff and reviewed context. | ||
|
|
||
| # What I could not fully verify | ||
|
|
||
| - The fix's behavior on Windows or other non-Linux platforms. `io::stdout().is_terminal()` is the standard Rust `IsTerminal` trait which is supported on all tier-1 platforms, so this should be equivalent to the Linux behavior, but I could not run on Windows. | ||
| - The interaction with all possible `LESSOPEN` or pager wrapper configurations beyond the one in this environment (`highlight-less-wrapper`). | ||
|
|
||
| # Final verdict | ||
|
|
||
| ✅ Ready to merge — no blocking issues. | ||
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.