Browse Source

Refactor temperature in TUI statlines to share code nicer

Luke Dashjr 12 years ago
parent
commit
ceb9a7e757
1 changed files with 16 additions and 9 deletions
  1. 16 9
      miner.c

+ 16 - 9
miner.c

@@ -2586,6 +2586,19 @@ void format_statline(char *buf, const char *cHr, const char *aHr, const char *uH
 }
 }
 #endif
 #endif
 
 
+static inline
+void temperature_column_tail(char *buf, bool maybe_unicode, const float * const temp)
+{
+	if (temp && *temp > 0.)
+			sprintf(buf, "%4.1fC", *temp);
+	else
+	{
+		if (temp)
+			strcpy(buf, "     ");
+	}
+	strcat(buf, " | ");
+}
+
 void get_statline3(char *buf, struct cgpu_info *cgpu, bool for_curses, bool opt_show_procs)
 void get_statline3(char *buf, struct cgpu_info *cgpu, bool for_curses, bool opt_show_procs)
 {
 {
 #ifndef HAVE_CURSES
 #ifndef HAVE_CURSES
@@ -2664,7 +2677,7 @@ void get_statline3(char *buf, struct cgpu_info *cgpu, bool for_curses, bool opt_
 	}
 	}
 	
 	
 	if (likely(cgpu->status != LIFE_DEAD2) && drv->override_statline_temp && drv->override_statline_temp(buf, cgpu, opt_show_procs))
 	if (likely(cgpu->status != LIFE_DEAD2) && drv->override_statline_temp && drv->override_statline_temp(buf, cgpu, opt_show_procs))
-		strcat(buf, " | ");
+		temperature_column_tail(&buf[strlen(buf)], for_curses, NULL);
 	else
 	else
 	{
 	{
 		float temp = cgpu->temp;
 		float temp = cgpu->temp;
@@ -2675,10 +2688,7 @@ void get_statline3(char *buf, struct cgpu_info *cgpu, bool for_curses, bool opt_
 				if (proc->temp > temp)
 				if (proc->temp > temp)
 					temp = proc->temp;
 					temp = proc->temp;
 		}
 		}
-		if (temp > 0.)
-			tailsprintf(buf, "%4.1fC | ", temp);
-		else
-			strcat(buf, "      | ");
+		temperature_column_tail(&buf[strlen(buf)], for_curses, &temp);
 	}
 	}
 	
 	
 #ifdef HAVE_CURSES
 #ifdef HAVE_CURSES
@@ -6549,10 +6559,7 @@ static void hashmeter(int thr_id, struct timeval *diff,
 		if (opt_show_procs && !opt_compact)
 		if (opt_show_procs && !opt_compact)
 			++divx;
 			++divx;
 		
 		
-		if (temp > 0.)
-			sprintf(&statusline[divx], "%4.1fC | ", temp);
-		else
-			strcpy(&statusline[divx], "      | ");
+		temperature_column_tail(&statusline[divx], true, &temp);
 		
 		
 		format_statline(&statusline[15],
 		format_statline(&statusline[15],
 		                cHr, aHr,
 		                cHr, aHr,