-
Notifications
You must be signed in to change notification settings - Fork 54
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
implement some prettyping-inspired display alongside textual data. #3
Conversation
this is a first stab at porting "prettyping.sh" into noping. the idea is to show a histogram of ping times instead of numerical values. with some work, we could actually show both, but this focuses on implementing the hard part (the histogram) properly. it is very rudimentary for now: * the math may be wrong for the size of the bar, I was mostly in a rush to make unicode work and have something pretty quickly. * all hosts are on the same line: each should have its own line * the histogram should be displayed in a separate window * it should use background colors as well * it should fallback when the terminal is not unicode-capable * the scaling logic is fully automatic, which necessarily gives weird results at first this requires switching to the ncursesw library and other unicode ncurses hackery described in this post: http://newsgroups.derkeiler.com/Archive/Rec/rec.games.roguelike.development/2010-09/msg00050.html pretty ping is a awk/bash script, MIT-licensed, available here: https://bitbucket.org/denilsonsa/small_scripts/src/tip/prettyping.sh
this was breaking the border
make sure that if we go beyond the max ratio, we just mark it as one
i did this after some stress testing, now it covers the whole range on input
Note that prettyping falls back to regular ASCII characters ( Now the questions are:
For example, the following program: #include <ncurses.h>
int main(void)
{
int counter;
initscr();
attron(A_UNDERLINE);
mvprintw(0,7,"Progress bar testing\n\n");
attroff(A_UNDERLINE);
for (counter=115; counter >= 111; counter--)
{
addch(counter | A_ALTCHARSET);
}
refresh();
getch();
endwin();
return 0;
} ... outputs:
It renders better on the terminal than here - it progresses actually quite nicely in 5 steps. Not bad! More information: |
Thanks again and best regards, |
Awesome, let's see what's the magic incantation then we can finish this. :) If you have pointers on how to name the commandline option, it would be appreciated. prettyping uses |
We're not using getopt_long for portability at the moment. I think a convention is to use upper case and lower case for boolean options, though not consistently: |
sounds like a plan to me! now if we could only figure out how to auto-detect now ;) |
This makes it much easier and cleaner to add a second, non-Unicode implementation and possibly even a non-color version.
Also, I just pushed an update to the ab/prettyping branch of my repository which does some refactoring of the code into its own function. I'd be great if you could merge or pick that into the PR. Thanks :) |
About unicode detection, what do we have?
It's unclear what are the expectations (of ncurses?) here - do we expect a "unicode" or "utf-8" terminal? And if the locale is set, that's one thing, but it doesn't mean the terminal supports it. But I guess we could assume that if the locale is set to unicode and the terminal doesn't support it, that's some serious foot-shooting from the user and failure is expected. That is my expectation is a unicode user anyways so far. |
Another note - from what I understand, ncurses itself relies on nl_getinfo() to detect the locale to display (say) unicode or borders properly. (I base this on the claim done by python.) I am not sure what that means, but there you go. :) |
I added the refactoring in - one thing though: it seems now the code runs only if |
Here's the unicode-detection code in ncurses:
This function is used as such:
Maybe we can use that? the screen object doesn't seem accessible unfortunately... |
this is fairly ugly - we use a hidden ncurses function to detect unicode (but at least we don't reimplement it), then we mess around with the character arrays to display the rights symbols i am not sure i like this, but i prefer to braindump than to stall, so let's move forward.
alright, that commit (5901ec3) adds some crude autodetection magic (based on that hidden ncurses function, we're just missing a commandline option now and we're good, although a second pair of eyes on that ugly mess I just pushed should be applied. unset |
this will ease transition to a commandline option override
note that "forcing" may not work: ncurses still expects your locale to be correct, so maybe the force flag should also explicitely set a utf8 locale?
done for the night. :) |
…tion. The "-u" and "-U" options are now handled in a single variable so that the last option "wins".
Alright, so we now have a commandline option, proper toolchain hooks, everything seems to be in order and I use this in production on a daily basis. In fact, I have had this code (65e6e0f, to be more precise) running for over 7 days straight over 6 targets now, so I'd say it works well. :) Can we merge this in already? The debian package already picked it up as well: http://packages.qa.debian.org/libo/liboping/news/20131226T164825Z.html :) |
ping? |
ping |
can we get this show on the road? this is working now, i have ran the code in a test to multiple hosts until i rebooted my workstation, about a week ago - so basically 4 months, without a crash. |
ping |
Any updates on this? |
Sorry for losing track of this :\ I've just merged this to the master branch (4710e54) and will create a new liboping version soon now :) Best regards, |
alas! thank you very much for this! |
In case someone looks at this pull request someday in the future and finds broken links to prettyping, it is because it has a new homepage: https://github.com/denilsonsa/prettyping and http://denilsonsa.github.io/prettyping/ |
this is a first stab at porting "prettyping.sh" into noping. the idea is to show a histogram of the ping history.
it is a little rough for now:
this requires switching to the ncursesw library and other unicode ncurses hackery described in this post:
http://newsgroups.derkeiler.com/Archive/Rec/rec.games.roguelike.development/2010-09/msg00050.html
pretty ping is a awk/bash script, MIT-licensed, available here:
https://bitbucket.org/denilsonsa/small_scripts/src/tip/prettyping.sh