Re: [tin-users] Piping/Printing message looks odd TODO
On 21 Mar 2016 around 7:36AM (-0400) Thomas Dickey wrote:
On Tue, Mar 15, 2016 at 08:04:12AM +0100, Urs Janßen wrote:
On Mon, Mar 14, 2016 at 08:45:13PM -0400, Glenn Spell wrote:
For years the following note has been in the tin feed.c file concerning the piping and printing messages:
/* TODO: looks odd because screen mode is raw */
As an illustration, the following patch provides me with a workaround for this issue.
It doesn't make any differfence here - looks as ugly as always on x86_64-pc-linux-gnu; ncursesw5.
Please check and see if the patch below provides any improvement.
The code looks "okay", but (reading the source), I think the fix should be in screen.c within show_progress().
OK. I've made some changes to show_progress(). How does this look? I changed the display of the "Press <RETURN> to continue..." message to be centered with color. That may not be the desired display format. Index: include/extern.h --- tin-2.3.2.orig/include/extern.h 2015-11-22 00:15:40.000000000 +0000 +++ tin-2.3.2/include/extern.h 2016-03-21 11:20:01.000000000 +0000 @@ -1605,6 +1605,7 @@ extern char *input_history[HIST_MAXNUM + # endif /* NNTP_INEWS */ #endif /* FORGERY */ +extern t_bool feed_raw_mode; extern t_bool word_highlight; #ifdef HAVE_COLOR extern constext txt_tinrc_colors[]; Index: src/feed.c --- tin-2.3.2.orig/src/feed.c 2015-11-22 00:14:30.000000000 +0000 +++ tin-2.3.2/src/feed.c 2016-03-21 11:16:13.000000000 +0000 @@ -439,21 +439,25 @@ feed_article( switch (function) { #ifndef DONT_HAVE_PIPING case FEED_PIPE: - /* TODO: looks odd because screen mode is raw */ - progress_mesg = fmt_string("%s (%d/%d)", _(txt_piping), counter->total, counter->max); + feed_raw_mode = TRUE; + show_progress(fmt_string("%s (%d/%d)", _(txt_piping), counter->total, counter->max), counter->total, counter->max); + feed_raw_mode = FALSE; break; #endif /* !DONT_HAVE_PIPING */ #ifndef DISABLE_PRINTING case FEED_PRINT: - /* TODO: looks odd because screen mode is raw */ - progress_mesg = fmt_string("%s (%d/%d)", _(txt_printing), counter->total, counter->max); + feed_raw_mode = TRUE; + show_progress(fmt_string("%s (%d/%d)", _(txt_printing), counter->total, counter->max), counter->total, counter->max); + feed_raw_mode = FALSE; break; #endif /* !DISABLE_PRINTING */ case FEED_SAVE: case FEED_AUTOSAVE: - progress_mesg = fmt_string("%s (%d/%d)", _(txt_saving), counter->total, counter->max); + feed_raw_mode = TRUE; + show_progress(fmt_string("%s (%d/%d)", _(txt_saving), counter->total, counter->max), counter->total, counter->max); + feed_raw_mode = FALSE; break; } Index: src/init.c --- tin-2.3.2.orig/src/init.c 2015-11-22 00:14:30.000000000 +0000 +++ tin-2.3.2/src/init.c 2016-03-21 11:16:05.000000000 +0000 @@ -127,6 +127,7 @@ t_bool created_rcdir; /* checks if fir t_bool dangerous_signal_exit; /* no get_respcode() in nntp_command when dangerous signal exit */ t_bool disable_gnksa_domain_check; /* disable checking TLD in From: etc. */ t_bool disable_sender; /* disable generation of Sender: header */ +t_bool feed_raw_mode = FALSE; /* show_progress() for feed_article() */ #ifdef NO_POSTING t_bool force_no_post = TRUE; /* force no posting mode */ #else Index: src/prompt.c --- tin-2.3.2.orig/src/prompt.c 2015-11-22 00:14:31.000000000 +0000 +++ tin-2.3.2/src/prompt.c 2016-03-21 07:36:28.000000000 +0000 @@ -773,8 +773,9 @@ prompt_continue( { int ch; int save_signal_context = signal_context; + t_bool save_cmd_line = cmd_line; - cmd_line = TRUE; + cmd_line = FALSE; info_message(_(txt_return_key)); signal_context = cMain; input_context = cPromptCONT; @@ -797,7 +798,7 @@ prompt_continue( #ifdef USE_CURSES my_fputc('\n', stdout); #endif /* USE_CURSES */ - cmd_line = FALSE; + cmd_line = save_cmd_line; #ifdef USE_CURSES my_retouch(); #endif /* USE_CURSES */ Index: src/screen.c --- tin-2.3.2.orig/src/screen.c 2015-11-22 00:14:31.000000000 +0000 +++ tin-2.3.2/src/screen.c 2016-03-21 08:38:37.000000000 +0000 @@ -465,6 +465,7 @@ show_progress( static int last_ratio; static t_artnum last_total; static time_t last_update; + t_bool save_cmd_line = cmd_line; #if defined(HAVE_CLOCK_GETTIME) || defined(HAVE_GETTIMEOFDAY) static t_artnum last_count; static int average; @@ -481,6 +482,9 @@ show_progress( if (batch_mode || count <= 0 || total <= 0) return; + if (feed_raw_mode) + cmd_line = FALSE; + /* If this is a new progress meter, start recalculating */ if ((last_txt != txt) || (last_total != total)) { last_ratio = -1; @@ -490,7 +494,7 @@ show_progress( curr_time = time(NULL); ratio = (int) ((count * 100) / total); - if ((ratio == last_ratio) && (curr_time - last_update < 2)) + if ((ratio == last_ratio) && (curr_time - last_update < 2) && (!feed_raw_mode)) /* * return if ratio did not change and less than 1-2 seconds since last * update to reduce output @@ -499,6 +503,7 @@ show_progress( last_update = curr_time; + if (!feed_raw_mode) { #if defined(HAVE_CLOCK_GETTIME) || defined(HAVE_GETTIMEOFDAY) display_format = my_malloc(strlen(DISPLAY_FMT) + strlen(_(txt_remaining)) + 1); strcpy(display_format, DISPLAY_FMT); @@ -556,6 +561,9 @@ show_progress( #else snprintf(display, sizeof(display), "%s %3d%%", txt, ratio); #endif /* HAVE_CLOCK_GETTIME || HAVE_GETTIMEOFDAY */ + } else { + snprintf(display, sizeof(display), "%s %3d%%", txt, ratio); + } /* Only display text if it changed from last time */ if (strcmp(display, last_display)) { @@ -587,4 +595,7 @@ show_progress( last_txt = txt; last_total = total; last_ratio = ratio; + + if (feed_raw_mode) + cmd_line = save_cmd_line; } Glenn
On Mon, Mar 21, 2016 at 07:57:16AM -0400, Glenn Spell wrote:
Please check and see if the patch below provides any improvement.
If you tag a few articles on the group or thread level and pipe them into a cmd. the tag mark is still present till the next manually forced screen redraw (^L)'.
Index: include/extern.h --- tin-2.3.2.orig/include/extern.h 2015-11-22 00:15:40.000000000 +0000 +++ tin-2.3.2/include/extern.h 2016-03-21 11:20:01.000000000 +0000 @@ -1605,6 +1605,7 @@ extern char *input_history[HIST_MAXNUM + # endif /* NNTP_INEWS */ #endif /* FORGERY */
+extern t_bool feed_raw_mode;
Yet another new global var, why not passing a flag to show_progress() if you're calling it direct (which is IMHO still not right)?
extern t_bool word_highlight; #ifdef HAVE_COLOR extern constext txt_tinrc_colors[]; Index: src/feed.c --- tin-2.3.2.orig/src/feed.c 2015-11-22 00:14:30.000000000 +0000 +++ tin-2.3.2/src/feed.c 2016-03-21 11:16:13.000000000 +0000 @@ -439,21 +439,25 @@ feed_article( switch (function) { #ifndef DONT_HAVE_PIPING case FEED_PIPE: - /* TODO: looks odd because screen mode is raw */ - progress_mesg = fmt_string("%s (%d/%d)", _(txt_piping), counter->total, counter->max); + feed_raw_mode = TRUE; + show_progress(fmt_string("%s (%d/%d)", _(txt_piping), counter->total, counter->max), counter->total, counter->max); + feed_raw_mode = FALSE; break; #endif /* !DONT_HAVE_PIPING */
progress_mesg is still NULL, but is passed on to art_open() in line 467, passing it to progress() in the end which then skips show_progress() - not very clean IMHO. urs -- "Only whimps use tape backup: _real_ men just upload their important stuff on ftp, and let the rest of the world mirror it ;)" - Linus
On 25 Mar 2016 around 1:27PM (-0400) Urs Janßen wrote:
If you tag a few articles on the group or thread level and pipe them into a cmd. the tag mark is still present till the next manually forced screen redraw (^L)'.
I think that's fixed for piping, printing and saving in the patch below.
Yet another new global var, why not passing a flag to show_progress() if you're calling it direct (which is IMHO still not right)?
OK. No new global variable for show_progress(), although I'm no longer calling it direct. The new global var is for the new piped message.
progress_mesg is still NULL, but is passed on to art_open() in line 467, passing it to progress() in the end which then skips show_progress() - not very clean IMHO.
OK. I'm no longer changing any of that code in feed.c. Please take a look at this and tell me what y'all think: Index: include/extern.h --- tin-2.3.2.orig/include/extern.h 2015-11-22 00:15:40.000000000 +0000 +++ tin-2.3.2/include/extern.h 2016-03-25 16:18:45.000000000 +0000 @@ -479,6 +479,9 @@ extern constext txt_articles_mailed[]; #ifndef DISABLE_PRINTING extern constext txt_articles_printed[]; #endif /* !DISABLE_PRINTING */ +#ifndef DONT_HAVE_PIPING + extern constext txt_articles_piped[]; +#endif /* !DONT_HAVE_PIPING */ extern constext txt_attach[]; extern constext txt_attach_charset[]; extern constext txt_attach_description[]; Index: src/feed.c --- tin-2.3.2.orig/src/feed.c 2015-11-22 00:14:30.000000000 +0000 +++ tin-2.3.2/src/feed.c 2016-03-25 16:47:06.000000000 +0000 @@ -439,14 +439,12 @@ feed_article( switch (function) { #ifndef DONT_HAVE_PIPING case FEED_PIPE: - /* TODO: looks odd because screen mode is raw */ progress_mesg = fmt_string("%s (%d/%d)", _(txt_piping), counter->total, counter->max); break; #endif /* !DONT_HAVE_PIPING */ #ifndef DISABLE_PRINTING case FEED_PRINT: - /* TODO: looks odd because screen mode is raw */ progress_mesg = fmt_string("%s (%d/%d)", _(txt_printing), counter->total, counter->max); break; #endif /* !DISABLE_PRINTING */ @@ -668,6 +666,7 @@ feed_articles( /* Setup printing - get print command line */ case FEED_PRINT: snprintf(outpath, sizeof(outpath), "%s %s", tinrc.printer, REDIRECT_OUTPUT); + redraw_screen = TRUE; break; #endif /* !DISABLE_PRINTING */ @@ -928,12 +927,11 @@ got_epipe_while_piping: Raw(TRUE); InitWin(); # endif /* USE_CURSES */ - prompt_continue(); + currmenu->redraw(); # ifndef USE_CURSES Raw(TRUE); InitWin(); # endif /* !USE_CURSES */ - redraw_screen = TRUE; break; #endif /* !DONT_HAVE_PIPING */ @@ -944,6 +942,7 @@ got_epipe_while_piping: break; } + currmenu->redraw(); print_save_summary(feed_type, counter.total); if (pproc_func != POSTPROCESS_NO) { t_bool delete_post_proc = FALSE; @@ -1024,6 +1023,12 @@ got_epipe_while_piping: } break; +#ifndef DONT_HAVE_PIPING + case FEED_PIPE: + info_message(_(txt_articles_piped), counter.success, PLURAL(counter.success, txt_article)); + break; +#endif /* !DONT_HAVE_PIPING */ + #ifndef DISABLE_PRINTING case FEED_PRINT: info_message(_(txt_articles_printed), counter.success, PLURAL(counter.success, txt_article)); Index: src/lang.c --- tin-2.3.2.orig/src/lang.c 2015-11-22 00:14:30.000000000 +0000 +++ tin-2.3.2/src/lang.c 2016-03-25 16:15:17.000000000 +0000 @@ -1145,6 +1145,7 @@ Tin will try to use XHDR XREF instead (s #endif /* !DISABLE_PRINTING */ #ifndef DONT_HAVE_PIPING + constext txt_articles_piped[] = N_("%d %s piped"); constext txt_help_global_pipe[] = N_("pipe article/thread/hot/pattern/tagged articles into command"); constext txt_no_command[] = N_("No command"); constext txt_pipe[] = N_("Pipe"); Index: src/prompt.c --- tin-2.3.2.orig/src/prompt.c 2015-11-22 00:14:31.000000000 +0000 +++ tin-2.3.2/src/prompt.c 2016-03-23 19:11:50.000000000 +0000 @@ -773,8 +773,9 @@ prompt_continue( { int ch; int save_signal_context = signal_context; + t_bool save_cmd_line = cmd_line; - cmd_line = TRUE; + cmd_line = FALSE; info_message(_(txt_return_key)); signal_context = cMain; input_context = cPromptCONT; @@ -797,7 +798,7 @@ prompt_continue( #ifdef USE_CURSES my_fputc('\n', stdout); #endif /* USE_CURSES */ - cmd_line = FALSE; + cmd_line = save_cmd_line; #ifdef USE_CURSES my_retouch(); #endif /* USE_CURSES */ Index: src/screen.c --- tin-2.3.2.orig/src/screen.c 2015-11-22 00:14:31.000000000 +0000 +++ tin-2.3.2/src/screen.c 2016-03-25 13:16:57.000000000 +0000 @@ -465,6 +465,8 @@ show_progress( static int last_ratio; static t_artnum last_total; static time_t last_update; + t_bool feeding = FALSE; + t_bool save_cmd_line = cmd_line; #if defined(HAVE_CLOCK_GETTIME) || defined(HAVE_GETTIMEOFDAY) static t_artnum last_count; static int average; @@ -481,6 +483,17 @@ show_progress( if (batch_mode || count <= 0 || total <= 0) return; + cmd_line = FALSE; + + /* TODO: ratio and time remaining are unstable when feeding * + * If feeding articles, don't print ratio or time remaining */ + if (strncmp(txt, _(txt_piping), strlen(_(txt_piping))) == 0 || + strncmp(txt, _(txt_printing), strlen(_(txt_printing))) == 0 || + strncmp(txt, _(txt_saving), strlen(_(txt_saving))) == 0) { + feeding = TRUE; + goto feeding; + } + /* If this is a new progress meter, start recalculating */ if ((last_txt != txt) || (last_total != total)) { last_ratio = -1; @@ -557,6 +570,10 @@ show_progress( snprintf(display, sizeof(display), "%s %3d%%", txt, ratio); #endif /* HAVE_CLOCK_GETTIME || HAVE_GETTIMEOFDAY */ + feeding: + if (feeding) + snprintf(display, sizeof(display), "%s", txt); + /* Only display text if it changed from last time */ if (strcmp(display, last_display)) { char *tmp; @@ -584,7 +601,11 @@ show_progress( STRCPY(last_display, display); } - last_txt = txt; - last_total = total; - last_ratio = ratio; + if (!feeding) { + last_txt = txt; + last_total = total; + last_ratio = ratio; + } + + cmd_line = save_cmd_line; } Glenn
On Fri, Mar 25, 2016 at 01:55:03PM -0400, Glenn Spell wrote:
Please take a look at this and tell me what y'all think:
instead of the goto I'd use if (!feeding) { /* If this is a new progress meter, start recalculating */ // ... } else snprintf(display, sizeof(display), "%s", txt); and move the if (!feeding) block from the end up into that large block. Otherwise it looks ok to me (but I didn't test it anywhere except i686-pc-linux-gnu & ncursesw (6.0.20160319)). urs
On 26 Mar 2016 around 6:05AM (-0400) Urs Urs Janßen wrote:
On Fri, Mar 25, 2016 at 01:55:03PM -0400, Glenn Spell wrote:
Please take a look at this and tell me what y'all think:
Otherwise it looks ok to me (but I didn't test it anywhere except i686-pc-linux-gnu & ncursesw (6.0.20160319)).
Thanks for applying the patch for the 2.3.3 release. It was still a work in progress. I've finished it now, and I'm satisfied with it. I've tested it on NetBSD with ncursesw and with termcap. But I'd still appreciate your comments. I completed setting the cmd_line var to FALSE for all stdout messages. I reverted some code from the previous patch that wouldn't work well in some edge cases. I've re-enabled the progress meter for feeding articles, calling show_progress() directly and reworking the progress_mesg var in feed.c. I added command to the new piped to message. I've prevented the progress meter from running backwards. I finished reworking the screen redraws in feed.c. If this is satisfactory please apply this patch to 2.3.3. Please take a look at this: Index: src/feed.c --- tin-2.3.3.orig/src/feed.c 2016-03-26 09:44:08.000000000 +0000 +++ tin-2.3.3/src/feed.c 2016-04-01 17:37:19.000000000 +0000 @@ -400,7 +400,7 @@ print_save_summary( snprintf(buf, sizeof(buf), _(txt_saved_to_range), what, first, last); - wait_message((tinrc.beginner_level) ? 2 : 1, buf); + wait_message((tinrc.beginner_level) ? 4 : 2, buf); return; } @@ -454,17 +454,19 @@ feed_article( progress_mesg = fmt_string("%s (%d/%d)", _(txt_saving), counter->total, counter->max); break; } + if (progress_mesg != NULL) { + show_progress(progress_mesg, counter->total, counter->max); + free(progress_mesg); + progress_mesg = NULL; + } if (use_current) openartptr = &pgart; /* Use art already open in pager */ else { - if (art_open(FALSE, &arts[art], group, openartptr, TRUE, progress_mesg) < 0) { + if (art_open(FALSE, &arts[art], group, openartptr, FALSE, NULL) < 0) /* User abort or an error */ - FreeIfNeeded(progress_mesg); return FALSE; - } } - FreeIfNeeded(progress_mesg); switch (function) { case FEED_MAIL: @@ -666,7 +668,6 @@ feed_articles( /* Setup printing - get print command line */ case FEED_PRINT: snprintf(outpath, sizeof(outpath), "%s %s", tinrc.printer, REDIRECT_OUTPUT); - redraw_screen = TRUE; break; #endif /* !DISABLE_PRINTING */ @@ -844,6 +845,7 @@ feed_articles( } } untag_all_articles(); /* TODO: this will untag even on partial failure */ + redraw_screen = TRUE; break; case FEED_HOT: /* hot (auto-selected) articles */ @@ -927,7 +929,7 @@ got_epipe_while_piping: Raw(TRUE); InitWin(); # endif /* USE_CURSES */ - currmenu->redraw(); + prompt_continue(); # ifndef USE_CURSES Raw(TRUE); InitWin(); @@ -942,7 +944,10 @@ got_epipe_while_piping: break; } - currmenu->redraw(); + if (redraw_screen) { + currmenu->redraw(); + redraw_screen = FALSE; + } print_save_summary(feed_type, counter.total); if (pproc_func != POSTPROCESS_NO) { t_bool delete_post_proc = FALSE; @@ -987,8 +992,10 @@ got_epipe_while_piping: clear_message(); } } else { - if (redraw_screen) + if (redraw_screen) { currmenu->redraw(); + redraw_screen = FALSE; + } } /* @@ -1025,7 +1032,7 @@ got_epipe_while_piping: #ifndef DONT_HAVE_PIPING case FEED_PIPE: - info_message(_(txt_articles_piped), counter.success, PLURAL(counter.success, txt_article)); + info_message(_(txt_articles_piped), counter.success, PLURAL(counter.success, txt_article), tinrc.default_pipe_command); break; #endif /* !DONT_HAVE_PIPING */ Index: src/lang.c --- tin-2.3.3.orig/src/lang.c 2016-03-26 09:44:08.000000000 +0000 +++ tin-2.3.3/src/lang.c 2016-04-01 17:37:20.000000000 +0000 @@ -1145,7 +1145,7 @@ Tin will try to use XHDR XREF instead (s #endif /* !DISABLE_PRINTING */ #ifndef DONT_HAVE_PIPING - constext txt_articles_piped[] = N_("%d %s piped"); + constext txt_articles_piped[] = N_("%d %s piped to \"%s\""); constext txt_help_global_pipe[] = N_("pipe article/thread/hot/pattern/tagged articles into command"); constext txt_no_command[] = N_("No command"); constext txt_pipe[] = N_("Pipe"); Index: src/screen.c --- tin-2.3.3.orig/src/screen.c 2016-03-26 09:56:33.000000000 +0000 +++ tin-2.3.3/src/screen.c 2016-04-01 17:37:20.000000000 +0000 @@ -97,8 +97,11 @@ info_message( ...) { char *buf; + t_bool save_cmd_line = cmd_line; va_list ap; + cmd_line = FALSE; + va_start(ap, fmt); clear_message(); @@ -116,6 +119,8 @@ info_message( stow_cursor(); va_end(ap); + + cmd_line = save_cmd_line; } @@ -129,8 +134,11 @@ wait_message( ...) { char *buf; + t_bool save_cmd_line = cmd_line; va_list ap; + cmd_line = FALSE; + va_start(ap, fmt); clear_message(); @@ -151,6 +159,8 @@ wait_message( (void) sleep(sdelay); /* clear_message(); would be nice, but tin doesn't expect this yet */ va_end(ap); + + cmd_line = save_cmd_line; } @@ -465,11 +475,11 @@ show_progress( static int last_ratio; static t_artnum last_total; static time_t last_update; - t_bool feeding = FALSE; t_bool save_cmd_line = cmd_line; #if defined(HAVE_CLOCK_GETTIME) || defined(HAVE_GETTIMEOFDAY) static t_artnum last_count; static int average; + static int last_average; static int samples; static int sum; char *display_format; @@ -485,104 +495,88 @@ show_progress( cmd_line = FALSE; - /* - * ratio and time remaining are unstable when feeding; - * if feeding articles, don't print ratio or time remaining - */ - if ( -#ifndef DONT_HAVE_PIPING - (!strncmp(txt, _(txt_piping), strlen(_(txt_piping)))) || -#endif /* DONT_HAVE_PIPING */ -#ifndef DISABLE_PRINTING - (!strncmp(txt, _(txt_printing), strlen(_(txt_printing)))) || -#endif /* DISABLE_PRINTING */ - (!strncmp(txt, _(txt_saving), strlen(_(txt_saving))))) - feeding = TRUE; - - if (!feeding) { - /* If this is a new progress meter, start recalculating */ - if ((last_txt != txt) || (last_total != total)) { - last_ratio = -1; - last_display[0] = '\0'; - last_update = time(NULL) - 2; - } + /* If this is a new progress meter, start recalculating */ + if ((last_txt != txt) || (last_total != total)) { + last_ratio = -1; + last_display[0] = '\0'; + last_update = time(NULL) - 2; + } - curr_time = time(NULL); - ratio = (int) ((count * 100) / total); - if ((ratio == last_ratio) && (curr_time - last_update < 2)) - /* - * return if ratio did not change and less than 1-2 seconds since last - * update to reduce output - */ - return; + curr_time = time(NULL); + ratio = (int) ((count * 100) / total); + if ((ratio == last_ratio) && (curr_time - last_update < 2)) + /* + * return if ratio did not change and less than 1-2 seconds since last + * update to reduce output + */ + return; - last_update = curr_time; + last_update = curr_time; #if defined(HAVE_CLOCK_GETTIME) || defined(HAVE_GETTIMEOFDAY) - display_format = my_malloc(strlen(DISPLAY_FMT) + strlen(_(txt_remaining)) + 1); - strcpy(display_format, DISPLAY_FMT); + display_format = my_malloc(strlen(DISPLAY_FMT) + strlen(_(txt_remaining)) + 1); + strcpy(display_format, DISPLAY_FMT); - if (last_ratio == -1) { - /* Don't print a "time remaining" this time */ - snprintf(display, sizeof(display), display_format, txt, ratio); + if (last_ratio == -1) { + /* Don't print a "time remaining" this time */ + snprintf(display, sizeof(display), display_format, txt, ratio); - /* Reset the variables */ - sum = average = samples = 0; + /* Reset the variables */ + sum = average = samples = 0; + } else { + /* Get the current time */ + tin_gettime(&this_time); + time_diff = (this_time.tv_sec - last_time.tv_sec) * 1000000; + time_diff += ((this_time.tv_nsec - last_time.tv_nsec) / 1000); + count_diff = (count - last_count); + + if (!count_diff) /* avoid div by zero */ + count_diff++; + + /* + * Calculate a running average based on the last 20 samples. For the + * first 19 samples just add all and divide by the number of samples. + * From the 20th sample on use only the last 20 samples to calculate + * the running averave. To make things easier we don't want to store + * and keep track of all of them, so we assume that the first sample + * was close to the current average and subtract it from sum. Then, + * the new sample is added to the sum and the sum is divided by 20 to + * get the new average. + */ + if (samples == 20) { + sum -= average; + sum += (time_diff / count_diff); + average = sum / 20; } else { - /* Get the current time */ - tin_gettime(&this_time); - time_diff = (this_time.tv_sec - last_time.tv_sec) * 1000000; - time_diff += ((this_time.tv_nsec - last_time.tv_nsec) / 1000); - count_diff = (count - last_count); - - if (!count_diff) /* avoid div by zero */ - count_diff++; - - /* - * Calculate a running average based on the last 20 samples. For the - * first 19 samples just add all and divide by the number of samples. - * From the 20th sample on use only the last 20 samples to calculate - * the running averave. To make things easier we don't want to store - * and keep track of all of them, so we assume that the first sample - * was close to the current average and subtract it from sum. Then, - * the new sample is added to the sum and the sum is divided by 20 to - * get the new average. - */ - if (samples == 20) { - sum -= average; - sum += (time_diff / count_diff); - average = sum / 20; - } else { - sum += (time_diff / count_diff); - average = sum / ++samples; - } + sum += (time_diff / count_diff); + average = sum / ++samples; + } - if (average >= 1000000) - secs_left = (total - count) * (average / 1000000); - else - secs_left = ((total - count) * average) / 1000000; + /* Don't allow progress meter to run backwards */ + if (average < last_average) + average = last_average; + else if (average > last_average) + last_average = average; - if (secs_left < 0) - secs_left = 0; + if (average >= 1000000) + secs_left = (total - count) * (average / 1000000); + else + secs_left = ((total - count) * average) / 1000000; - strcat(display_format, _(txt_remaining)); - snprintf(display, sizeof(display), display_format, txt, ratio, secs_left / 60, secs_left % 60); - } - free(display_format); + if (secs_left < 0) + secs_left = 0; + + strcat(display_format, _(txt_remaining)); + snprintf(display, sizeof(display), display_format, txt, ratio, secs_left / 60, secs_left % 60); + } + free(display_format); - last_count = count; - tin_gettime(&last_time); + last_count = count; + tin_gettime(&last_time); #else - snprintf(display, sizeof(display), "%s %3d%%", txt, ratio); + snprintf(display, sizeof(display), "%s %3d%%", txt, ratio); #endif /* HAVE_CLOCK_GETTIME || HAVE_GETTIMEOFDAY */ - last_txt = txt; - last_total = total; - last_ratio = ratio; - - } else - snprintf(display, sizeof(display), "%s", txt); - /* Only display text if it changed from last time */ if (strcmp(display, last_display)) { char *tmp; @@ -610,5 +604,9 @@ show_progress( STRCPY(last_display, display); } + last_txt = txt; + last_total = total; + last_ratio = ratio; + cmd_line = save_cmd_line; } Thanks, Glenn
On Fri, Apr 01, 2016 at 04:14:23PM -0400, Glenn Spell wrote:
I completed setting the cmd_line var to FALSE for all stdout messages. I reverted some code from the previous patch that wouldn't work well in some edge cases. I've re-enabled the progress meter for feeding articles, calling show_progress() directly and reworking the progress_mesg var in feed.c. I added command to the new piped to message. I've prevented the progress meter from running backwards. I finished reworking the screen redraws in feed.c.
If this is satisfactory please apply this patch to 2.3.3.
When piping an article to 'pgpverify -test' the screen with the result of pgpverify is messed up after aplying this patch. Here is a screenshot: <http://d--p.de/tmp/2016-04-03.png> Whithout this patch (plain 2.3.3) I cannot see that screen at all. It seems to be that tin no longer waits for a key ("Press <RETURN> to continue..."). Dennis
participants (3)
-
Dennis Preiser -
Glenn Spell -
Urs Janßen