Skip to content

add read tool formatters#1016

Open
LasmarKhalifa wants to merge 1 commit into
06-30/pi-tool-formatter-bashfrom
06-30/pi-tool-formatter-read
Open

add read tool formatters#1016
LasmarKhalifa wants to merge 1 commit into
06-30/pi-tool-formatter-bashfrom
06-30/pi-tool-formatter-read

Conversation

@LasmarKhalifa

@LasmarKhalifa LasmarKhalifa commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Closes #1024

LasmarKhalifa commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@LasmarKhalifa LasmarKhalifa force-pushed the 06-30/pi-tool-formatter-read branch from 1522547 to 2162423 Compare July 3, 2026 15:30
@LasmarKhalifa LasmarKhalifa marked this pull request as ready for review July 3, 2026 16:30

@mathiusj mathiusj left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

read formatters look good. Two edge/consistency notes.

path = truncate(path)
details = if limit
offset ||= 1
"lines #{offset}–#{offset + limit - 1}"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Edge case: with limit: 0 this renders (lines 1–0) — a backwards range (offset + limit - 1 = 1 + 0 - 1 = 0). limit: 0 isn't obviously invalid input from Pi. Minor, but a limit.positive? guard (or documenting that limit is assumed ≥1) avoids the inverted range.

# READ OK 0 lines
#
#: () -> String
def format_read

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Counting inconsistency with the later sibling formatters. This counts content.to_s.lines.length (includes blank lines). The find/ls result formatters landing later in the stack use .map(&:strip).reject(&:empty?).length (drop blanks), so content "a\n\nb" reports 3 here vs 2 there. Same "count the lines" job, two rules. Worth making deliberate now — either align, or add a comment that read reports file line count (blanks included) while entry-listing tools don't.

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.

2 participants