Skip to content

Formatting fails when value-to-print is very large #607

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
BenWiederhake opened this issue Apr 11, 2016 · 8 comments
Closed

Formatting fails when value-to-print is very large #607

BenWiederhake opened this issue Apr 11, 2016 · 8 comments

Comments

@BenWiederhake
Copy link

Reproduce with:

  • Start bpython (happens in both bpython version 0.15 on top of Python 3.5.1+ /usr/bin/python3 and bpython version 0.15 on top of Python 2.7.11+ /usr/bin/python)
  • Do something that has at least two screenfuls of output when printed. Example: ["Hello"] * 1000

Expected result: boring stuff. Just the printed "value" of a list that contains a thousand "hello"s.

Actual result: The value, and then some formatting related characters that got garbled:

>>> ["Hello"] * 1000
['Hello', 'Hello', 'Hello', 'Hello', 'Hello', 'Hello', 'Hello', 'Hello', 'Hello', 'Hello', 'Hello', 'Hello', 'Hello', 'Hello',
 'Hello', 'Hello', 'Hello', 'Hello', 'Hello', 'Hello', 'Hello', 'Hello', 'Hello', 'Hello', 'Hello', 'Hello', 'Hello', 'Hello',
[... SNIP ...]
 'Hello', 'Hello', 'Hello', 'Hello', 'Hello', 'Hello', 'Hello', 'Hello', 'Hello', 'Hello', 'Hello', 'Hello', 'Hello', 'Hello',
 'Hello', 'Hello', 'Hello', 'Hello', 'Hello', 'Hello']�[-26;1H
>>>

Note the trailing U+001B which smells like formatting gone wrong.

I'm not sure whether this is a bug in xfce4-terminal 0.6.3, bpython, bpython-curtsies, curtsies, or maybe something else entirely. However, bpython is the only program exhibiting this behavior, so I reported it here.

@thomasballinger
Copy link
Member

I bet this is some nonstandard terminal formatting that curtsies is doing. I can't reproduce at the moment, but will try soon with xfce.

@thomasballinger
Copy link
Member

/me still hasn't tried with xfce

I'm guessing something's happening to the math in Curtsies such that the "Cursor Home" command that moves the cursor <ESC>[{ROW};{COLUMN}H came out with a negative row here. I checked and Blessings passes through negative numbers to its Terminal.move command, so this is possible.

So probably one of the numbers in cursor_pos[0] - offscreen_scrolls + self.top_usable_row is bad, but I don't know which. I don't have a Linux machine around at the moment to check.

@thomasballinger
Copy link
Member

thomasballinger commented Jun 7, 2016

It turns out this is happening in my terminal too, but iTerm2 swallows the invalid sequence! It's likely a Curtsies issue, these sequence may not be doing anything important, I'll look into it more.

@thomasballinger
Copy link
Member

I noticed in a gif I uploaded for another reason that the cursor disappears sometimes, and I think this may be related based on the Curtsies source: the sequence to make the cursor visible is written just after this sequence that is sometimes negative.
asciicast

@thomasballinger
Copy link
Member

I suspect this is the problem but haven't nicely reproduced it. @BenWiederhake if it's not much trouble would you try pip install git+https://github.com/thomasballinger/curtsies.git@fix-bpython-607 to see if it fixes the problem?

@BenWiederhake
Copy link
Author

Appears to work, thanks :D

(For fun I pip uninstalled this version of curtsies again, as a sanity check of sorts, and indeed: with the old system version, it still shows the faulty behavior, so your fix definitely works.)

@thomasballinger
Copy link
Member

Great, I've merged that and will do a Curtsies release before long, so at least fresh installations of Curtsies will have it fixed. I'll leave this open until I've done that Curtsies release.

@sebastinas
Copy link
Contributor

A new version of curtsies has been released in the meantime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants