\r and \b in qtconsole don't behave as expected #629

Closed
eteq opened this Issue Jul 28, 2011 · 5 comments

Comments

Projects
None yet
4 participants
@eteq
Contributor

eteq commented Jul 28, 2011

In a normal terminal, the "\r" and "\b" control characters should move to the beginning of the line and back one character, respectively.

However, in qtconsole, writing '\b' to stdout (or "print '\b'") seems to do nothing at all, and '\r' behaves like '\n'. Is there any way to get around this and return them to the expected behavior?

This is useful for things like download notifiers that shouldn't print a new line to update the percentage downloaded or something like that - I'm not seeing the terminal just fill up with garbage instead of a dynamically updating download notification.

@epatters

This comment has been minimized.

Show comment
Hide comment
@epatters

epatters Jul 28, 2011

Contributor

I'm afraid you may have re-adjust your expectations somewhat: the qtconsole is not a "normal terminal". In particular, it does not currently support any ANSI sequences for (non-forward) cursor movement, and this includes the '\r' and '\b' characters.

I have tried to emulate a real terminal when practical, but robust support for arbitrary cursor movement is a pretty serious effort. I may find some time to work on this, but don't hold your breath.

That said, you are welcome to dig into the code. Feel free to ask for guidance if you are so inclined.

Contributor

epatters commented Jul 28, 2011

I'm afraid you may have re-adjust your expectations somewhat: the qtconsole is not a "normal terminal". In particular, it does not currently support any ANSI sequences for (non-forward) cursor movement, and this includes the '\r' and '\b' characters.

I have tried to emulate a real terminal when practical, but robust support for arbitrary cursor movement is a pretty serious effort. I may find some time to work on this, but don't hold your breath.

That said, you are welcome to dig into the code. Feel free to ask for guidance if you are so inclined.

@eteq

This comment has been minimized.

Show comment
Hide comment
@eteq

eteq Jul 28, 2011

Contributor

Fair enough - if I find time to dig into this, I'll re-post here. Thanks for the info!

Contributor

eteq commented Jul 28, 2011

Fair enough - if I find time to dig into this, I'll re-post here. Thanks for the info!

@fperez

This comment has been minimized.

Show comment
Hide comment
@fperez

fperez Jul 29, 2011

Member

I marked it as low priority/enhancement because as Evan said, the Qt console behaves like a console when feasible, but is not an ANSI terminal emulator. Having said that, it would be very cool to have proper support of non-forward cursor movement, so @eteq, if you manage to have a go at this, we'd be delighted to incorporate the improvements.

Member

fperez commented Jul 29, 2011

I marked it as low priority/enhancement because as Evan said, the Qt console behaves like a console when feasible, but is not an ANSI terminal emulator. Having said that, it would be very cool to have proper support of non-forward cursor movement, so @eteq, if you manage to have a go at this, we'd be delighted to incorporate the improvements.

@v3ss0n

This comment has been minimized.

Show comment
Hide comment
@v3ss0n

v3ss0n Oct 16, 2011

I believe there are terminal emulator libs already in python. I had tried one before , do not remember its name. It have support for all escape characters.

v3ss0n commented Oct 16, 2011

I believe there are terminal emulator libs already in python. I had tried one before , do not remember its name. It have support for all escape characters.

@fperez

This comment has been minimized.

Show comment
Hide comment
@fperez

fperez Oct 16, 2011

Member

The point is that by necessity, the qt console is not a terminal emulator: it's a widget that feels in many ways like a console, but it has inline graphics, rich html support, and many features that simply break the assumptions of a pure terminal emulator. A terminal emulator is a very constrained device that matches the assumptions of old-style vt-100 type environments, with a character model for addressing the 2-d space with an equispaced grid of rows and columns. Our qt console is a real GUI app with pixel-level addressing, proportional fonts, graphics, etc. That gives it much of its power, but also imposes some limitations in that we can't simply blindly reuse terminal emulator code that wants to address an 80x25 grid of fixed-width characters.

Member

fperez commented Oct 16, 2011

The point is that by necessity, the qt console is not a terminal emulator: it's a widget that feels in many ways like a console, but it has inline graphics, rich html support, and many features that simply break the assumptions of a pure terminal emulator. A terminal emulator is a very constrained device that matches the assumptions of old-style vt-100 type environments, with a character model for addressing the 2-d space with an equispaced grid of rows and columns. Our qt console is a real GUI app with pixel-level addressing, proportional fonts, graphics, etc. That gives it much of its power, but also imposes some limitations in that we can't simply blindly reuse terminal emulator code that wants to address an 80x25 grid of fixed-width characters.

@fperez fperez closed this in 21c436b Dec 7, 2011

jdmarch pushed a commit that referenced this issue May 30, 2012

Jonathan March Jonathan March
Merge pull request #1787 from punchagan/minor-doc-fix
DOC: This removes, from the qt-console docs, an obsolete warning that \r and \b are not supported. This issue was fixed by #629 and #1561.

mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this issue Nov 3, 2014

mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this issue Nov 3, 2014

Merge pull request #1089 from mdboom/qtconsole-carriage-return
Support carriage return ('\r') and beep ('\b') characters in the qtconsole, providing text-mode 'scroll bars' and terminal bell in the console.

It extends AnsiCodeProcessor to understand the '\r' character and move the cursor back to the start of the line. It also understands the '\b' character and calls QTApplication::beep(). Neither are strictly speaking ANSI code sequences, of course, but they seem related enough and was simple enough to do it this way.

Closes #629.

mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this issue Nov 3, 2014

DOC: Remove regression from qt-console docs.
Issue #629 is closed.  Remove related note from docs.

mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this issue Nov 3, 2014

Jonathan March Jonathan March
Merge pull request #1787 from punchagan/minor-doc-fix
DOC: This removes, from the qt-console docs, an obsolete warning that \r and \b are not supported. This issue was fixed by #629 and #1561.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment