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

No colors in Windows Terminal or cmd #1972

Closed
3 tasks done
sztomi opened this issue Feb 4, 2020 · 17 comments · Fixed by python-poetry/cleo#313
Closed
3 tasks done

No colors in Windows Terminal or cmd #1972

sztomi opened this issue Feb 4, 2020 · 17 comments · Fixed by python-poetry/cleo#313
Labels
area/cli Related to the command line kind/bug Something isn't working as expected

Comments

@sztomi
Copy link
Contributor

sztomi commented Feb 4, 2020

  • I am on the latest Poetry version.
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option).
  • OS version and name: Windows 10.0.18362.592
  • Poetry version: 1.0.3
  • Link of a Gist with the contents of your pyproject.toml file: n/a

Issue

This is #548 which was said to be fixed in "the latest beta" at the time, but now appears to be broken with no beta being more recent than the latest released version (1.0.3).

Long story short, there are no colors displayed on windows with any of the command shells I tried except in ConEmu. The default cmd.exe, powershell.exe and the new Windows Terminal don't display colors.

Some screenshots:

Powershell in Windows Terminal:

image

Cmd in Windows Terminal:

image

cmd.exe:

image

Cmd in Cmder (based on ConEmu) - This works!:

image

Powershell in Cmder (based on ConEmu):

image

This last one can probably be considered working as well, the green text is likely due to the cmder config.

@sztomi sztomi added the kind/bug Something isn't working as expected label Feb 4, 2020
@yelled1
Copy link

yelled1 commented Apr 26, 2020

@sztomi Did you also noticed that in Cmder at least as soon as I hit $poetry shell that all colors disappear & emacs key binding on the shell is gone as well? Have you found a fix for that or should I put in as second bug list?
Plus, do you get different prompt? Mine is plain C:\Prj\MOA> instead of what I see with pyenv:

C:\Prj  
λ v_awscli.bat
C:\Users\ny11559\.pyenv\pyenv-win\versions\aws_cli\Scripts\activate
C:\Prj  
(aws_cli) λ 

I know that this is supposed to be depreciated with PYENV_VIRTUALENV_DISABLE_PROMPT=1, but I will likely keep it as is.
Thanks,

@finswimmer finswimmer added the area/cli Related to the command line label Apr 28, 2020
@ewen-lbh
Copy link

ewen-lbh commented Apr 30, 2020

I tried with poetry --ansi and it worked for me. Seems like some stdout coloring library disables ANSI output when detecting PowerShell, and that --ansi forces it.

@naveen521kk
Copy link

Looks like using rich would solve this issue.

@myliyifei
Copy link

I can't display the ANSI color effect in Windows terminal either, I have to add the command line parameter --ansi every time I run it, can this option switch be added to the config without adding the parameter every time?

@ewen-lbh
Copy link

@myliyifei you could use an alias (sth. like alias poetry="poetry --ansi") as a workaround, but I don't know how to make aliases on windows though (or if it's even possible at all...)

@gaoming714
Copy link

gaoming714 commented Oct 4, 2020

@sztomi hi ,you can check the env, the poety need to get your "TERM"

echo $TERM

For TERM = cygwin , you need to add --ansi to focus color it.
For TERM = xterm, you are lucky.
I'm not clear the other values.

What is yours ?
here is my config.
powershell_to_msys2

@sztomi
Copy link
Contributor Author

sztomi commented Oct 4, 2020

@gaoming714 TERM is not set in native windows terminals, that's a unix thing.

@naveen521kk
Copy link

I found the problem here. Poetry uses cleo which in turn uses clikit which in turn uses pastel. Where pastel doesn't support colours on Windows. The alternative is to use colorama, for colour.

@TBBle
Copy link
Contributor

TBBle commented Jan 4, 2021

If it works with --ansi but not without, that's the same as #3354, and is a bug in clikit (sdispater/clikit#35).

As a workaround, you can set the ANSICON env-var to something non-empty to force ANSI support.

@myliyifei
Copy link

myliyifei commented Jan 7, 2021 via email

@dedale
Copy link

dedale commented Mar 17, 2021

@myliyifei you could use an alias (sth. like alias poetry="poetry --ansi") as a workaround, but I don't know how to make aliases on windows though (or if it's even possible at all...)

If you have a dir that comes first in your PATH (before poetry), you can add a poetry.cmd in it with:

@call %USERPROFILE%\.poetry\bin\poetry.bat %* --ansi

@Secrus
Copy link
Member

Secrus commented Jul 13, 2022

Could anyone verify if this is still an issue? cleo no longer uses clikit, so the issue might be resolved. I don't have a windows machine to test this.

@TBBle
Copy link
Contributor

TBBle commented Jul 13, 2022

poetry --version with the latest Poetry master still does not use ANSI under Windows Terminal, but does with --ansi or when the ANSICON environment has been set.

Although cleo no longer uses clikit, I recall looking into it last year, and the relevant code was just copied from clikit into cleo, and the relevant bug is now python-poetry/cleo#104.

image

@chenyulue
Copy link

@sztomi hi ,you can check the env, the poety need to get your "TERM"

echo $TERM

For TERM = cygwin , you need to add --ansi to focus color it. For TERM = xterm, you are lucky. I'm not clear the other values.

What is yours ? here is my config. powershell_to_msys2

Following your hint, I add an environment variable TERM and set it to xterm in windows, and then poetry command shows infomation with colors. No need poetry --ansi any more!

@starball5
Copy link

Related Stack Overflow question: Is there a way to activate colored output for Poetry in Windows Terminal?

@Yaekiou
Copy link

Yaekiou commented Mar 19, 2023

you could use an alias (sth. like alias poetry="poetry --ansi") as a workaround, but I don't know how to make aliases on windows though (or if it's even possible at all...)

input this in the terminal

$PROFILE
# will output path\to\profile.ps1

Open (create) the profile.ps1 in a text editor and then paste the following code into it

function ColorfulPoetry {
    & "poetry.exe" --ansi $args
}

Set-Alias poetry ColorfulPoetry

References:

&

Set-Alias

$args

Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/cli Related to the command line kind/bug Something isn't working as expected
Projects
None yet
Development

Successfully merging a pull request may close this issue.