cURL / Mailing Lists / curl-users / Single Mail

curl-users

Re: simplified progress-bar for dumb terminals

From: Dan Fandrich <dan_at_coneharvesters.com>
Date: Wed, 4 Apr 2012 16:13:43 +0200

On Wed, Apr 04, 2012 at 02:38:42PM +0200, Kamil Dudka wrote:
> I was more thinking of a new option for this. Nevertheless, detecting term
> capabilities might also be a solution. The problem is that we need to link
> an additional library to access this information. Or am I missing something?

That's where tgetstr() and tigetstr() are on my Linux box, too.

> Please have a look at the attached patch. Any feedback is welcome.

> +AC_ARG_WITH(ncurses,
> +AC_HELP_STRING([--with-ncurses],[Enable ncurses support if available]),
> + [OPT_NCURSES=$withval])
> +
> +if test "x$OPT_NCURSES" != xno; then
> + if test "x$OPT_NCURSES" = xyes; then
> + CURL_CHECK_PKGCONFIG(ncurses)
> + if test "$PKGCONFIG" != "no" ; then
> + addlib=`$PKGCONFIG --libs ncurses`
> + addcflags=`$PKGCONFIG --cflags ncurses`

Does curses even come with a pkg-config file?

> +#ifdef USE_NCURSES
> +# include <term.h>
> +#endif

My docs say that both term.h and curses.h need to be included.

> + if(bar->dummy_term)
> + fputs(line, bar->out);
> + else {
> + snprintf(format, sizeof(format), "\r%%-%ds %%5.1f%%%%", barwidth);

Since we've gone through the effort to read the 'cr' capability out of
terminfo, we might as well use it here in place of a hard-coded \r.

> +#ifdef USE_NCURSES
> + term = curlx_getenv("TERM");
> + if(term) {
> + bar->dummy_term = (1 != tgetent(NULL, term)) || !tgetstr("cr", NULL);

What is the purpose of using the termcap compatibility routines here instead
of the terminfo routines? termcap has been obsolete for a long, long time.

> + free(term);
> + }
> +#endif
> +
> bar->out = config->errors;
> }
>
> diff --git a/src/tool_cb_prg.h b/src/tool_cb_prg.h
> index f64335a..c0e29fd 100644
> --- a/src/tool_cb_prg.h
> +++ b/src/tool_cb_prg.h
> @@ -32,6 +32,8 @@ struct ProgressData {
> int width;
> FILE *out; /* where to write everything to */
> curl_off_t initial_size;
> + bool dummy_term;

dumb_term or dumber_term here sounds better to my ears.

>>> Dan
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-users
FAQ: http://curl.haxx.se/docs/faq.html
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2012-04-04