Browse Source

Minor refactor of text-only mode: avoid wasting bottom line of console, and save status lines as they are replaced by log items

Luke Dashjr 11 years ago
parent
commit
a0109fec7b
3 changed files with 27 additions and 4 deletions
  1. 5 1
      logging.c
  2. 21 3
      miner.c
  3. 1 0
      miner.h

+ 5 - 1
logging.c

@@ -34,7 +34,11 @@ static void _my_log_curses(int prio, const char *datetime, const char *str)
 		;
 	else
 #endif
-		printf(" %s %s%s", datetime, str, "                    \n");
+	{
+		last_logstatusline_len = -1;
+		printf("\n %s %s\r", datetime, str);
+		fflush(stdout);
+	}
 }
 
 /* high-level logging function, based on global opt_log_level */

+ 21 - 3
miner.c

@@ -213,6 +213,7 @@ bool use_curses = true;
 #else
 bool use_curses;
 #endif
+int last_logstatusline_len;
 #ifdef HAVE_LIBUSB
 bool have_libusb;
 #endif
@@ -3831,7 +3832,8 @@ static void text_print_status(int thr_id)
 	cgpu = get_thr_cgpu(thr_id);
 	if (cgpu) {
 		get_statline(logline, sizeof(logline), cgpu);
-		printf("%s\n", logline);
+		printf("\n%s\r", logline);
+		fflush(stdout);
 	}
 }
 
@@ -8028,7 +8030,7 @@ static void hashmeter(int thr_id, struct timeval *diff,
 
 				get_statline(logline, sizeof(logline), cgpu);
 				if (!curses_active) {
-					printf("%s          \r", logline);
+					printf("\n%s\r", logline);
 					fflush(stdout);
 				} else
 					applog(LOG_INFO, "%s", logline);
@@ -8176,7 +8178,23 @@ out_unlock:
 
 	if (showlog) {
 		if (!curses_active) {
-			printf("%s          \r", logstatusline);
+			if (want_per_device_stats)
+				printf("\n%s\r", logstatusline);
+			else
+			{
+				const int logstatusline_len = strlen(logstatusline);
+				int padding;
+				if (last_logstatusline_len > logstatusline_len)
+					padding = (last_logstatusline_len - logstatusline_len);
+				else
+				{
+					padding = 0;
+					if (last_logstatusline_len == -1)
+						puts("");
+				}
+				printf("%s%*s\r", logstatusline, padding, "");
+				last_logstatusline_len = logstatusline_len;
+			}
 			fflush(stdout);
 		} else
 			applog(LOG_INFO, "%s", logstatusline);

+ 1 - 0
miner.h

@@ -938,6 +938,7 @@ extern bool opt_fail_only;
 extern bool opt_autofan;
 extern bool opt_autoengine;
 extern bool use_curses;
+extern int last_logstatusline_len;
 #ifdef HAVE_LIBUSB
 extern bool have_libusb;
 #endif