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

[REQUEST] Forcing ANSI #890

Closed
naveen521kk opened this issue Jan 7, 2021 · 17 comments
Closed

[REQUEST] Forcing ANSI #890

naveen521kk opened this issue Jan 7, 2021 · 17 comments

Comments

@naveen521kk
Copy link

Have you checked the issues for a similar suggestions? YES

I need an Environment variable which forces ANSI output whatever the system may be.
This is particularly useful in GitHub Actions, where it doesn't show any colored output, currently, but setting that a environment variable should print colors.
Is it currently possible to do now?

@willmcgugan
Copy link
Collaborator

You can construct the Console like this to generate ANSI regardless of environment:

console = Console(force_terminal=True, color_system="truecolor")

I think there is an env var that indicates if running on GH Actions, or maybe you can define one.

@naveen521kk
Copy link
Author

You can construct the Console like this to generate ANSI regardless of environment:

Looks like it doesn't work? I just tried it. The code was pretty much simple though

logger = logging.getLogger(__name__)
custom_theme = Theme(
    {
        "log.level": "magenta",
        "repr.number": "bold green blink",
        "log.message": "white on red",
        "logging.level.info": "green on white",
        "logging.level.notset":"red on white"
    },
)

console=Console(theme=custom_theme, force_terminal=True, color_system="truecolor")

logger.addHandler(
    RichHandler(
        show_time=False,
        show_path=False,
        console=console,
        rich_tracebacks=True
    )
)

I could see no coloured output in GHA or ANSI locally on Git Bash(#330), where if ANSI is printed it should be turned into colours.

@willmcgugan
Copy link
Collaborator

That does work. Try printing os.environ or running python -m rich.diagnose

@naveen521kk
Copy link
Author

Try printing os.environ or running python -m rich.diagnose

I haven't actually, made it based on an environment variable. That is a script is meant to be run in CI so I just forced it.
Just that poetry's ANSI forcing works. I have run python -m rich.diagnose here..
This is the place where the logger is present. I would be happy if you could help me :)

@willmcgugan
Copy link
Collaborator

Ah, you're on Windows. Try also setting legacy_windows=False. You might also want to set width to say 120 or so.

@naveen521kk
Copy link
Author

Ah, you're on Windows.

I am sorry I didn't say this beforehand.

Try also setting legacy_windows=False. You might also want to set width to say 120 or so.

I did it naveen521kk/msys2-updater@bd834de but there isn't any colour there https://github.com/naveen521kk/msys2-updator/runs/1669125766?check_suite_focus=true#step:6:11

@willmcgugan
Copy link
Collaborator

Try logging console.options

@naveen521kk
Copy link
Author

See this

@willmcgugan
Copy link
Collaborator

I suspect that colorama may be stripping out ansi codes, even when legacy_windows is False. I'll look in to it.

@naveen521kk
Copy link
Author

Any updates?

@willmcgugan
Copy link
Collaborator

Can’t do much about this without reinventing colorama. I may revisit this issue in future.

@naveen521kk
Copy link
Author

Maybe I will make an issue on Colorama about this? Asking them to check for an environment variable?

@naveen521kk
Copy link
Author

looks like there is a PR upstream tartley/colorama#230

@naveen521kk
Copy link
Author

Update: I just did a regular dependency update and this seems to be fixed naveen521kk/msys2-updater@4a34e98.

https://github.com/naveen521kk/msys2-updator/runs/2739486117?check_suite_focus=true#step:10:284 (I was happy without those colours though)

@hellow554

This comment was marked as outdated.

@hellow554

This comment was marked as outdated.

@hellow554
Copy link

Sorry for the noise! I'm stupid! :) Instead of console.print(my_tree) I just did print(my_tree).... It works! I'm really sorry :)

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

No branches or pull requests

3 participants