@@ -16,12 +16,13 @@ indent = tab
1616tab-size = 4
1717*/
1818
19- #include < array>
2019#include < algorithm>
20+ #include < array>
2121#include < cmath>
2222#include < ranges>
2323#include < stdexcept>
2424#include < string>
25+ #include < string_view>
2526#include < utility>
2627
2728#include " btop_draw.hpp"
@@ -31,6 +32,7 @@ tab-size = 4
3132#include " btop_tools.hpp"
3233#include " btop_input.hpp"
3334#include " btop_menu.hpp"
35+ #include < fmt/format.h>
3436
3537
3638using std::array;
@@ -146,12 +148,12 @@ namespace Draw {
146148 }
147149
148150 TextEdit::TextEdit () {}
149- TextEdit::TextEdit (string text, bool numeric) : numeric(numeric), text(text) {
151+ TextEdit::TextEdit (string text, bool numeric) : numeric(numeric), text(std::move( text) ) {
150152 pos = this ->text .size ();
151153 upos = ulen (this ->text );
152154 }
153155
154- bool TextEdit::command (const string& key) {
156+ bool TextEdit::command (const std::string_view key) {
155157 if (key == " left" and upos > 0 ) {
156158 upos--;
157159 pos = uresize (text, upos).size ();
@@ -193,7 +195,7 @@ namespace Draw {
193195 upos++;
194196 }
195197 else {
196- const string first = uresize (text, upos) + key;
198+ const auto first = fmt::format ( " {}{} " , uresize (text, upos), key) ;
197199 text = first + text.substr (pos);
198200 upos++;
199201 pos = first.size ();
@@ -245,9 +247,10 @@ namespace Draw {
245247 this ->text .clear ();
246248 }
247249
248- string createBox (const int x, const int y, const int width,
249- const int height, string line_color, bool fill,
250- const string title, const string title2, const int num) {
250+ string createBox (
251+ const int x, const int y, const int width, const int height, string line_color, bool fill, const std::string_view title,
252+ const std::string_view title2, const int num
253+ ) {
251254 string out;
252255
253256 if (line_color.empty ())
@@ -283,12 +286,16 @@ namespace Draw {
283286
284287 // ? Draw titles if defined
285288 if (not title.empty ()) {
286- out += Mv::to (y, x + 2 ) + Symbols::title_left + Fx::b + numbering + Theme::c (" title" ) + title
287- + Fx::ub + line_color + Symbols::title_right;
289+ out += fmt::format (
290+ " {}{}{}{}{}{}{}{}{}" , Mv::to (y, x + 2 ), Symbols::title_left, Fx::b, numbering, Theme::c (" title" ), title, Fx::ub,
291+ line_color, Symbols::title_right
292+ );
288293 }
289294 if (not title2.empty ()) {
290- out += Mv::to (y + height - 1 , x + 2 ) + Symbols::title_left_down + Fx::b + numbering + Theme::c (" title" ) + title2
291- + Fx::ub + line_color + Symbols::title_right_down;
295+ out += fmt::format (
296+ " {}{}{}{}{}{}{}{}{}" , Mv::to (y, x + 2 ), Symbols::title_left, Fx::b, numbering, Theme::c (" title" ), title2, Fx::ub,
297+ line_color, Symbols::title_right_down
298+ );
292299 }
293300
294301 return out + Fx::reset + Mv::to (y + 1 , x + 1 );
@@ -1229,7 +1236,7 @@ namespace Mem {
12291236 out += Mv::to (y + 1 , x + 2 ) + Theme::c (" title" ) + Fx::b + " Total:" + rjust (floating_humanizer (totalMem), mem_width - 9 ) + Fx::ub + Theme::c (" main_fg" );
12301237 vector<string> comb_names (mem_names.begin (), mem_names.end ());
12311238 if (show_swap and has_swap and not swap_disk) comb_names.insert (comb_names.end (), swap_names.begin (), swap_names.end ());
1232- for (auto name : comb_names) {
1239+ for (const auto & name : comb_names) {
12331240 if (cy > height - 4 ) break ;
12341241 string title;
12351242 if (name == " swap_used" ) {
@@ -1482,7 +1489,7 @@ namespace Proc {
14821489
14831490 string box;
14841491
1485- int selection (const string& cmd_key) {
1492+ int selection (const std::string_view cmd_key) {
14861493 auto start = Config::getI (" proc_start" );
14871494 auto selected = Config::getI (" proc_selected" );
14881495 auto last_selected = Config::getI (" proc_last_selected" );
@@ -1526,7 +1533,7 @@ namespace Proc {
15261533 if (selected > 0 ) selected = select_max;
15271534 }
15281535 else if (cmd_key.starts_with (" mousey" )) {
1529- int mouse_y = std::stoi (cmd_key.substr (6 ));
1536+ int mouse_y = std::atoi (cmd_key.substr (6 ). data ( ));
15301537 start = clamp ((int )round ((double )mouse_y * (numpids - select_max - 2 ) / (select_max - 2 )), 0 , max (0 , numpids - select_max));
15311538 }
15321539
0 commit comments