tenox7 / ttyplot

a realtime plotting utility for terminal/console with data input from stdin
Apache License 2.0
972 stars 45 forks source link

Feature request: work with limited data #25

Closed ChanderG closed 5 years ago

ChanderG commented 5 years ago

All uses cases where I would like to use ttyplot are with "limited" input. As it stands, ttyplot quits immediately on stdin EOF.

One simple solution that works is to replace the break statement in the if(r<0) codepath with a sleep(10); continue;.

I can open a PR, if this is desirable.

tenox7 commented 5 years ago

Sounds interesting. Can you provide some examples of data sources that work this way?

ChanderG commented 5 years ago

Usually log analysis with awk. Stuff like number of entries matching a string per second or time gap in milliseconds between entries. This sort of lightweight off-line analytics on log files.

tenox7 commented 5 years ago

Any chance you could produce some examples that I can see how it works? I'm just a little concerned that proposed change may introduce infinite loop over closed stdin / broken pipe.

ChanderG commented 5 years ago

A trivial example of limited data for testing:

seq 1 100 | ttyplot

You are right about the infinite loop though, that is exactly what happens. Then, the only way to exit is to SIGINT/Ctrl-C. Better to have a sigwait based approach maybe.

tenox7 commented 5 years ago

In above case there never going to be any data after seq is done. Do you want ttyplot to retry reading or pause before exiting? If retry, can you send a better example that demonstrates the use case? If it's just waiting before quit you could add sleep, eg { seq 1 100; sleep 60; } | ttyplot

ChanderG commented 5 years ago

No retry, just like the seq example above."sleep 60" solution works too.

Do feel free to close this issue, if the feature is not of general interest.

tenox7 commented 5 years ago

I just want to understand the issue a little more. I don't think I have full understanding yet.

If you are plotting data that say eventually "runs out" and just want ttyplot to hang around there doing nothing, much like lets say you piped it to more or less, then perhaps an option could be added to "do not quit after pipe is closed" or something like that.

Also perhaps do send a PR so I can review the changes and understand even better :)

tenox7 commented 5 years ago

@ChanderG I have created a new issue #41 not to clear screen while exiting, it should be simple to implement