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

Check for 'closed' attribute on 'wrapped' in AnsiToWin32 #84

Closed
wants to merge 1 commit into from

Conversation

blueyed
Copy link

@blueyed blueyed commented Jan 22, 2016

Otherwise colorama might cause crashes when used in Vim (davidhalter/jedi-vim#522 (comment)) or Neovim (davidhalter/jedi-vim#522 (comment)).

@blueyed blueyed force-pushed the hasattr-wrapped-closed branch from 8136165 to b29cb92 Compare January 22, 2016 22:16
self.strip = strip

# should we should convert ANSI sequences into win32 calls?
if convert is None:
convert = conversion_supported and not wrapped.closed and is_a_tty(wrapped)
convert = (conversion_supported and
Copy link
Author

Choose a reason for hiding this comment

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

Not sure if and here is right, compared to the or above?!

Copy link
Collaborator

Choose a reason for hiding this comment

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

The and and or are ok.

  • We want to strip the ANSI codes in two separate cases: either we're using a Windows cmd-like terminal (conversion_supported, ANSI codes are not supported) OR we're not using a tty at all (e.g. output redirection)
  • To convert the ANSI codes to Windows API we require two conditions: use a cmd-like terminal AND use a tty (no redirection).

@wiggin15
Copy link
Collaborator

This looks good to me, but I fear that the two lines for 'convert' and 'strip' are becoming too long and compilcated (I also prefer not to have a line break after (, which was added because the lines are becoming long...). Perhaps it would be a good idea to separate the wrapped.closed check to a new function, say is_stream_closed(stream) which would check both hasattr and the attribute, and then use this function in the two changed lines?

@blueyed
Copy link
Author

blueyed commented Jan 23, 2016

is_stream_closed

Thought about that initially, but then it was clearer that way somehow (inline).

I've wondered even if for such a stream it should not be true (given that it's something not connected to a term)?!

self.strip = strip

# should we should convert ANSI sequences into win32 calls?
if convert is None:
convert = conversion_supported and not wrapped.closed and is_a_tty(wrapped)
convert = (conversion_supported and
hasattr(wrapped, 'closed') and not
Copy link
Owner

Choose a reason for hiding this comment

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

Personally, I'd put the 'not' on the next line - it does apply to the 'wrapped.closed'. Ditto the 'not' at the end of line 68.

@blueyed
Copy link
Author

blueyed commented Jan 24, 2016

I'd be OK with everything, and also if you cherry-pick and amend it.

Please note that this caused and still causes a lot of bug reports for jedi-vim, which uses colorama internally, and therefore it would be nice to get this fixed soon.

wiggin15 pushed a commit to wiggin15/colorama that referenced this pull request Feb 7, 2016
@wiggin15
Copy link
Collaborator

wiggin15 commented Feb 7, 2016

Hi @blueyed . I created a similar patch here:
https://github.com/wiggin15/colorama/tree/issue84
Can you please test this branch and let me know it if works for you?

wiggin15 pushed a commit to wiggin15/colorama that referenced this pull request Feb 8, 2016
@blueyed
Copy link
Author

blueyed commented Feb 10, 2016

Given the test it should work.
I could test it tomorrow, if you really want that. Otherwise the you should also be able to reproduce it in Vim yourself.

@wiggin15 wiggin15 closed this in 1244a00 Feb 11, 2016
@OddBloke
Copy link

OddBloke commented Mar 7, 2016

This bug is in the version of colorama that is currently due to be shipped in Ubuntu 16.04. It'd be great if a new release could be cut so we didn't have to maintain a diff from upstream for the next 5 years. :)

@OddBloke
Copy link

OddBloke commented Mar 7, 2016

(The bug tracking this problem in Ubuntu is https://bugs.launchpad.net/ubuntu/+source/python-colorama/+bug/1554129, for reference)

@wiggin15
Copy link
Collaborator

wiggin15 commented Mar 8, 2016

Done. Thanks.

@OddBloke
Copy link

OddBloke commented Mar 9, 2016

This has been uploaded to Debian and sync'd to Ubuntu, so it will be in 16.04. Thanks!

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 this pull request may close these issues.

4 participants