Fixed: Menu size and preset size issues and added warnings for small terminal size

This commit is contained in:
aristocratos 2021-09-20 18:20:30 +02:00
parent 85f945ada0
commit af465b5b84
5 changed files with 53 additions and 2 deletions

View file

@ -2,6 +2,8 @@
* Fixed: ARCH detection in Makefile
* Fixed: Color gradient array out of bounds, added clamp 0-100 for cpu percent values
## v1.0.1
* Fixed: UTF-8 check to include UTF8

View file

@ -306,15 +306,26 @@ namespace Config {
//* Apply selected preset
void apply_preset(const string& preset) {
string boxes;
for (const auto& box : ssplit(preset, ',')) {
const auto& vals = ssplit(box, ':');
boxes += vals.at(0) + ' ';
}
if (not boxes.empty()) boxes.pop_back();
auto min_size = Term::get_min_size(boxes);
if (Term::width < min_size.at(0) or Term::height < min_size.at(1)) {
return;
}
for (const auto& box : ssplit(preset, ',')) {
const auto& vals = ssplit(box, ':');
if (vals.at(0) == "cpu") set("cpu_bottom", (vals.at(1) == "0" ? false : true));
else if (vals.at(0) == "mem") set("mem_below_net", (vals.at(1) == "0" ? false : true));
else if (vals.at(0) == "proc") set("proc_left", (vals.at(1) == "0" ? false : true));
set("graph_symbol_" + vals.at(0), vals.at(2));
}
if (not boxes.empty()) boxes.pop_back();
if (check_boxes(boxes)) set("shown_boxes", boxes);
}
@ -475,6 +486,7 @@ namespace Config {
}
void toggle_box(const string& box) {
auto old_boxes = current_boxes;
auto box_pos = rng::find(current_boxes, box);
if (box_pos == current_boxes.end())
current_boxes.push_back(box);
@ -486,6 +498,14 @@ namespace Config {
for (const auto& b : current_boxes) new_boxes += b + ' ';
new_boxes.pop_back();
}
auto min_size = Term::get_min_size(new_boxes);
if (Term::width < min_size.at(0) or Term::height < min_size.at(1)) {
current_boxes = old_boxes;
return;
}
Config::set("shown_boxes", new_boxes);
}

View file

@ -351,7 +351,6 @@ namespace Input {
return;
}
else if (key == "s" and (Config::getB("show_detailed") or Config::getI("selected_pid") > 0)) {
if (Term::width < 80 or Term::height < 20) return;
atomic_wait(Runner::active);
if (Config::getB("show_detailed") and Config::getI("proc_selected") == 0 and Proc::detailed.status == "Dead") return;
Menu::show(Menu::Menus::SignalChoose);

View file

@ -757,6 +757,28 @@ namespace Menu {
return (redraw ? Changed : retval);
}
int sizeError(const string& key) {
if (redraw) {
vector<string> cont_vec;
cont_vec.push_back(Fx::b + Theme::g("used")[100] + "Error:" + Theme::c("main_fg") + Fx::ub);
cont_vec.push_back("Terminal size to small to" + Fx::reset);
cont_vec.push_back("display menu or box!" + Fx::reset);
messageBox = Menu::msgBox{45, 0, cont_vec, "error"};
Global::overlay = messageBox();
}
auto ret = messageBox.input(key);
if (ret == msgBox::Ok_Yes or ret == msgBox::No_Esc) {
messageBox.clear();
return Closed;
}
else if (redraw) {
return Changed;
}
return NoChange;
}
int signalSend(const string& key) {
auto& s_pid = (Config::getB("show_detailed") and Config::getI("selected_pid") == 0 ? Config::getI("detailed_pid") : Config::getI("selected_pid"));
if (s_pid == 0) return Closed;
@ -1286,6 +1308,7 @@ namespace Menu {
//* Add menus here and update enum Menus in header
const auto menuFunc = vector{
ref(sizeError),
ref(signalChoose),
ref(signalSend),
ref(signalReturn),
@ -1312,6 +1335,12 @@ namespace Menu {
if (currentMenu < 0 or not menuMask.test(currentMenu)) {
Menu::active = true;
redraw = true;
if (((menuMask.test(Main) or menuMask.test(Options) or menuMask.test(Help) or menuMask.test(SignalChoose))
and (Term::width < 80 or Term::height < 24))
or (Term::width < 50 or Term::height < 20)) {
menuMask.reset();
menuMask.set(SizeError);
}
for (const auto& i : iota(0, (int)menuMask.size())) {
if (menuMask.test(i)) currentMenu = i;
}

View file

@ -69,6 +69,7 @@ namespace Menu {
//* Enum for functions in vector menuFuncs
enum Menus {
SizeError,
SignalChoose,
SignalSend,
SignalReturn,