Skip to content
This repository

OS X Lion Terminal.app line wrap problem #915

Closed
radeksz opened this Issue October 21, 2011 · 10 comments

3 participants

radeksz Bradley M. Froehle Min RK
radeksz

I have a problem with deadline on Mac OS X Lion, ipython 0.11, python 2.7.2. When wrapping the input line the line prompt isn't taken into account properly. It gets all messy when I press delete in the long line.

The amount of "error" per line is dependent on the length of the prompt. If I make the prompt one character longer, the first line is wrapped one character "later".

Example:

ipython --colors=NoColor
Python 2.7.2 (default, Aug 16 2011, 18:48:22) 
Type "copyright", "credits" or "license" for more information.

IPython 0.11 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: 012345678901234567890123456789012345678901234567890123456789012345678901
2345678
90123456789012345678901234567890123456789012345678901234567890123456789012345678
90123456789012345678901234567890123456789012345678901234567890123456789012345678
90123456789012345678901234567890123456789012345678901234567890123456789012345678
90123456789012345678901234567890123456789012345678901234567890123456789012345678
90123456789012345678901234567890123456789012345678901234567890123456789012345678

I have readline installed:

[Radek ~]$ fink list|grep readline
 i  readline5   5.0-1006    Comfortable terminal input library
 i  readline5-shlibs    5.0-1006    Comfortable terminal input library
Bradley M. Froehle
Collaborator

I don't have this issue using the homebrew version of python 2.7.2 (and readline 6.2.1).

Min RK
Owner

What Python does have this problem? If homebrew Python doesn't have it for you, and System Python doesn't appear to have it for me.

And how are you causing the problem - is it resizing the window, or just typing out a long line that it waits too long to wrap?

radeksz

Fink Python 2.7.2 (version 1:2.7.2-4) and Lion system python (Python 2.7.1 (r271:86832, Jun 16 2011, 16:59:05)) do not have this problem, only ipython (fink installation ipython-py27, 0.11-3).

It's typing a long line that causes this "late" wrap, no resizing of the window needed. Colors of the prompt have no influence on the wrap.

Min RK
Owner

Interesting. Can you run a standard dist or git master of IPython with your System or Fink Pythons? You can use python ipython.py from the source dir to launch IPython without installing it.

Another thing you might test is launching without readline:

$> ipython --InteractiveShell.readline_use=False

I don't think IPython configures anything about line wrapping, but I'm definitely not sure about that.

radeksz

I did run ipython from git (0.12dev) and the problem persists (as of 23 October 2011) when ipython is run with fink python 2.7.2.

When I manually disable readline in 0.12dev with --InteractiveShell.readline_use=False, ipython crashes:

[Radek ipython]$ /sw/bin/python ipython.py --InteractiveShell.readline_use=False # fink python
ipython/IPython/frontend/terminal/interactiveshell.pyc in interact(self=<IPython.frontend.terminal.interactiveshell.TerminalInteractiveShell object>, display_banner=False)


    257         more = False
--> 258         hlen_before_cell = self.readline.get_current_history_length()
    259 

AttributeError: 'NoneType' object has no attribute 'get_current_history_length'

After "fixing" the crash (changing the offending line to hlen_before_cell = 0) the input lines keep being wrapped incorrectly.

Problem disappears for system (Lion) python 2.7.1, but with some readline warnings.

[Radek ipython]$ /usr/bin/python ipython.py # Lion python
IPython/utils/rlineimpl.py:96: RuntimeWarning: Leopard libedit detected - readli
ne will not be well behaved including some crashes on tab completion, and incorr
ect history navigation. It is highly recommended that you install readline, whic
h is easy_installable with: 'easy_install readline'
  RuntimeWarning)
Python 2.7.1 (r271:86832, Jun 16 2011, 16:59:05) 
Type "copyright", "credits" or "license" for more information.

IPython 0.12.dev -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Min RK
Owner

Sorry, that readline crash is due to a small omission in a recent PR, fix is forthcoming.

Frankly, it sounds like a bug in Fink Python. What happens if you just do:

raw_input('long prompt > ')

from Fink Python, and then enter more than a line?

radeksz

The raw_input function works in (fink) python correctly.

[Radek ipython]$ /sw/bin/python ipython.py # fink python, 23 Oct 2011 ipython 0.12dev
 Python 2.7.2 (default, Aug 16 2011, 18:48:22) 
Type "copyright", "credits" or "license" for more information.

IPython 0.12.dev -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

In [2]: raw_input('long prompt > ')
long prompt > xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
radeksz

I think I identified the problem, it's the \n in the prompt that causes incorrect line wrap. It appears to have nothing with ipython, as it surfaces with raw_input:

[Radek ipython]$ /sw/bin/python
Python 2.7.2 (default, Aug 16 2011, 18:48:22) 
[GCC 4.2.1 Compatible Apple Clang 2.1 (tags/Apple/clang-163.7.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> raw_input('prompt>')
prompt>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

>>> raw_input('\nprompt>')

prompt>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

My temporary fix includes changing ipython_config.py:

c.TerminalInteractiveShell.separate_in = '' # was '\n'

The problem doesn't occur on system (Lion) python. I guess I should file a bug report for readline (fink version 5.0-1006)?

radeksz

Indeed it is the readline library that causes problems.

http://sourceforge.net/mailarchive/message.php?msg_id=28278097

radeksz radeksz closed this October 25, 2011
Min RK
Owner

Thanks for narrowing it down! Perhaps you can install the python-readline package, which links against current gnu readline:

easy_install readline

If you do that --user, or on your PYTHONPATH, it should be used instead of the default readline.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.