manrajgrover / halo

💫 Beautiful spinners for terminal, IPython and Jupyter
MIT License
2.89k stars 147 forks source link

Bug: Escape sequences leaking on stdout, even using the sys.stderr stream #36

Closed mirukana closed 6 years ago

mirukana commented 6 years ago

Description

When using a spinner with stream=sys.stderr, the escape sequences to hide/show the terminal's cursor will still be outputed to stdout. They are visible if stdout is redirected to a file and opened in a text editor/cat -v, or directly piped to cat -v. This messes with the program's normal output in any case.

System settings

Steps to recreate

Run this script, piping its output to cat -v (e.g. python3 script | cat -v):

from halo import Halo
import sys
spinner = Halo(stream=sys.stderr)
spinner.start()
spinner.stop()
print("Testing")

People to notify

@ManrajGrover

manrajgrover commented 6 years ago

Hi @ccc032, thanks for reporting this. I believe this happens because of the dependency cursor being used where on line 37, it outputs escape sequences. One way of fixing this would be to remove dependency and move the code to this library and allow streams to be passed. Another way would be to send a PR and wait for the project owner to accept and publish the changes on pip. I would love to keep this code in a separate repository of it's own as it could benefit others in their projects.

manrajgrover commented 6 years ago

Updating things here, I've created an issue for this https://github.com/GijsTimmers/cursor/issues/2

manrajgrover commented 6 years ago

@ccc032 This should be fixed now. Could you please try HEAD and check whether you are still facing this issue or not? I'll make a release for this soon.

mirukana commented 6 years ago

@ManrajGrover Everything works fine now, thanks.