-
-
Notifications
You must be signed in to change notification settings - Fork 36
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
Yaspin pipesafety issues #31
Comments
Hi @sebageek Thanks for reporting this! Can you please share python version and locale of the environment you're running at: $ python -V
$ locale -a Which operating system is used? |
Sure thing! I'm using python from within a virtualenv for this. Operating System is Linux.
|
I was able to look at this issue more thoroughly, especially at this part:
Initially, the idea behind "pipe safety" was the ability to direct the output of the program which uses As I see, the main concern outlined by this issue is that output generated by The way to fix this probably is to add more checks like @sebageek what do you think? I believe that, as of now, you have a closer familiarity with this issue, since you're actively utilizing |
So I think this depends on what the user expects from yaspin in case their program is used with a pipe (aka stdout is not a tty). I see the following options:
In my programs using yaspin I currently replace the Spinner class with a DummySpinner somewhat compatible to yaspin. This would be one approach but would need some tuning. In my code this looks something like this: class DummySpinner:
def __init__(self, *args, **kwargs):
self.text = ''
def write(self, *args, **kwargs):
print(*args, **kwargs)
def __getattr__(self, name):
return self
def __call__(self):
pass
def __enter__(self):
return self
def __exit__(self, *args, **kwargs):
return False With this I somewhat emulate |
This seems to be still an issue. I would prefer option 1 from the comment above. |
I'm seeing this same issue, similar environmental setup as #31 (comment): Python 3 (3.10), Linux (Ubuntu 20.04), running in a virtual environment. I'm only familiar with a handful of terminal drawing libraries/toolkits, but here's the rough order of precedence that I've seen elsewhere:
This is (IMO) the most reasonable set of defaults -- |
Pipesafety of yaspin does not work for me (or I misunderstood the feature).
When I run yaspin and pipe the output into another program or into a file I'd expect to only see the output of
write()
calls and maybe ofok()
/fail()
or other functions with persistant text. Nevertheless I can also see the spinnerstate in programms likeless
orxxd
.and when running this script
$ python pipesafe.py |xxd 00000000: 0de2 a08b 1b5b 306d 201b 5b4b 080d e2a0 .....[0m .[K.... 00000010: 991b 5b30 6d20 5465 7374 1b5b 4b08 0de2 ..[0m Test.[K... 00000020: a0b9 1b5b 306d 2054 6573 741b 5b4b 080d ...[0m Test.[K.. 00000030: e2a0 b81b 5b30 6d20 5465 7374 1b5b 4b0d ....[0m Test.[K. 00000040: 1b5b 4b48 656c 6c6f 2077 6f72 6c64 0a08 .[KHello world.. 00000050: 0d1b 5b4b ..[K
This feels especially weird when using grep. In the case grep matches the spinner text, only the text from
write()
is displayed:In an attempt to fix this in an application I'm writing I created a yaspin-like interface, that maps
write()
toprint()
and ignores.text
plus all other calls to the class. I then replace yaspin with that class if stdout is not a tty, but I'm not sure if this is the way to go for upstream.The text was updated successfully, but these errors were encountered: