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
Fix ANSI control sequences in Jupyter notebooks #193
Conversation
Hi @nschrader Thanks for your PR! |
Running tests manually (
You have to ensure that tests are working correctly and add a specific test cases for you fix. |
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.
Please address the above comments.
Thanks for your review, Pavel. Couldn't you simply "squash and merge" this PR on GitHub? So I don't need to force-push anything. I didn't see the test suite, thanks for the hint! Should be all good now, just needed to adjust for new EL sequence. |
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 👍
Just a minor item to clarify.
yaspin/core.py
Outdated
@@ -317,7 +307,8 @@ def write(self, text): | |||
# Ensure output is Unicode | |||
assert isinstance(_text, str) | |||
|
|||
sys.stdout.write("{0}\n".format(_text)) | |||
fill = max(0, len(self._text) - len(_text) + 2) | |||
sys.stdout.write("{0}{1}\n".format(_text, " " * fill)) |
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.
I'm not sure I understand this part. Why this extra filling 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.
LGTM
@nschrader once again, thanks for your contribution! I'll include this into the next yaspin release. |
@pavdmyt sorry for the mess, but I was testing again this morning and noticed some more problems which Jupyter. Turns out that I'd suggest that you revert this PR and I open a new one, so there is a clean trace. |
Second try of #193 and fixing #176 - Checking if stdout is a TTY to determine if output is a Jupyter cell or a terminal - Disabled ANSI control sequence DECTCEM for Jupyter (anyway there is no cursor) - Replaced ANSI control sequence EL for Jupyter (where it doesn't erase the line, but just prints three white spaces) with some code that simply overrides the entire line with white spaces - Added patching sys.stdout.isatty to pretend output is a terminal
I suggest this fix for #176.
^[K
is a special case of^[0K
)Other control sequences seem to work fine in Jupyter. Tests: