Skip to content

Conversation

@einfachIrgendwer0815
Copy link
Contributor

Fixes #636 with the solution proposed in this comment.

The limit at which reading continues but content gets discarded is now called "soft limit". Respectively, the limit at which bat will abort is now called "hard limit".

The default values for the soft and hard limits can be overwritten using the --soft-line-limit and --hard-line-limit cli options. --disable-line-limits will disable both limits.

Copy link
Collaborator

@Enselic Enselic left a comment

Choose a reason for hiding this comment

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

Hi! A took a quick look and had some drive-by comments.

Line length (in bytes) at which the line will be ignored. Zero disables this limit.
Default: 64 kB

--hard-line-limit <BYTES>
Copy link
Collaborator

Choose a reason for hiding this comment

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

In what scenario do we prefer aborting bat over ignoring the line?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is helpful for files (especially pseudo-files) that have very long lines or do not contain any LF characters at all. One example given in #636 is /dev/zero. Let us assume there is the soft limit but not the hard limit. When reading such a file, bat would hang forever while wasting CPU time.

So the soft limit prevents out-of-memory events, the hard limit additionally prevents hanging infinitely.

Admittedly, the use case is tiny. Removing the hard limit is probably fine, since oom crashes are already prevented by the soft limit alone.

escape sequences unless the syntax highlighting language is plain text. Possible values:
auto, always, *never*.

--disable-line-limits
Copy link
Collaborator

Choose a reason for hiding this comment

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

The fewer options the better IMO. So I don't think we need this one, since I don't think we need two settings (see comment below).

--disable-line-limits
Disables all line limits. Short for `--soft-line-limit 0 --hard-line-limit 0`.

--soft-line-limit <BYTES>
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm thinking about the name for this. What name for this setting do other editors use?

│ File: sample.rs
───────┼────────────────────────────────────────────────────────────────────────
1 │ /// A rectangle. First line is changed to prevent a regression of #1869
2 │ struct Rectangle {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we prevent formatting to change in this file (and others?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The inserted spaces are there to leave room for the ! that is placed in front of replaced lines, so that the formatting does not look off in those cases. Without these placeholder spaces the formatting would stay as it was, however, the grid would look weird for replaced lines.

It would look something like this:

 51 │ normal content
 52 ! │ <line too long>
 53 │ normal content

The other alternative is to not add the ! altogether:

 51 │ normal content
 52 │ <line too long>
 53 │ normal content

But, especially without color, it would be somewhat easy to overlook that a line was replaced.

@Enselic Enselic added the waiting-on-author Progress on this PR is blocked mostly because we are waiting on the author of the PR to do something label Aug 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-on-author Progress on this PR is blocked mostly because we are waiting on the author of the PR to do something

Projects

None yet

Development

Successfully merging this pull request may close these issues.

files of infinite length cause bat to crash

2 participants