Skip to content

Commit da6ccd7

Browse files
committed
add proc width percentage to presets
1 parent 732ed71 commit da6ccd7

3 files changed

Lines changed: 15 additions & 4 deletions

File tree

src/btop_config.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,9 @@ namespace Config {
7373

7474
{"presets", "#* Define presets for the layout of the boxes. Preset 0 is always all boxes shown with default settings. Max 9 presets.\n"
7575
"#* Format: \"box_name:P:G,box_name:P:G\" P=(0 or 1) for alternate positions, G=graph symbol to use for box.\n"
76+
"#* proc box format can also be \"proc:P:G:W\" W=(0-100) for proc width percentage.\n"
7677
"#* Use whitespace \" \" as separator between different presets.\n"
77-
"#* Example: \"cpu:0:default,mem:0:tty,proc:1:default cpu:0:braille,proc:0:tty\""},
78+
"#* Example: \"cpu:0:default,mem:0:tty,proc:1:default:80 cpu:0:braille,proc:0:tty\""},
7879

7980
{"vim_keys", "#* Set to True to enable \"h,j,k,l,g,G\" keys for directional control in lists.\n"
8081
"#* Conflicting keys for h:\"help\" and k:\"kill\" is accessible while holding shift."},
@@ -468,7 +469,7 @@ namespace Config {
468469
return false;
469470
}
470471
const auto& vals = ssplit(box, ':');
471-
if (vals.size() != 3) {
472+
if (vals.size() != 3 and not (vals.size() == 4 and vals.at(0) == "proc")) {
472473
validError = "Malformatted preset in config value presets!";
473474
return false;
474475
}
@@ -484,6 +485,10 @@ namespace Config {
484485
validError = "Invalid graph name in config value presets!";
485486
return false;
486487
}
488+
if (vals.size() == 4 and not (vals.at(3) == "default" or intValid("", vals.at(3)))) {
489+
validError = "Invalid proc width percent in config value presets!";
490+
return false;
491+
}
487492
}
488493
new_presets.push_back(preset);
489494
}
@@ -515,6 +520,7 @@ namespace Config {
515520
set("mem_below_net", (vals.at(1) != "0"));
516521
} else if (vals.at(0) == "proc") {
517522
set("proc_left", (vals.at(1) != "0"));
523+
set("proc_box_width_percent", (vals.size() == 4 and vals.at(3) != "default") ? std::clamp(stoi(vals.at(3)), 0, 100) : Proc::width_p);
518524
}
519525
if (vals.at(0).starts_with("gpu")) {
520526
set("graph_symbol_gpu", vals.at(2));

src/btop_input.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ namespace Input {
313313
new_proc_box_width_percent = Proc::width_p; // set to default width
314314

315315
if (proc_box_width_percent != new_proc_box_width_percent) {
316-
Config::current_preset = -1;
316+
Config::current_preset.reset();
317317
Config::set("proc_box_width_percent", new_proc_box_width_percent);
318318
Draw::calcSizes(!Proc::shown);
319319
Draw::update_clock(true);

src/btop_menu.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,11 +291,14 @@ namespace Menu {
291291
"P=(0 or 1) for alternate positions.",
292292
"G=graph symbol to use for box.",
293293
"",
294+
"proc box format can also be \"proc:P:G:W\"",
295+
"W=(0 - 100) for box width percentage.\n",
296+
"",
294297
"Use whitespace \" \" as separator between",
295298
"different presets.",
296299
"",
297300
"Example:",
298-
"\"mem:0:tty,proc:1:default cpu:0:braille\""},
301+
"\"mem:0:tty,proc:1:default:80 cpu:0:braille\""},
299302
{"shown_boxes",
300303
"Manually set which boxes to show.",
301304
"",
@@ -1388,6 +1391,7 @@ static int optionsMenu(const string& key) {
13881391
if (option == "proc_box_width_percent") {
13891392
editor.text = fmt::format("{}", std::clamp(stoi(editor.text), 0, 100));
13901393
screen_redraw = true;
1394+
Config::current_preset.reset();
13911395
}
13921396
Config::set(option, stoi(editor.text));
13931397
}
@@ -1477,6 +1481,7 @@ static int optionsMenu(const string& key) {
14771481
if (option == "proc_box_width_percent") {
14781482
value = std::clamp(static_cast<int>(value), 0, 100);
14791483
screen_redraw = true;
1484+
Config::current_preset.reset();
14801485
}
14811486
Config::set(option, static_cast<int>(value));
14821487
}

0 commit comments

Comments
 (0)