Skip to content
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

Always displays escape characters #271

Closed
db0 opened this issue Sep 4, 2018 · 11 comments
Closed

Always displays escape characters #271

db0 opened this issue Sep 4, 2018 · 11 comments
Labels
bug Something isn't working question Further information is requested

Comments

@db0
Copy link

db0 commented Sep 4, 2018

Whenever I'm trying to bat a file, I always get an output like this
ESC[38;5;238m───────┬───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────ESC[0m ESC[38;5;238m│ ESC[0mFile: ESC[1mREADME.mdESC[0m ESC[38;5;238m───────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────ESC[0m ESC[38;5;238m 1ESC[0m ESC[38;5;238m│ESC[0m ESC[38;2;253;151;31m#ESC[0mESC[38;2;253;151;31m ESC[0mESC[38;2;253;151;31mparallel-sshESC[0m ESC[38;5;238m 2ESC[0m ESC[38;5;238m│ESC[0m ESC[38;5;238m 3ESC[0m ESC[38;5;238m│ESC[0m ESC[38;2;255;255;255mThis is an attempt to reboot pssh. ESC[0m ESC[38;5;238m 4ESC[0m ESC[38;5;238m│ESC[0m ESC[38;5;238m 5ESC[0m ESC[38;5;238m│ESC[0m ESC[38;2;253;151;31m##ESC[0mESC[38;2;253;151;31m ESC[0mESC[38;2;253;151;31mGoalsESC[0m ESC[38;5;238m 6ESC[0m ESC[38;5;238m│ESC[0m ESC[38;5;238m 7ESC[0m ESC[38;5;238m│ESC[0m ESC[38;2;119;119;119m*ESC[0mESC[38;2;255;255;255m ESC[0mESC[38;2;255;255;255mCleaner code, where possibleESC[0m ESC[38;5;238m 8ESC[0m ESC[38;5;238m│ESC[0m ESC[38;2;119;119;119m*ESC[0mESC[38;2;255;255;255m Incorporate many of the patches and fix many of the issues found atESC[0m ESC[38;5;238m 9ESC[0m ESC[38;5;238m│ESC[0m ESC[38;2;255;255;255m ESC[0mESC[4;38;2;166;226;46mhttps://github.comESC[0mESC[4;38;2;166;226;46m/lilydjwg/pssh/issuesESC[0m ESC[38;5;238m 10ESC[0m ESC[38;5;238m│ESC[0m ESC[38;2;119;119;119m*ESC[0mESC[38;2;255;255;255m Add a few features (-L/--list-hosts, for one)ESC[0m ESC[38;5;238m 11ESC[0m ESC[38;5;238m│ESC[0m ESC[38;5;238m 12ESC[0m ESC[38;5;238m│ESC[0m ESC[38;2;253;151;31m##ESC[0mESC[38;2;253;151;31m ESC[0mESC[38;2;253;151;31mOriginal README.mdESC[0m ESC[38;5;238m 13ESC[0m ESC[38;5;238m│ESC[0m ESC[38;2;255;255;255mPSSH provides parallel versions of OpenSSH and related tools, including pssh, pscp, prsync, pnuke and pslurp. This project includes psshlib which can be used within custom applications. The source code ESC[0m ESC[38;5;238m ESC[0m ESC[38;5;238m│ESC[0m ESC[38;2;255;255;255mis written in PythonESC[0m ESC[38;5;238m 14ESC[0m ESC[38;5;238m│ESC[0m ESC[38;5;238m 15ESC[0m ESC[38;5;238m│ESC[0m ESC[38;2;255;255;255mPSSH is supported on Python 2.5 and later (including Python 3.1 and later). It was originally written and maintained by Brent N. Chun. Due to his busy schedule, Brent handed over maintenance to Andrew MESC[0m ESC[38;5;238m ESC[0m ESC[38;5;238m│ESC[0m ESC[38;2;255;255;255mcNabb in October 2009.ESC[0m ESC[38;5;238m 16ESC[0m ESC[38;5;238m│ESC[0m ESC[38;5;238m 17ESC[0m ESC[38;5;238m│ESC[0m ESC[38;2;255;255;255mThis project originally located at ESC[0mESC[38;2;255;255;255m[ESC[0mESC[38;2;255;255;255mGoogle CodeESC[0mESC[38;2;255;255;255m]ESC[0mESC[38;2;255;255;255m(ESC[0mESC[4;38;2;166;226;46mhttps://code.google.com/p/parallel-ssh/ESC[0mESC[38;2;255;255;255m)ESC[0mESC[38;2;255;255;255m. Since Google Code has been closed, and has not appeared elsewhere, I (lilydjwg) have exported it to GitHub.ESC[0m ESC[38;5;238m───────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────ESC[0m

I searched around and found #98 which seems relevant, and it did lead me to thinking the culprit is less, so using --paging=never which seems to work. It seems that without it, bat always default to using less, even if the output is less than one screen, and for some reason that paging fails to display escape characters correctly.

However if I simply pipe the bat --paging=never output to less, then it displays fine paged, so I'm not sure what is causing this.

I'm using it on Fedora 27, using Gnome Terminal and bat 0.6.1 compiled with cargo.

@sharkdp
Copy link
Owner

sharkdp commented Sep 4, 2018

Thank you for reporting this.

What is the content of the PAGER and BAT_PAGER environment variables?

@sharkdp sharkdp added the question Further information is requested label Sep 4, 2018
@db0
Copy link
Author

db0 commented Sep 4, 2018

PAGER=/usr/bin/less
BAT_PAGER is empty

@sharkdp
Copy link
Owner

sharkdp commented Sep 4, 2018

Can you please try to set PAGER (or BAT_PAGER) to less (instead of /usr/bin/less)?

@db0
Copy link
Author

db0 commented Sep 4, 2018

Wow that did the trick! How can the full path be causing this?

@sharkdp
Copy link
Owner

sharkdp commented Sep 4, 2018

Thank you for checking.

This is partly bat's fault. We currently explicitly check for PAGER == "less" here:

bat/src/output.rs

Lines 29 to 37 in 9316f2a

let mut process = if pager == "less" {
let mut args = vec!["--RAW-CONTROL-CHARS", "--no-init"];
if quit_if_one_screen {
args.push("--quit-if-one-screen");
}
let mut p = Command::new("less");
p.args(&args).env("LESSCHARSET", "UTF-8");
p

If we detect less as a pager, we add a command-line option which is necessary to interpret the ANSI-color-sequences (--RAW-CONTROL-CHARS). We should make that check more robust, such that we also add these options if PAGER == "/usr/bin/less" or similar.

@sharkdp sharkdp added the bug Something isn't working label Sep 4, 2018
@db0
Copy link
Author

db0 commented Sep 4, 2018

Gotcha! Thanks for the quick fix.

@sharkdp sharkdp closed this as completed in 1d9e7ac Sep 5, 2018
@sharkdp
Copy link
Owner

sharkdp commented Sep 12, 2018

Fix released in v0.7.0.

@WiSaGaN
Copy link

WiSaGaN commented Nov 1, 2018

The fix is not able to detect something like /usr/bin/less -X. Is it accidental?

@sharkdp
Copy link
Owner

sharkdp commented Nov 1, 2018

The fix is not able to detect something like /usr/bin/less -X. Is it accidental?

No. If you decide to pass your own arguments to less (here: -X), bat will not pass any additional arguments to less. You will have to pass -R yourself.

@TomLavenziano
Copy link

Currently running v0.9.0 and still had the same problem.

I have PAGER=most
Setting BAT_PAGER=less did the trick to fix it.

@sharkdp
Copy link
Owner

sharkdp commented Nov 25, 2018

@TomLavenziano I think a recent change in bat made things worse here. Please see #430

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Further information is requested
Projects
None yet
Development

No branches or pull requests

5 participants
@db0 @WiSaGaN @sharkdp @TomLavenziano and others