prompt-toolkit / python-prompt-toolkit

Library for building powerful interactive command line applications in Python
https://python-prompt-toolkit.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
9.1k stars 717 forks source link

v0.26 bugs in Windows #86

Open darikg opened 9 years ago

darikg commented 9 years ago

In python 2.7: Need to press meta+enter to execute a line even when multiline mode is off

In python 3.3: Fails with traceback:

raceback (most recent call last):
  File "C:\Users\dg\Anaconda3\envs\ppt3\Scripts\ptpython-script.py", line 9, in <module>
    load_entry_point('prompt-toolkit==0.25', 'console_scripts', 'ptpython')()
  File "c:\users\dg\documents\python\python-prompt-toolkit\prompt_toolkit\contrib\entry_points\ptpython.py", line 77, in run

    startup_paths=startup_paths, always_multiline=always_multiline)
  File "c:\users\dg\documents\python\python-prompt-toolkit\prompt_toolkit\contrib\repl.py", line 189, in embed
    cli.start_repl(startup_paths=startup_paths)
  File "c:\users\dg\documents\python\python-prompt-toolkit\prompt_toolkit\contrib\repl.py", line 48, in start_repl
    on_exit=AbortAction.RAISE_EXCEPTION)
  File "c:\users\dg\documents\python\python-prompt-toolkit\prompt_toolkit\__init__.py", line 251, in read_input
    next(g)
  File "c:\users\dg\documents\python\python-prompt-toolkit\prompt_toolkit\__init__.py", line 301, in _read_input
    self._redraw()
  File "c:\users\dg\documents\python\python-prompt-toolkit\prompt_toolkit\__init__.py", line 191, in _redraw
    self.renderer.render(self)
  File "c:\users\dg\documents\python\python-prompt-toolkit\prompt_toolkit\renderer.py", line 465, in render
    style=self._style, grayed=cli.is_aborting,
  File "c:\users\dg\documents\python\python-prompt-toolkit\prompt_toolkit\renderer.py", line 345, in output_screen_diff
    current_pos = move_cursor(screen.get_cursor_position())
  File "c:\users\dg\documents\python\python-prompt-toolkit\prompt_toolkit\renderer.py", line 232, in move_cursor
    output.cursor_up(current_y - new.y)
  File "c:\users\dg\documents\python\python-prompt-toolkit\prompt_toolkit\terminal\win32_output.py", line 166, in cursor_up
    sr = self._screen_buffer_info().dwCursorPosition
AttributeError: 'NoneType' object has no attribute 'dwCursorPosition'
jonathanslenders commented 9 years ago

Thanks for reporting! I have no immediate idea what's going on, but I'll have a look at this as soon as possible.

jonathanslenders commented 9 years ago

Hi, I was just trying on Windows, but with Python 3.4 I can't reproduce it. It seems that the windll.kernel32.GetConsoleScreenBufferInfo API call fails.

darikg commented 9 years ago

If it helps, I can confirm there's two different issues with python 3.3 and 3.4. In 3.3 I get the error message I listed above, and in 3.4, I get simply "failed to create process." printed to console.

darikg commented 9 years ago

Oddly enough, even though ptpython fails in 3.3, ptipython works (Although it still needs control-enter to execute a line). With 3.4, both ptpython and ptipython print 'failed to create process'

darikg commented 9 years ago

If you want to hear something completely bananas, ptpython in python 3.3 works if you set prompt_toolkit.terminal.win32_input._DEBUG_RENDER_OUTPUT to True

darikg commented 9 years ago

Mapping \x0d to Keys.ControlJ instead of ControlM fixes the new line issue

jonathanslenders commented 9 years ago

Okay, that sounds like there are a couple of bugs. Thanks for keeping me up to date. I haven't been able to fix anything lately, but I hope to restart prompt-toolkit development very soon again.

darikg commented 9 years ago

Totally wasn't my intention to try to rush you or anything!! I'm just having fun poking around blindly and keeping notes here

jonathanslenders commented 8 years ago

Hi @darikg,

Can we close this issue? Windows development progressed a lot, but I'm not sure whether this still happens or not.

darikg commented 8 years ago

Yeah close it!

On Wed, Jul 15, 2015 at 7:24 AM, Jonathan Slenders <notifications@github.com

wrote:

Hi @darikg https://github.com/darikg,

Can we close this issue? Windows development progressed a lot, but I'm not sure whether this still happens or not.

— Reply to this email directly or view it on GitHub https://github.com/jonathanslenders/python-prompt-toolkit/issues/86#issuecomment-121586028 .

itsnotvalid commented 8 years ago

Same bug for win64 (windows 8.1) python2.7 prompt_toolkit-0.45 when using mycli-1.2.

Traceback (most recent call last):
  File "C:\Python27\Scripts\mycli-script.py", line 9, in <module>
    load_entry_point('mycli==1.2.0', 'console_scripts', 'mycli')()
  File "C:\Python27\lib\site-packages\click\core.py", line 664, in __call__
    return self.main(*args, **kwargs)
  File "C:\Python27\lib\site-packages\click\core.py", line 644, in main
    rv = self.invoke(ctx)
  File "C:\Python27\lib\site-packages\click\core.py", line 837, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "C:\Python27\lib\site-packages\click\core.py", line 464, in invoke
    return callback(*args, **kwargs)
  File "C:\Python27\lib\site-packages\mycli\main.py", line 550, in cli
    mycli.run_cli()
  File "C:\Python27\lib\site-packages\mycli\main.py", line 311, in run_cli
    document = cli.run()
  File "C:\Python27\lib\site-packages\prompt_toolkit\interface.py", line 272, in
 run
    self._redraw()
  File "C:\Python27\lib\site-packages\prompt_toolkit\interface.py", line 244, in
 _redraw
    is_done=self.is_done)
  File "C:\Python27\lib\site-packages\prompt_toolkit\renderer.py", line 339, in
render
    style=style,
  File "C:\Python27\lib\site-packages\prompt_toolkit\renderer.py", line 159, in
output_screen_diff
    current_pos = move_cursor(Point(y=y, x=c))
  File "C:\Python27\lib\site-packages\prompt_toolkit\renderer.py", line 76, in m
ove_cursor
    _output_cursor_forward(new.x)
  File "C:\Python27\lib\site-packages\prompt_toolkit\terminal\win32_output.py",
line 187, in cursor_forward
    sr = self._screen_buffer_info().dwCursorPosition
AttributeError: 'NoneType' object has no attribute 'dwCursorPosition'
jonathanslenders commented 8 years ago

@itsnotvalid Does this still happen? If so, is it reproducible, or just from time to time? Can you tell me which version of Windows you have and which Python version (also 64 or 32bit)?

kdahlhaus commented 8 years ago

Yes - still happens on Windows 7 Pro 64 bit, Python 2.7.10 32 bit, when doing a 'pip install ptpython'

10 ~/prog/ptpython: pip freeze Pygments==2.0.2 docopt==0.6.2 jedi==0.9.0 prompt-toolkit==0.52 ptpython==0.24 six==1.10.0 wcwidth==0.1.5

9 ~/prog/ptpython: ptpython Traceback (most recent call last): File "C:\Python27\Lib\runpy.py", line 162, in _run_module_as_main "main", fname, loader, pkg_name) File "C:\Python27\Lib\runpy.py", line 72, in _run_code exec code in run_globals File "C:\Users\KDahlhausen\prog\ptpython\env\Scripts\ptpython.exemain.py", line 9, in File "C:\Users\KDahlhausen\prog\ptpython\env\lib\site-packages\ptpython\entry_points\run_ptpython.py", line 70, in run title='Python REPL (ptpython)') File "C:\Users\KDahlhausen\prog\ptpython\env\lib\site-packages\ptpython\repl.py", line 292, in embed cli = CommandLineInterface(application=repl.create_application(), eventloop=eventloop) File "C:\Users\KDahlhausen\prog\ptpython\env\lib\site-packages\prompt_toolkit\interface.py", line 90, in init mouse_support=application.mouse_support) File "C:\Users\KDahlhausen\prog\ptpython\env\lib\site-packages\prompt_toolkit\renderer.py", line 230, in init self.reset(_scroll=True) File "C:\Users\KDahlhausen\prog\ptpython\env\lib\site-packages\prompt_toolkit\renderer.py", line 259, in reset self.output.scroll_buffer_to_prompt() File "C:\Users\KDahlhausen\prog\ptpython\env\lib\site-packages\prompt_toolkit\terminal\win32_output.py", line 237, in scroll_buffer_to_prompt sr = info.srWindow AttributeError: 'NoneType' object has no attribute 'srWindow'

bzm3r commented 8 years ago

I get the error with the simplest example:

from __future__ import unicode_literals
from prompt_toolkit import prompt

if __name__ == '__main__':
    answer = prompt('Give me some input: ')
    print('You said: %s' % answer)

On Windows 10, 64bit, with the latest Anaconda (Python 2.7) installed (I installed python-prompt-toolkit through the anaconda.org repository link). (I don't mind switching to Python 3.5 though :+1: )

lebe-dev commented 8 years ago

Windows 10 64bit Python 3.4.3 x86

jonathanslenders commented 7 years ago

Hi everyone, a lot of improvements regarding Windows were done in the last couple of months. Now that IPython uses prompt_toolkit, many smaller bugs have been fixed as well.

I think the windows issues in this ticket are all solved. Please let me know if this is not the case.

thisgf commented 7 years ago

Get Screen Buffer Error: handler:152 GetLastError():6

thisgf commented 7 years ago

I have get NoConsoleScreenBuffer exception too, and i print the windll.kernel32.GetLastError() result get 6 return code. this meat "invalid windows handler"

jonathanslenders commented 7 years ago

I have a possible fix: jonathanslenders/python-prompt-toolkit@d5d9e29

Can you please upgrade to the latest prompt_toolkit master, and see whether it works? So far, I really still don't understand what's going on. It seems to happen on 64bit builds of Python only.

Also see: https://github.com/ipython/ipython/issues/10070