nghung270192 / colorama

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

colorama.init() breaks readline's history #57

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I am unable to use the history features of
readline when using colorama.

I made a small Windows command line tool that uses python's raw_input
to show a prompt to the user, which can then type a number of commands
and execute them. I use the readline module and its
read_history_file() and write_history_file() functions to make my tool
remember the command history across sessions.

The problem is that if I don't use colorama the previous history loads
fine and can be accessed by the user by using the up and down arrows,
but as soon as I call the colorama.init() the history does not work
anymore. In fact it seems to load a different history, which you can
use, but as soon as you close the windows console that "colorama"
history is lost.

I checked the functions exponsed by colorama and I found a couple of
things that looked promising. I saw that you can call init(wrap=False)
which seems that should restore the original stdin and stdout streams.
There is also a deinit() function that seems to do the same. However,
as soon as I try to use those I get the following traceback:

Readline internal error
Traceback (most recent call last):
  File "C:\Anaconda\lib\site-packages\pyreadline\console\console.py", line 768,
in hook_wrapper_23
    res = ensure_str(readline_hook(prompt))
  File "C:\Anaconda\lib\site-packages\pyreadline\rlmain.py", line 569, in readli
ne
    self.readline_setup(prompt)
  File "C:\Anaconda\lib\site-packages\pyreadline\rlmain.py", line 565, in readli
ne_setup
    self._print_prompt()
  File "C:\Anaconda\lib\site-packages\pyreadline\rlmain.py", line 466, in _print
_prompt
    x, y = c.pos()
  File "C:\Anaconda\lib\site-packages\pyreadline\console\console.py", line 261,
in pos
    self.GetConsoleScreenBufferInfo(self.hout, byref(info))
ArgumentError: argument 2: <type 'exceptions.TypeError'>: expected LP_CONSOLE_SC
REEN_BUFFER_INFO instance instead of pointer to CONSOLE_SCREEN_BUFFER_INFO
[9] <-
Readline internal error

So I cannot use this solution to fix my problem.

Is there something else that I could do? Maybe this is a Windows
specific problem?

Any help would be appreciated. Thanks!

Angel

Original issue reported on code.google.com by tart...@gmail.com on 10 Aug 2014 at 2:34