-
-
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
Add Flag to Avoid Treating NUL Separated Input as Binary #2974
Comments
Hi @LangLangBart, would your issue be fixed by adding the flag -A to show non printable characters? This would result in the following output: |
Thanks for the suggestion. I failed to mention this in the issue report here and only described it in the linked discussion. For my use case, the I try to colorize my # zsh only, the '-N' flag separates the array elements by `NUL`
print -rNC1 -- "${(@uv)history}" | bat -pl zsh | fzf --read0 |
My bad, I missed the discussion link. So the issue you're having, is that when printing something (in this case a line from the history file), in case it has a null char in it, it will give an error. It feels like a very nieche problem to have, but I think it could be fixed, as you said, adding a --read0 or --read-null-bytes flag. I could work on this as I'm looking for my first contribution to the project, but it would be good to have an opinion from a more senior contributor too :) |
I'm personally in favor of the idea, but it would be great to wait for input from some of the other maintainers before spending time on it, in case we don't all agree 😉 |
I have updated the description, and I would propose a
Agreed, we should wait for input from some of the maintainers. |
Sounds good to me. Let's think about making this an option, not a flag. Maybe there are other reasonable options that we want to add later (apart from a yes or no decision). Like whether or not we print that warning. |
EDIT1: I found the reason in #248, and #336
How about |
great, so @LangLangBart you propose --input to specify which language to use for printing or did I get it wrong? so basically (more or less) if input not set
let mut first_line = vec![];
reader.read_until(b'\n', &mut first_line).ok();
let content_type = if first_line.is_empty() {
None
} else {
Some(content_inspector::inspect(&first_line[..]))
};
if content_type == Some(ContentType::UTF_16LE) {
reader.read_until(0x00, &mut first_line).ok();
}
else
content_type = get_content_type_from_input(input)
endif |
@einfachIrgendwer0815 started already a PR. Besides the color, it works well. Image below comparing |
@LangLangBart the color issue should be fixed now |
nice :) |
Discussed in #2971
Issue
Currently, running a command like the following will print a warning:
The warning is defined in
src/printer.rs
:bat/src/printer.rs
Lines 435 to 444 in 8f8c953
The decision to label the input as
BINARY
seems to be made insrc/input.rs
:bat/src/input.rs
Lines 260 to 271 in 8f8c953
A hacky workaround is to make the first line empty, use
bat
, and then remove the first line:Proposed solution
A new flag that doesn't label
content_type
asBINARY
when the first line ends with aNUL
byte:The
crate
1 used to determine if content isbinary
states:Based on this, a
--text
flag would be very appropriate, similar to howgrep
andgit diff
have one as well.Footnotes
sharkdp/content_inspector: Fast inspection of binary buffers to guess/determine the type of content ↩
The text was updated successfully, but these errors were encountered: