Show More
@@ -320,14 +320,36 b' class TerminalInteractiveShell(InteractiveShell):' | |||||
320 | pre_run=self.pre_prompt, reset_current_buffer=True) |
|
320 | pre_run=self.pre_prompt, reset_current_buffer=True) | |
321 | return document.text |
|
321 | return document.text | |
322 |
|
322 | |||
|
323 | def enable_win_unicode_console(self): | |||
|
324 | import win_unicode_console | |||
|
325 | ||||
|
326 | if PY3: | |||
|
327 | win_unicode_console.enable() | |||
|
328 | else: | |||
|
329 | # https://github.com/ipython/ipython/issues/9768 | |||
|
330 | from win_unicode_console.streams import (TextStreamWrapper, | |||
|
331 | stdout_text_transcoded, stderr_text_transcoded) | |||
|
332 | ||||
|
333 | class LenientStrStreamWrapper(TextStreamWrapper): | |||
|
334 | def write(self, s): | |||
|
335 | if isinstance(s, bytes): | |||
|
336 | s = s.decode(self.encoding, 'replace') | |||
|
337 | ||||
|
338 | self.base.write(s) | |||
|
339 | ||||
|
340 | stdout_text_str = LenientStrStreamWrapper(stdout_text_transcoded) | |||
|
341 | stderr_text_str = LenientStrStreamWrapper(stderr_text_transcoded) | |||
|
342 | ||||
|
343 | win_unicode_console.enable(stdout=stdout_text_str, | |||
|
344 | stderr=stderr_text_str) | |||
|
345 | ||||
323 | def init_io(self): |
|
346 | def init_io(self): | |
324 | if sys.platform not in {'win32', 'cli'}: |
|
347 | if sys.platform not in {'win32', 'cli'}: | |
325 | return |
|
348 | return | |
326 |
|
349 | |||
327 |
|
|
350 | self.enable_win_unicode_console() | |
328 | import colorama |
|
|||
329 |
|
351 | |||
330 | win_unicode_console.enable() |
|
352 | import colorama | |
331 | colorama.init() |
|
353 | colorama.init() | |
332 |
|
354 | |||
333 | # For some reason we make these wrappers around stdout/stderr. |
|
355 | # For some reason we make these wrappers around stdout/stderr. |
General Comments 0
You need to be logged in to leave comments.
Login now