From 5d2f7420c32d69b70f23e002385d9d97dcaab305 Mon Sep 17 00:00:00 2001 From: cpalv Date: Tue, 23 May 2023 19:06:50 -0500 Subject: [PATCH 1/2] update cpu load average display --- src/btop_draw.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/btop_draw.cpp b/src/btop_draw.cpp index 4ecd294..774f310 100644 --- a/src/btop_draw.cpp +++ b/src/btop_draw.cpp @@ -495,6 +495,7 @@ namespace Cpu { int b_columns, b_column_size; int b_x, b_y, b_width, b_height; int graph_up_height; + long unsigned int lavg_str_len = 0; bool shown = true, redraw = true, mid_line = false; string box; Draw::Graph graph_upper; @@ -701,7 +702,22 @@ namespace Cpu { for (const auto& val : cpu.load_avg) { lavg += string(sep, ' ') + (lavg_pre.size() < 3 ? to_string((int)round(val)) : to_string(val).substr(0, 4)); } - out += Mv::to(b_y + b_height - 2, b_x + cx + 1) + Theme::c("main_fg") + lavg_pre + lavg; + + string lavg_str = Mv::to(b_y + b_height - 2, b_x + cx + 1) + Theme::c("main_fg") + lavg_pre + lavg; + // if previous load average string is longer than current + // then right pad the current string with spaces until + // the current string is the same length as the previous + // otherwise set the lavg_str_len. + // + // When a shorter string gets written, the remaining characters + // from the previous string get left behind. This "erases" the + // leftover characters from the previous string. + if (lavg_str_len > lavg_str.length()) { + lavg_str += string(lavg_str_len - lavg_str.length(), ' '); + } else { + lavg_str_len = lavg_str.length(); + } + out += lavg_str; } redraw = false; From 1039bd5b5d32796c4acaff6aa973ba64388e0758 Mon Sep 17 00:00:00 2001 From: cpalv Date: Wed, 24 May 2023 19:51:43 -0500 Subject: [PATCH 2/2] amend! update cpu load average display update cpu load average display applied suggested changes --- src/btop_draw.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/btop_draw.cpp b/src/btop_draw.cpp index 774f310..2352b09 100644 --- a/src/btop_draw.cpp +++ b/src/btop_draw.cpp @@ -703,7 +703,7 @@ namespace Cpu { lavg += string(sep, ' ') + (lavg_pre.size() < 3 ? to_string((int)round(val)) : to_string(val).substr(0, 4)); } - string lavg_str = Mv::to(b_y + b_height - 2, b_x + cx + 1) + Theme::c("main_fg") + lavg_pre + lavg; + string lavg_str = lavg_pre + lavg; // if previous load average string is longer than current // then right pad the current string with spaces until // the current string is the same length as the previous @@ -717,7 +717,7 @@ namespace Cpu { } else { lavg_str_len = lavg_str.length(); } - out += lavg_str; + out += Mv::to(b_y + b_height - 2, b_x + cx + 1) + Theme::c("main_fg") + lavg_str; } redraw = false;