@@ -522,6 +522,7 @@ namespace Cpu {
522522 int b_columns, b_column_size;
523523 int b_x, b_y, b_width, b_height;
524524 float max_observed_pwr = 1 .0f ;
525+ float last_valid_cpu_watts = 0 .0f ;
525526
526527 int graph_up_height, graph_low_height;
527528 int graph_up_width, graph_low_width;
@@ -846,11 +847,14 @@ namespace Cpu {
846847 }
847848
848849 if (show_watts) {
849- string cwatts = fmt::format (" {:>4.{}f}" , cpu.usage_watts , cpu.usage_watts < 10 .0f ? 2 : cpu.usage_watts < 100 .0f ? 1 : 0 );
850- string cwatts_post = " W" ;
851-
852- max_observed_pwr = max (max_observed_pwr, cpu.usage_watts );
853- out += Theme::g (" cached" ).at (clamp (cpu.usage_watts / max_observed_pwr * 100 .0f , 0 .0f , 100 .0f )) + cwatts + Theme::c (" main_fg" ) + cwatts_post;
850+ const auto watts_error = cpu.usage_watts < 0 .0f or cpu.usage_watts > 9'999 .0f ;
851+ last_valid_cpu_watts = watts_error ? last_valid_cpu_watts : cpu.usage_watts ;
852+ max_observed_pwr = max (max_observed_pwr, last_valid_cpu_watts);
853+ fmt::format_to (std::back_inserter (out), " {watts_color}{cwatts:>4.{precision}f}{main_fg}W" ,
854+ " watts_color" _a = Theme::g (" cached" ).at (clamp (last_valid_cpu_watts / max_observed_pwr * 100 .0f , 0 .0f , 100 .0f )),
855+ " cwatts" _a = last_valid_cpu_watts,
856+ " precision" _a = last_valid_cpu_watts < 9 .995f ? 2 : last_valid_cpu_watts < 99 .95f ? 1 : 0 ,
857+ " main_fg" _a = Theme::c (" main_fg" ));
854858 }
855859
856860 out += Theme::c (" div_line" ) + Symbols::v_line;
0 commit comments