tenox7 / ttyplot

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

Trigger redraw on SIGWINCH (Window resize signal) #61

Closed eMPee584 closed 1 year ago

eMPee584 commented 1 year ago

Otherwise, the plot will look broken until the regular refresh timeout has occurred..

tenox7 commented 1 year ago

sounds simple enough, would you consider sending a PR?

tenox7 commented 1 year ago

but wait, this is already there:

https://github.com/tenox7/ttyplot/blob/master/ttyplot.c#L217

is it not working correctly?

eMPee584 commented 1 year ago

Well checked again, it doesn't seem so.. using debian's version 1.4+77.g1a1693b-2 ..

zbits commented 1 year ago

My slow moving graphs that update once an hour do not update on window resize:

netstat -b -w 3600 -I em0 | awk 'NR>3 { print $1/1048576; print $2/1048576; fflush }' | ttyplot -2 -t "IN/OUT Bandwidth in MB/s (${1}s resolution)" -u "MB/s" -c "#"

Using version 1.4 on OpenBSD.

tenox7 commented 1 year ago

thanks, let me investigate a bit more

tenox7 commented 1 year ago
netstat -b -w 3600 -I em0 | awk 'NR>3 { print $1/1048576; print $2/1048576; fflush }' | ttyplot -2 -t "IN/OUT Bandwidth in MB/s (${1}s resolution)" -u "MB/s" -c "#"

thats actually a really cool way of getting bandwidth usage! @zbits would you like to send a PR for readme/examples :)

tenox7 commented 1 year ago

OK I did some testing and I think I understand the issue. So redraw() is called on SIGWINCH, however it doesn't actually repaint the screen. The screen is eventually correctly redrawn when there is data for a new refresh, however in this case this would be after 1 hour. This should not be the case, SIGWINCH should do a full redraw of course.

The fix would be to repaint the screen with current data in a separate function. That function would be called either from the main while loop or refresh() on SIGWINCH.

tenox7 commented 1 year ago

ok I think I fixed it, in head master

can you download the source, compile and test?

zbits commented 1 year ago

That fixed it! Thank you.

Note that compiling it on openbsd the library "tinfo" was missing. I wasn't sure how to obtain it and the ttyplot git commits didn't explain its necessity, so I edited it out of the Makefile and ttyplot compiled and worked fine.

thats actually a really cool way of getting bandwidth usage! @zbits would you like to send a PR for readme/examples :)

I'm new to git and have never created a PR but I will read up on it and send you one.

Thanks for the ttyplot project. I love its simplicity. In my case, it replaced a prometheus/grafana solution.

tenox7 commented 1 year ago

thanks for testing! Let me know if any issues, I will make a release 1.5 with this soon

as for a PR, you basically fork it (top right "Fork"), then in your own copy you make edits - you can do it online even use the pen button just beside readme, make a commit, then once looks good then go to pull requests and create a PR