From 65357c8c46154de4e4eca14075bfe5523bb5fc14 Mon Sep 17 00:00:00 2001 From: Daniel Lange Date: Mon, 7 Dec 2020 10:26:01 +0100 Subject: New upstream version 3.0.3 --- IncSet.c | 77 +++++++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 50 insertions(+), 27 deletions(-) (limited to 'IncSet.c') diff --git a/IncSet.c b/IncSet.c index e9e2893..d280caf 100644 --- a/IncSet.c +++ b/IncSet.c @@ -1,17 +1,24 @@ /* htop - IncSet.c (C) 2005-2012 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ +#include "config.h" // IWYU pragma: keep + #include "IncSet.h" -#include "StringUtils.h" -#include "ListItem.h" -#include "CRT.h" + +#include #include #include +#include "CRT.h" +#include "ListItem.h" +#include "Object.h" +#include "ProvideCurses.h" +#include "XUtils.h" + static void IncMode_reset(IncMode* mode) { mode->index = 0; @@ -72,7 +79,10 @@ static void updateWeakPanel(IncSet* this, Panel* panel, Vector* lines) { ListItem* line = (ListItem*)Vector_get(lines, i); if (String_contains_i(line->value, incFilter)) { Panel_add(panel, (Object*)line); - if (selected == (Object*)line) Panel_setSelected(panel, n); + if (selected == (Object*)line) { + Panel_setSelected(panel, n); + } + n++; } } @@ -80,7 +90,9 @@ static void updateWeakPanel(IncSet* this, Panel* panel, Vector* lines) { for (int i = 0; i < Vector_size(lines); i++) { Object* line = Vector_get(lines, i); Panel_add(panel, line); - if (selected == line) Panel_setSelected(panel, i); + if (selected == line) { + Panel_setSelected(panel, i); + } } } } @@ -95,10 +107,11 @@ static bool search(IncMode* mode, Panel* panel, IncMode_GetPanelValue getPanelVa break; } } - if (found) - FunctionBar_draw(mode->bar, mode->buffer); - else - FunctionBar_drawAttr(mode->bar, mode->buffer, CRT_colors[FAILED_SEARCH]); + + FunctionBar_drawExtra(mode->bar, + mode->buffer, + found ? -1 : CRT_colors[FAILED_SEARCH], + true); return found; } @@ -106,11 +119,18 @@ static bool IncMode_find(IncMode* mode, Panel* panel, IncMode_GetPanelValue getP int size = Panel_size(panel); int here = Panel_getSelectedIndex(panel); int i = here; - for(;;) { - i+=step; - if (i == size) i = 0; - if (i == -1) i = size - 1; - if (i == here) return false; + for (;;) { + i += step; + if (i == size) { + i = 0; + } + if (i == -1) { + i = size - 1; + } + if (i == here) { + return false; + } + if (String_contains_i(getPanelValue(panel, i), mode->buffer)) { Panel_setSelected(panel, i); return true; @@ -129,22 +149,27 @@ bool IncSet_prev(IncSet* this, IncType type, Panel* panel, IncMode_GetPanelValue bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue getPanelValue, Vector* lines) { if (ch == ERR) return true; + IncMode* mode = this->active; int size = Panel_size(panel); bool filterChanged = false; bool doSearch = true; if (ch == KEY_F(3)) { - if (size == 0) return true; + if (size == 0) + return true; + IncMode_find(mode, panel, getPanelValue, 1); doSearch = false; - } else if (ch < 255 && isprint((char)ch)) { + } else if (0 < ch && ch < 255 && isprint((unsigned char)ch)) { if (mode->index < INCMODE_MAX) { mode->buffer[mode->index] = ch; mode->index++; mode->buffer[mode->index] = 0; if (mode->isFilter) { filterChanged = true; - if (mode->index == 1) this->filtering = true; + if (mode->index == 1) { + this->filtering = true; + } } } } else if ((ch == KEY_BACKSPACE || ch == 127)) { @@ -162,7 +187,7 @@ bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue doSearch = false; } } else if (ch == KEY_RESIZE) { - Panel_resize(panel, COLS, LINES-panel->y-1); + Panel_resize(panel, COLS, LINES - panel->y - 1); } else { if (mode->isFilter) { filterChanged = true; @@ -177,7 +202,7 @@ bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue } this->active = NULL; Panel_setDefaultBar(panel); - FunctionBar_draw(this->defaultBar, NULL); + FunctionBar_draw(this->defaultBar); doSearch = false; } if (doSearch) { @@ -191,22 +216,20 @@ bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue const char* IncSet_getListItemValue(Panel* panel, int i) { ListItem* l = (ListItem*) Panel_get(panel, i); - if (l) - return l->value; - return ""; + return l ? l->value : ""; } void IncSet_activate(IncSet* this, IncType type, Panel* panel) { this->active = &(this->modes[type]); - FunctionBar_draw(this->active->bar, this->active->buffer); + FunctionBar_drawExtra(this->active->bar, this->active->buffer, -1, true); panel->currentBar = this->active->bar; } -void IncSet_drawBar(IncSet* this) { +void IncSet_drawBar(const IncSet* this) { if (this->active) { - FunctionBar_draw(this->active->bar, this->active->buffer); + FunctionBar_drawExtra(this->active->bar, this->active->buffer, -1, true); } else { - FunctionBar_draw(this->defaultBar, NULL); + FunctionBar_draw(this->defaultBar); } } -- cgit v1.2.3