nghung270192 / colorama

Automatically exported from code.google.com/p/colorama
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Colorama broken in 3.3.3.0 #47

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Simply importing colorama in Python 3.3.3.0 will cause an error.

Operating System: Windows 7 x64
Python Distribution: WinPython x64
Python Version: 3.3.3.0

Readline internal error
Traceback (most recent call last):
  File "C:\WinPython-64bit-3.3.3.0\python-3.3.3.amd64\lib\site-packages\pyreadline\console\console.py", line 768, in hook_wrapper_23
    res = ensure_str(readline_hook(prompt))
  File "C:\WinPython-64bit-3.3.3.0\python-3.3.3.amd64\lib\site-packages\pyreadline\rlmain.py", line 569, in readline
    self.readline_setup(prompt)
  File "C:\WinPython-64bit-3.3.3.0\python-3.3.3.amd64\lib\site-packages\pyreadline\rlmain.py", line 565, in readline_setup
    self._print_prompt()
  File "C:\WinPython-64bit-3.3.3.0\python-3.3.3.amd64\lib\site-packages\pyreadline\rlmain.py", line 466, in _print_prompt
    x, y = c.pos()
  File "C:\WinPython-64bit-3.3.3.0\python-3.3.3.amd64\lib\site-packages\pyreadline\console\console.py", line 261, in pos
    self.GetConsoleScreenBufferInfo(self.hout, byref(info))
ctypes.ArgumentError: argument 2: <class 'TypeError'>: expected 
LP_CONSOLE_SCREEN_BUFFER_INFO instance instead of pointer to 
CONSOLE_SCREEN_BUFFER_INFO

Original issue reported on code.google.com by Con...@gmail.com on 23 Dec 2013 at 11:42

GoogleCodeExporter commented 9 years ago
Hi and thanks for your useful work on colorama.

I got the same problem with several 32 bits XP and 7 machines, with colorama 2.7

The problem seems related to pyreadline and the fact that it also uses ctypes 
and GetConsoleScreenBufferInfo (and other functions of that dll) with other 
signatures declared to ctypes [1].

I could get my terminal functional again by matching the signatures with the 
ones in pyreadline/console/console.py. I attached the modified win32.py file.

I do not know what is the right way of using those dll functions, but as 
pyreadline is more common I adapted colorama to it and not the contrary. It 
would be great if pyreadline and colorama could get along nicely...

Best regards,

LF

[1] https://github.com/astropy/astropy/issues/1440

Original comment by l.fayo...@ymail.com on 9 Jan 2014 at 5:39

Attachments:

GoogleCodeExporter commented 9 years ago
Massive thanks for reporting all this, both the problem and your solution.

I'll have a look at the diffs, see if I can understand what's going on, 
consider merging and releasing. Currently failing to find the time, but maybe 
this weekend.

Original comment by tart...@gmail.com on 10 Jan 2014 at 12:55

GoogleCodeExporter commented 9 years ago

Original comment by tart...@gmail.com on 10 Jan 2014 at 12:55

GoogleCodeExporter commented 9 years ago
Issue 48 has been merged into this issue.

Original comment by tart...@gmail.com on 13 Jan 2014 at 11:06

GoogleCodeExporter commented 9 years ago
Googling for LP_CONSOLE_SCREEN_BUFFER_INFO type mismatch error located this 
thread and LF's patch, which successfully resolves the issue for me.  Thanks!

Original comment by ice.r...@gmail.com on 17 Mar 2014 at 10:19

GoogleCodeExporter commented 9 years ago
Isolate the win32 module from the global ctypes.windll instance. Use windll = 
ctypes.LibraryLoader(ctypes.WinDLL). The module will get its own instance of 
WinDLL('kernel32'), which will have its own cached function pointers. 

Original comment by eryksun on 29 Mar 2014 at 12:51

GoogleCodeExporter commented 9 years ago
Issue 51 has been merged into this issue.

Original comment by tart...@gmail.com on 17 Apr 2014 at 9:14

GoogleCodeExporter commented 9 years ago
Many thanks all. After much thought and sucking of teeth, I've committed the 
solution suggested relatively recently by eryksun, since that seems likely to 
prevent incompatibilities with other libraries as well as the known problem 
with pyreadline.

Original comment by tart...@gmail.com on 17 Apr 2014 at 9:43