-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Adding line number printing when output is piped out #2983
Open
domenicomastrangelo
wants to merge
15
commits into
sharkdp:master
Choose a base branch
from
domenicomastrangelo:2935-compatibility-issue-with-cat-piping
base: master
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.
Open
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
bb411ab
Adding line number printing when output is piped out
debf7c3
Added CHANGELOG entry
a3234bf
cargo fmt --check
5727ccb
Fixed file_with_invalid_utf8_filename integration test
de19b52
Merge branch 'master' into 2935-compatibility-issue-with-cat-piping
domenicomastrangelo 1eec98b
Add check for non-terminal/tty handle
9523e40
Merge branch '2935-compatibility-issue-with-cat-piping' of github.com…
76832ef
cargo fmt
8ad55ab
Trigger Build
320f42b
Added current line number prefix
f96427f
Added current line number prefix
c0c1fd6
Merge branch '2934-compatibility-issue-with-cat-piping' of github.com…
2ba6813
Added switch to plain style as default:w in case of loop_through = true
1f4d6f0
Changed default to be Plain in case of loop_through
b13049a
Merge branch 'master' into 2935-compatibility-issue-with-cat-piping
domenicomastrangelo 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 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious, is this really the expected behavior? The test invokes
bat
without any line number style component arguments. I think it should stay as it was before - according to the issue being solved, line numbers should only be displayed when piping when the command line argument was explicitly passed, no?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch!
I added a check for handle type here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this doesn't pass the test now, it seems like there may be an issue with the filename and the is_terminal() function or something like that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
debugging it shows self.config.style_components.numbers() returns true, is there a different way to know if line numbers are requested that i'm missing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My guess would be the following:
The
SimplePrinter
is used whenever stdout is not interactive,--color
is not set toalways
,--decorations
is not set toalways
and--force-colorization
is not set either (see app.rs, config.rs and controller.rs).--style
controls which style components (such as header or line numbers) are used. The default for--style
ischanges,grid,header-filename,numbers,snip
. This default currently stays the same even ifloop_through == true
(which means thatSimplePrinter
will be used). Currently,SimplePrinter
just does not care about--style
.So, when
loop_through == true
, the default for--style
should beplain
instead. Then your changes should work since they do when you specify--style=plain
explicitly.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the tip @einfachIrgendwer0815!
I updated the code and pushed the changes, now all the tests pass correctly and I removed all the integration test changes which were not necessary.
I also added a test for this specific case :)