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

Support possibility to wrap either stdout or stderr #257

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

barabanus
Copy link

@barabanus barabanus commented Apr 7, 2020

It's common to use stdout to generate binary files and stderr to print log and errors. At the same time colorama provides very convenient functionality to strip color codes from streams when output is redirected. The problem is that colorama wraps both stdout and stderr which strips binary symbols from stdout when binary files are generated.

It would be very useful for colorama library to wrap separately stderr / stdout on demand during initialization. I suggest to reuse 'wrap' argument to colorama.init() like this:

colorama.init()
colorama.init(wrap=False)
colorama.init(wrap="stdout")
colorama.init(wrap="stderr")

This pull request is linked to issue #256

@tartley
Copy link
Owner

tartley commented Oct 13, 2020

Hey. FYI, Yesterday I created a PR to test releases before we push them to PyPI. When that is merged, I'll be more confident about resuming merges and releases. I'll try to look at this PR soon. Thank you for creating it!

@septatrix
Copy link

septatrix commented Sep 5, 2021

I think I would prefer passing the streams directly instead of as strings such that the signature would be init(..., wrap: bool | TextIO) -> None instead.

@barabanus
Copy link
Author

I think I would prefer passing the streams directly instead of as strings such that the signature would be init(..., wrap: bool | TextIO) -> None instead.

The only valid values for the stream argument would be either sys.stdout or sys.stderr, so I don't see any benefits to use stream vs string.

if sys.stdout is None:
wrapped_stdout = None
else:
elif wrap != "stderr":
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgive my very overdue drive-by review, but does this do the wrong thing if wrap==False ?

if sys.stderr is None:
wrapped_stderr = None
else:
elif wrap != "stdout":
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

@tartley
Copy link
Owner

tartley commented Oct 7, 2021

Also: This PR changes the code and behavior, but does not include corresponding test changes, which it would need before it could be merged. (or how else would future contributors know when their changes break your code?)

(I thought I mentioned this last night, but don't see it now. Perhaps I messed up.)

@barabanus
Copy link
Author

Thanks for the comments, I'll review them on weekends

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

Successfully merging this pull request may close these issues.

None yet

3 participants