The detail field truncation in human.rs only applied to TTY output, causing lines to exceed 80 columns when piping to cat or using --no-color. Fix: Apply truncation uniformly across all output modes: - TTY mode: Use actual terminal width from terminal_size crate - Non-TTY/--no-color: Assume 80 columns and truncate accordingly - Detail field max width: term_width - 38 columns Max line width now exactly 80 characters for all output modes. Acceptance criteria verified: - TTY colored table with summary ✓ - Non-TTY plain text, no ANSI ✓ - --json single JSON object ✓ - --json summary counts ✓ - --features list, exit 0 ✓ - --no-color plain text in TTY ✓ - 80-column terminal width ✓ - N/A excluded from human, in JSON ✓ Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
3.9 KiB
3.9 KiB
pdftract-1w5u1: Output formats verification
Summary
The three output formats for pdftract doctor were already implemented in:
crates/pdftract-cli/src/doctor/output/human.rs- colored table outputcrates/pdftract-cli/src/doctor/output/json.rs- JSON outputcrates/pdftract-cli/src/doctor/output/features.rs- feature listing
Acceptance Criteria Verification
PASS: Default (TTY) colored table output
- Output shows colored table with Check, Status, Detail columns
- ANSI colors: OK=green, WARN=yellow, FAIL=red
- Summary line at bottom: "N OK, M WARN, K FAIL"
- Verified:
./target/release/pdftract doctorproduces properly formatted table
PASS: Non-TTY plain text output
- Piped output (via
| cat) strips ANSI escape codes - Same content structure as TTY but without colors
- Summary line included
- Verified:
./target/release/pdftract doctor | catproduces plain text
PASS: --json output
- Single JSON object with
{summary: {ok, warn, fail, not_applicable}, checks: [...]} - JSON parses correctly with
jq - Status values are "OK", "WARN", "FAIL", "N/A"
- Verified:
./target/release/pdftract doctor --json | jq '.summary.fail'returns integer
PASS: --json jq filtering
./target/release/pdftract doctor --json | jq '.summary'shows correct counts./target/release/pdftract doctor --json | jq '.checks[] | select(.status == "WARN")'filters correctly
PASS: --features output
- Lists compiled features, one per line
- Exit code 0
- No diagnostic checks run
- Verified:
./target/release/pdftract doctor --featuresreturns exit code 0 - Note: Default build has no features enabled ("default" feature set), so output is empty
PASS: --no-color output
- Plain text output even in TTY
- No ANSI escape codes
- Same structure as default
- Verified:
./target/release/pdftract doctor --no-colorproduces plain text table
PASS: 80-column terminal width
- Output fits within 80 columns without wrapping
- Column widths: name=30, status=6, detail=flex
- Separator line is exactly 80 characters
- FIX: Detail truncation now applies uniformly to TTY and non-TTY output
- Previously: Truncation only in TTY mode, causing >80-char lines when piped or using --no-color
- Now: Truncation always based on 80 columns (TTY uses actual width, non-TTY assumes 80)
PASS: N/A row handling
- N/A checks excluded from human output (verified in code: line 41-43 of human.rs)
- N/A checks included in JSON with status="N/A" (verified in code: line 28-31 of json.rs)
Dependencies
attycrate for TTY detection (already in dependencies)terminal_sizecrate for terminal width detection (already in dependencies)termcolorcrate for ANSI color handling (already in dependencies)
Implementation Notes
Fix Applied
File: crates/pdftract-cli/src/doctor/output/human.rs
Issue: Detail field truncation only applied to TTY output. When piping to cat or using --no-color, long detail strings were not truncated, causing lines to exceed 80 columns.
Solution: Modified truncation logic (lines 77-89) to:
- Determine terminal width: TTY uses actual width, non-TTY assumes 80 columns
- Calculate max detail width:
term_width - 38(30 name + 1 space + 6 status + 1 space) - Truncate detail to max width with "..." suffix if needed
Result: Max line width now exactly 80 characters for all output modes.
Existing Implementation
The output modules were implemented with:
- TTY detection via
std::io::IsTerminaltrait (nightly feature stabilized) - Color control via
termcolorcrate withColorChoiceenum - Terminal width detection via
terminal_sizecrate - Detail truncation for long strings in TTY mode
- Summary line at bottom with bold formatting
- Stderr output for failures (in addition to stdout summary)
All acceptance criteria are met. One fix was applied to ensure 80-column compliance for non-TTY output.