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

Color output is broken in some combinations on Windows + MSYS2 #657

Closed
martinlindhe opened this issue May 12, 2022 · 8 comments · Fixed by #688
Closed

Color output is broken in some combinations on Windows + MSYS2 #657

martinlindhe opened this issue May 12, 2022 · 8 comments · Fixed by #688

Comments

@martinlindhe
Copy link

  • os: windows
  • lsd --version: 0.21.0
  • echo $TERM: xterm-256color
  • echo $LS_COLORS:

Expected behavior

Seeing colors.

Actual behavior

With windows terminal, launcing bash using msys2:
image

wezterm, launching zsh using msys2:
image

See colored prompt and colored cargo output is working. Only "lsd" command output has codes showing ←[38;5;4m←[1m bin←[0m ←[38;5;4m←[1m pkg←[0m.

The same "lsd.exe" correctly shows colors in powershell and cmd.exe, and also when run thru stand-alone msys2.

@martinlindhe
Copy link
Author

martinlindhe commented May 17, 2022

Update:

I have done some investigation and the issue seems to have been resolved in 2019 but the code has since been refactored so the fix was lost.

PR #195 resolved this in 2019 but the code path is no longer in master.

What disappeared is the call to ansi_term::enable_ansi_support(), or similar.

The essence of the issue is that in Windows 10 an application need to "opt in" for ansi code support by calling SetConsoleMode() with the ENABLE_VIRTUAL_TERMINAL_PROCESSING bits set.
That is just what is going on inside ansi_term::enable_ansi_support:

https://github.com/ogham/rust-ansi-term/blob/ff7eba98d55ad609c7fcc8c7bb0859b37c7545cc/src/windows.rs#L51-L57

All of this is laid out in detail by a Microsoft employee here: microsoft/terminal#6634 (comment)

@martinlindhe
Copy link
Author

Update 2:

You might not want to accept my open PR to fix this issue, as I am attempting to fix the root cause in crossterm over at crossterm-rs/crossterm#666

A work-around for the moment to get lsd colors working on MSYS2 is something like this:

alias ls="TERM=dumb lsd"

because TERM=dumb short-circuits crossterm's broken terminal check.

@martinlindhe
Copy link
Author

Update 3: crossterm merged a fix for this in crossterm-rs/crossterm@35d58cc

When a new release of crossterm is out, we can update the dependency for lsd and this issue should be resolved.

@martinlindhe
Copy link
Author

martinlindhe commented Jul 3, 2022

This issue has been resolved in crossterm 0.24:

Fix escape codes on Git-Bash + Windows Terminal / Alacritty / WezTerm.

https://github.com/crossterm-rs/crossterm/releases/tag/0.24

@meain
Copy link
Member

meain commented Jul 3, 2022

I am guessing #675 is related.

@meain meain mentioned this issue Jul 3, 2022
5 tasks
@martinlindhe
Copy link
Author

@meain Yes, that is the same issue for sure.

@meain
Copy link
Member

meain commented Jul 4, 2022

@martinlindhe Would you be able to check if #688 fixes the issue? I have bumped the crossterm version.

@martinlindhe
Copy link
Author

@meain Confirmed working with x86-64-msvc artifact from your #688.
Capture

The second command is lsd 0.22.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants