Fixes for overwriting console output

This commit is contained in:
moosecrap 2025-04-09 08:16:02 -07:00
parent a9f8754922
commit 01ec0e0163

View File

@ -204,8 +204,10 @@ int main (int argc, char **argv)
/* print sensor info */ /* print sensor info */
if (print_info) { if (print_info) {
do { do {
if (overwrite) if (overwrite) {
printf("\x1b[?25l"); /* Hide cursor */
printf("\x1b[K"); /* Clear current console line */ printf("\x1b[K"); /* Clear current console line */
}
if (print_board_sensors) if (print_board_sensors)
print_board_info(board_sensors, board_sensor_count); print_board_info(board_sensors, board_sensor_count);
@ -224,14 +226,17 @@ int main (int argc, char **argv)
if (!overwrite) if (!overwrite)
printf("\n"); /* Print line break at the end for continuous output */ printf("\n"); /* Print line break at the end for continuous output */
if (overwrite && compact) {
printf("\x1b[1G"); /* Move cursor back to column 1 */
if (gpu_count > 1 || print_board_sensors)
printf("\x1b[%dA", gpu_count-1+print_board_sensors); /* Move cursor back up to the top of gpu list */
}
fflush(stdout); fflush(stdout);
sleep(watch); sleep(watch);
if (overwrite && compact) {
printf("\x1b[1G"); /* Move cursor back to column 1 */
for (int i = 0; i < gpu_count+print_board_sensors; i++) {
printf("\x1b[K"); /* Clear current console line */
printf("\x1b[1A"); /* Move cursor up one line */
}
}
} while (watch > 0); } while (watch > 0);
} }