[tin-users] Piping/Printing message looks odd TODO

Glenn Spell glenn at gs.fay.nc.us
Fri Apr 1 22:14:23 CEST 2016


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




More information about the tin-users mailing list