-
Notifications
You must be signed in to change notification settings - Fork 200
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
Add logic to handle ANSI escape sequences to move cursor #616
Conversation
Thanks for your work here @jsbautista ! As quick comment, adding a test for this new move cursor action logic could be worthy |
… into TQDMQtConsole
I appreciate the goal to add these ANSI codes to allow the cursor to move between lines. This limitation seems to be the main thing standing between qtconsole being a "true terminal emulator", that is compliant'ish with other terminals. Though, I see some issues with the changes in this MR. Your GIF seems to show output that is different that what the intended behavior should be. Here is what your I suggest the goal should be to get QtConsole to give output that matches these screenshots. "Segunda prueba" should be printed on the second line, as this string comes before the "\x1b[A" control character. Not "Segunda prueba" on the last line, as shown in your GIF. It also looks like this PR breaks |
Hi @TheMatt2 thank you for the feedback and giving this work a check! I think the current GIF being shown is a little bit out of date. The main goal of this PR is to give a handling similar to ANSI codes related with cursor movement as you would observe over IPython (but we could indeed give a check to the behavior of other terminals/platforms to contrast possible differences in behavior). So running the
def prueba():
print("\rPrimera prueba", end="")
print("\n", end="")
print("\rSegunda prueba", end="")
print("\x1b[A", end="")
print("\n\n", end="")
print("\rReemplazo", end="")
print() Still, we have some edge cases that need handling and also, as you mention, the changes here are causing some tests as the carriage return one to fail but we are giving all that a check. Hopefully this makes current state of this PR/work clearer but let us know if you have further suggestions/comments/ideas! |
Thank you for your response and clarification. Now I'm with you. |
Co-authored-by: Daniel Althviz Moré <16781833+dalthviz@users.noreply.github.com>
Checking aroung some issue related with Rich, using the changes here alone are not enough to see the improvements done. For more details you can check spyder-ide/spyder-kernels#494 (comment) (where using the Rich Console API is needed - |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @jsbautista for your work here! Left a question and a suggestion. Other than that seems like there is not much else to do here, although maybe could be worthy to do some extra manually testing with things like Rich and TQDM (I already did some while checking spyder-ide/spyder-kernels#494)
Co-authored-by: Daniel Althviz Moré <16781833+dalthviz@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @jsbautista for your work on this! Just some small style suggestions and a comment for you.
Co-authored-by: Carlos Cordoba <ccordoba12@gmail.com>
… into TQDMQtConsole
Co-authored-by: Daniel Althviz Moré <16781833+dalthviz@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @jsbautista for all your work here! This LGTM 👍
Just in case, do you have any further comments @ccordoba12 ? Also, in case this is ready to be merged, should the millestone be set to be 5.7.0
maybe (since this adds new functionality)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me now, thanks @jsbautista and @dalthviz for this great improvement!
I think this is closer to be a bug fix than new functionality because it doesn't add new config options, features or shortcuts. As you can see in our changelog, we release a new minor version when there are additions like those to the package, or when dropping Python versions or changing dependencies. |
Also, since this basically fixes spyder-ide/spyder#6172, a PR in Spyder should be created to sync our Qtconsole subrepo there with these changes. |
I made changes to the way the ANSI code \n is handled. Previously, whenever the \n code appeared, a new line was inserted unconditionally. After the change, a new line is inserted unless there is already a written line at the current position. In that case, instead of inserting a new line, the cursor moves one line down.
Preview with changes made:
Comparison of the result obtained with the changes made and in Ipython with QTDM
Preview with changes made:
Preview with IPython:
Fixes: #350
Related with: spyder-ide/spyder-kernels#494 spyder-ide/spyder#6172