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

Use red text when printing errors on command line #511

Closed
brainwane opened this issue Oct 8, 2019 · 11 comments · Fixed by #649
Closed

Use red text when printing errors on command line #511

brainwane opened this issue Oct 8, 2019 · 11 comments · Fixed by #649

Comments

@brainwane
Copy link
Contributor

A suggested enhancement (from a new user at a sprint night): when twine emits error messages on the command line, print them in red.

@bhrutledge
Copy link
Contributor

bhrutledge commented Oct 10, 2019

I like this idea. Here are some random thoughts.

There was some discussion about caveats in #488 (comment).

Is it worth considering a holistic approach to styling twine's output? Or just keep it simple for now?

I found a couple packages that might help:

Could folks share examples of Python command-line tools with well-done colors?

@bhrutledge bhrutledge added enhancement question Discussion/decision needed from maintainers labels Oct 10, 2019
@pradyunsg
Copy link
Member

Could folks share examples of Python command-line tools with well-done colors?

pip 😉

https://github.com/pypa/pip/blob/e060970d51c5946beac8447eb95585d83019582d/src/pip/_internal/utils/logging.py#L174

Like, we have a decent setup for colors in logging-to-std-streams -- the other part of actually having output be "gracefully colored" is where pip struggles IMO. :)

packages that might help

I suggest using colorama -- it's a much more battle tested library as per my understanding.

@sigmavirus24
Copy link
Member

Isn't colorama problematic to install on Windows?

@pradyunsg
Copy link
Member

Isn't colorama problematic to install on Windows?

I don't think so. Windows is the target platform for the main functionality of the library, and it's a pure Python library. (pip vendors and uses it)

Take a look at colorama's PyPI page for more details: https://pypi.org/project/colorama/#description

@bhrutledge bhrutledge changed the title Enhancement suggestion: errors in CLI should be red Use red text when printing errors on command line Apr 16, 2020
@sigmavirus24
Copy link
Member

I’ve personally only tested it on Windows XP (CMD, Console2), Ubuntu (gnome-terminal, xterm), and OS X.

That doesn't inspire hope. That said, I think I had colorama confused with another project.

We'll also likely want to have a convenient way to determine when to disable colors, including when standard out/error is not a pty/tty. I suspect pip does this already

@bhrutledge
Copy link
Contributor

We'll also likely want to have a convenient way to determine when to disable colors, including when standard out/error is not a pty/tty.

I've been casually bookmarking packages for terminal text styling, and though I don't have a specific example, IIRC some of them have this built-in.

A few more:

@sigmavirus24
Copy link
Member

I would avoid crayons. It's most likely abandonware

@pradyunsg
Copy link
Member

pradyunsg commented May 11, 2020

That doesn't inspire hope

Just because it's old doesn't means it's broken. As far as I know, it works pretty well even on Windows 10 systems, and Windows has a reputation related to backward compatibility. ;)

If you're interested in looking at how pip does color handling and all that, the relevant code is pip._internal.utils.logging:ColorizedStreamHandler. Our logging setup colors warnings (yellow) and errors (red) as well as allowing us to dump debug logs to a file, while printing to the std* streams. Feel free to "permanently borrow" any of that code. :)

@pradyunsg
Copy link
Member

To be clear, colorama is actively maintained as well. There's been commits on the repo over past few weeks and given that it's pretty broadly used (ala pip), I don't expect twine to bump into any major issues if it switches to using it. :)

@di
Copy link
Member

di commented Jun 2, 2020

Seems like the decision here is to do this, and to use colorama to do it.

@bhrutledge bhrutledge removed the question Discussion/decision needed from maintainers label Jun 14, 2020
@bhrutledge bhrutledge linked a pull request Jun 18, 2020 that will close this issue
2 tasks
@bhrutledge
Copy link
Contributor

Closed via #649.

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

Successfully merging a pull request may close this issue.

5 participants