The Wayback Machine - https://web.archive.org/web/20210421032100/https://github.com/sharkdp/bat/issues/1385
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

Wrong colors, lots of â" characters on Windows #1385

Open
xobs opened this issue Nov 16, 2020 · 10 comments
Open

Wrong colors, lots of â" characters on Windows #1385

xobs opened this issue Nov 16, 2020 · 10 comments

Comments

@xobs
Copy link

@xobs xobs commented Nov 16, 2020

What version of bat are you using?
bat 0.16.0

Describe the bug you encountered:
Output is unreadable, and contains a lot of garbage.

image

What did you expect to happen instead?
Usable output

How did you install bat?
cargo install bat

Terminal: Windows Terminal 1.3.2651.0
Font: CaskaydiaCove NF
Codepage: 437
Shell: PowerShell 7.0.3

Windows Build 2004

@xobs xobs added the bug label Nov 16, 2020
@eth-p
Copy link
Collaborator

@eth-p eth-p commented Nov 16, 2020

Not too sure about the colors yet, but the random characters where the grid separator should be looks like a unicode decoding issue.

A couple questions:

Does your font support unicode characters?

Is your pager less, and if so, what version is it?

Are you using Git Bash/MSYS2/Cygwin, or the native Windows environment?

What happens if you use --paging=never?

@eth-p eth-p added the windows label Nov 16, 2020
@xobs
Copy link
Author

@xobs xobs commented Nov 16, 2020

Yes, my font supports Unicode characters. I'm using Starship and lsd which print out things using Nerd Fonts.

I'm unsure what my pager is. I don't have $env:PAGER set to anything, and I'm not sure that Windows would honor that anyway.

I'm using a native Windows environment, running Powershell 7.0.3. I notice this isn't the latest version, so I'll upgrade to Powershell 7.1.0 to see if that fixes things at all. Edit: Powershell 7.1.0 doesn't change things.

If I use --paging=never it works:

image

@xobs
Copy link
Author

@xobs xobs commented Nov 16, 2020

It appears as though bat has found less.exe version 436 in my path, and is using that. If I remove less, then things look as expected:

image

@xobs
Copy link
Author

@xobs xobs commented Nov 16, 2020

I've removed the MinGW install, since I'm not sure where it came from. As a result, this is no longer an issue for me. You may close this Issue if you feel it is resolved.

However, it may still be considered a problem that the presence of less.exe in the PATH can cause incorrect output, so this perhaps can still be considered an issue.

@sharkdp
Copy link
Owner

@sharkdp sharkdp commented Nov 23, 2020

Thanks for figuring this out and posting the explanation here.

We could test for very old versions of less (11 years old) and potentially skip them or print an error (on Windows). We already check the version of less, so that would be an easy fix.

@xobs
Copy link
Author

@xobs xobs commented Nov 23, 2020

To be fair, this isn't the first time I've been bitten by random things in the PATH on Windows. Strange and bizarre things happen if sh.exe is there and you try to use make, for example.

There appeared to be a check already, but it wasn't getting triggered. I agree that it's a good first issue.

@Acelya-9028
Copy link

@Acelya-9028 Acelya-9028 commented Jan 16, 2021

Hello, I have a similar issue :s

As you can see below:

bat_default
bat_without_pager

And my settings:

set guifont=CaskaydiaCove\ NF:h15
→ ~\AppData\Local\nvim [master ↑2 +0 ~1 -0 !]› pwsh --version
PowerShell 7.1.0
→ ~\AppData\Local\nvim [master ↑2 +0 ~1 -0 !]› bat --version
bat 0.17.1
→ ~\AppData\Local\nvim [master ↑2 +0 ~1 -0 !]› [System.Text.Encoding]::Default.EncodingName
Unicode (UTF-8)
→ ~\AppData\Local\nvim [master ↑2 +0 ~1 -0 !]› less --version
less 563 (Spencer V8 regular expressions)
Copyright (C) 1984-2020  Mark Nudelman

less comes with NO WARRANTY, to the extent permitted by law.
For information about the terms of redistribution,
see the file named README in the less distribution.
Home page: http://www.greenwoodsoftware.com/less
→ ~\AppData\Local\nvim [master ↑2 +0 ~1 -0 !]› Get-Command less

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Application     less.exe                                           0.8.1.0    C:\ProgramData\chocolatey\bin\less.exe

Is there an alternative to less as pager? Thank you for the help!

@eth-p
Copy link
Collaborator

@eth-p eth-p commented Jan 18, 2021

That is pretty weird... Recent versions of less should work.

Is there any alternative to less as a pager?

We don't officially support other pagers, but we also don't stop people^1 from using other pagers if they can find a suitable one.

I don't know of any alternatives for Windows, but I can tell you the features that it would need to support:

  • ANSI color codes
  • UTF-8

^1. Barring a few exceptions which are known to not work:

bat/src/pager.rs

Lines 101 to 107 in d36b091

let use_less_instead = match (&source, &kind) {
// 'more' and 'most' do not supports colors; automatically use 'less' instead
// if the problematic pager came from the generic PAGER env var
(PagerSource::EnvVarPager, PagerKind::More) => true,
(PagerSource::EnvVarPager, PagerKind::Most) => true,
// If PAGER=bat, silently use 'less' instead to prevent recursion ...

@Acelya-9028
Copy link

@Acelya-9028 Acelya-9028 commented Jan 21, 2021

Thank you very much.

So I found the solution, obviously it's an encoding problem, but where? Which put me on the way is that inside the Powershell Console (GUI) (v7.1.1), I don't have any problems.

image

So, <U+2500> is displayed only inside the Neovim embeded terminal and play with $env:LESSCHARSET change displayed things.

chcp return 0 and [console]::InputEncoding; [console]::OutputEncoding; return

IsSingleByte      : True
EncodingName      : Western European (Windows)
WebName           : windows-1252
HeaderName        : windows-1252
BodyName          : iso-8859-1
Preamble          :
WindowsCodePage   :
IsBrowserDisplay  :
IsBrowserSave     :
IsMailNewsDisplay :
IsMailNewsSave    :
EncoderFallback   : System.Text.InternalEncoderBestFitFallback
DecoderFallback   : System.Text.InternalDecoderBestFitFallback
IsReadOnly        : True
CodePage          : 1252

IsSingleByte      : True
EncodingName      : Western European (Windows)
WebName           : windows-1252
HeaderName        : windows-1252
BodyName          : iso-8859-1
Preamble          :
WindowsCodePage   :
IsBrowserDisplay  :
IsBrowserSave     :
IsMailNewsDisplay :
IsMailNewsSave    :
EncoderFallback   : System.Text.InternalEncoderBestFitFallback
DecoderFallback   : System.Text.InternalDecoderBestFitFallback
IsReadOnly        : False
CodePage          : 1252

So to fix it, put the below code inside your Powershell $profile file.

[console]::InputEncoding = [console]::OutputEncoding = New-Object System.Text.UTF8Encoding

image

For more information, read this and this.

EDIT: You can also use $OutputEncoding instead of [console]::InputEncoding; [console]::OutputEncoding;. I think this can fix your problem @xobs.

@sharkdp
Copy link
Owner

@sharkdp sharkdp commented Feb 16, 2021

Ok, is there anything left to do here? Should the findings be documented somewhere?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment