Auto-follow process after a search.

See #237.
This commit is contained in:
Hisham 2016-05-05 10:30:06 -03:00
parent d464be13db
commit 572546f806
5 changed files with 34 additions and 20 deletions

View File

@ -328,7 +328,7 @@ static Htop_Reaction actionFilterByUser(State* st) {
return HTOP_REFRESH | HTOP_REDRAW_BAR | HTOP_UPDATE_PANELHDR; return HTOP_REFRESH | HTOP_REDRAW_BAR | HTOP_UPDATE_PANELHDR;
} }
static Htop_Reaction actionFollow(State* st) { Htop_Reaction Action_follow(State* st) {
st->pl->following = MainPanel_selectedPid((MainPanel*)st->panel); st->pl->following = MainPanel_selectedPid((MainPanel*)st->panel);
Panel_setSelectionColor(st->panel, CRT_colors[PANEL_SELECTION_FOLLOW]); Panel_setSelectionColor(st->panel, CRT_colors[PANEL_SELECTION_FOLLOW]);
return HTOP_KEEP_FOLLOWING; return HTOP_KEEP_FOLLOWING;
@ -557,7 +557,7 @@ void Action_setBindings(Htop_Action* keys) {
keys['='] = actionExpandOrCollapse; keys['='] = actionExpandOrCollapse;
keys['-'] = actionExpandOrCollapse; keys['-'] = actionExpandOrCollapse;
keys['u'] = actionFilterByUser; keys['u'] = actionFilterByUser;
keys['F'] = actionFollow; keys['F'] = Action_follow;
keys['S'] = actionSetup; keys['S'] = actionSetup;
keys['C'] = actionSetup; keys['C'] = actionSetup;
keys[KEY_F(2)] = actionSetup; keys[KEY_F(2)] = actionSetup;

View File

@ -49,6 +49,8 @@ Htop_Reaction Action_setSortKey(Settings* settings, ProcessField sortKey);
// ---------------------------------------- // ----------------------------------------
Htop_Reaction Action_follow(State* st);
void Action_setBindings(Htop_Action* keys); void Action_setBindings(Htop_Action* keys);

View File

@ -40,6 +40,7 @@ typedef struct IncSet_ {
IncMode* active; IncMode* active;
FunctionBar* defaultBar; FunctionBar* defaultBar;
bool filtering; bool filtering;
bool found;
} IncSet; } IncSet;
typedef const char* (*IncMode_GetPanelValue)(Panel*, int); typedef const char* (*IncMode_GetPanelValue)(Panel*, int);
@ -114,7 +115,7 @@ static void updateWeakPanel(IncSet* this, Panel* panel, Vector* lines) {
} }
} }
static void search(IncMode* mode, Panel* panel, IncMode_GetPanelValue getPanelValue) { static bool search(IncMode* mode, Panel* panel, IncMode_GetPanelValue getPanelValue) {
int size = Panel_size(panel); int size = Panel_size(panel);
bool found = false; bool found = false;
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
@ -128,6 +129,7 @@ static void search(IncMode* mode, Panel* panel, IncMode_GetPanelValue getPanelVa
FunctionBar_draw(mode->bar, mode->buffer); FunctionBar_draw(mode->bar, mode->buffer);
else else
FunctionBar_drawAttr(mode->bar, mode->buffer, CRT_colors[FAILED_SEARCH]); FunctionBar_drawAttr(mode->bar, mode->buffer, CRT_colors[FAILED_SEARCH]);
return found;
} }
bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue getPanelValue, Vector* lines) { bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue getPanelValue, Vector* lines) {
@ -151,24 +153,30 @@ bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue
} }
} }
doSearch = false; doSearch = false;
} else if (ch < 255 && isprint((char)ch) && (mode->index < INCMODE_MAX)) { } else if (ch < 255 && isprint((char)ch)) {
mode->buffer[mode->index] = ch; if (mode->index < INCMODE_MAX) {
mode->index++; mode->buffer[mode->index] = ch;
mode->buffer[mode->index] = 0; mode->index++;
if (mode->isFilter) { mode->buffer[mode->index] = 0;
filterChanged = true; if (mode->isFilter) {
if (mode->index == 1) this->filtering = true; filterChanged = true;
} if (mode->index == 1) this->filtering = true;
} else if ((ch == KEY_BACKSPACE || ch == 127) && (mode->index > 0)) {
mode->index--;
mode->buffer[mode->index] = 0;
if (mode->isFilter) {
filterChanged = true;
if (mode->index == 0) {
this->filtering = false;
IncMode_reset(mode);
} }
} }
} else if ((ch == KEY_BACKSPACE || ch == 127)) {
if (mode->index > 0) {
mode->index--;
mode->buffer[mode->index] = 0;
if (mode->isFilter) {
filterChanged = true;
if (mode->index == 0) {
this->filtering = false;
IncMode_reset(mode);
}
}
} else {
doSearch = false;
}
} else if (ch == KEY_RESIZE) { } else if (ch == KEY_RESIZE) {
Panel_resize(panel, COLS, LINES-panel->y-1); Panel_resize(panel, COLS, LINES-panel->y-1);
} else { } else {
@ -187,7 +195,7 @@ bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue
doSearch = false; doSearch = false;
} }
if (doSearch) { if (doSearch) {
search(mode, panel, getPanelValue); this->found = search(mode, panel, getPanelValue);
} }
if (filterChanged && lines) { if (filterChanged && lines) {
updateWeakPanel(this, panel, lines); updateWeakPanel(this, panel, lines);

View File

@ -35,6 +35,7 @@ typedef struct IncSet_ {
IncMode* active; IncMode* active;
FunctionBar* defaultBar; FunctionBar* defaultBar;
bool filtering; bool filtering;
bool found;
} IncSet; } IncSet;
typedef const char* (*IncMode_GetPanelValue)(Panel*, int); typedef const char* (*IncMode_GetPanelValue)(Panel*, int);

View File

@ -83,6 +83,9 @@ static HandlerResult MainPanel_eventHandler(Panel* super, int ch) {
result = HANDLED; result = HANDLED;
} else if (ch != ERR && this->inc->active) { } else if (ch != ERR && this->inc->active) {
bool filterChanged = IncSet_handleKey(this->inc, ch, super, (IncMode_GetPanelValue) MainPanel_getValue, NULL); bool filterChanged = IncSet_handleKey(this->inc, ch, super, (IncMode_GetPanelValue) MainPanel_getValue, NULL);
if (this->inc->found) {
reaction |= Action_follow(this->state);
}
if (filterChanged) { if (filterChanged) {
this->state->pl->incFilter = IncSet_filter(this->inc); this->state->pl->incFilter = IncSet_filter(this->inc);
reaction = HTOP_REFRESH | HTOP_REDRAW_BAR; reaction = HTOP_REFRESH | HTOP_REDRAW_BAR;