mirror of https://github.com/xzeldon/htop.git
incremental search and filter reintegrated!
This commit is contained in:
parent
d0c72c3fb2
commit
ade7993fcb
4
Action.c
4
Action.c
|
@ -224,13 +224,13 @@ static Htop_Reaction actionToggleTreeView(State* st) {
|
|||
|
||||
static Htop_Reaction actionIncFilter(State* st) {
|
||||
IncSet* inc = ((MainPanel*)st->panel)->inc;
|
||||
IncSet_activate(inc, INC_FILTER);
|
||||
IncSet_activate(inc, INC_FILTER, st->panel);
|
||||
st->pl->incFilter = IncSet_filter(inc);
|
||||
return HTOP_REFRESH | HTOP_KEEP_FOLLOWING;
|
||||
}
|
||||
|
||||
static Htop_Reaction actionIncSearch(State* st) {
|
||||
IncSet_activate(((MainPanel*)st->panel)->inc, INC_SEARCH);
|
||||
IncSet_activate(((MainPanel*)st->panel)->inc, INC_SEARCH, st->panel);
|
||||
return HTOP_REFRESH | HTOP_KEEP_FOLLOWING;
|
||||
}
|
||||
|
||||
|
|
35
IncSet.c
35
IncSet.c
|
@ -38,7 +38,6 @@ typedef struct IncMode_ {
|
|||
typedef struct IncSet_ {
|
||||
IncMode modes[2];
|
||||
IncMode* active;
|
||||
FunctionBar* bar;
|
||||
FunctionBar* defaultBar;
|
||||
bool filtering;
|
||||
} IncSet;
|
||||
|
@ -82,7 +81,6 @@ IncSet* IncSet_new(FunctionBar* bar) {
|
|||
IncMode_initFilter(&(this->modes[INC_FILTER]));
|
||||
this->active = NULL;
|
||||
this->filtering = false;
|
||||
this->bar = bar;
|
||||
this->defaultBar = bar;
|
||||
return this;
|
||||
}
|
||||
|
@ -137,7 +135,7 @@ bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue
|
|||
return true;
|
||||
IncMode* mode = this->active;
|
||||
int size = Panel_size(panel);
|
||||
bool filterChange = false;
|
||||
bool filterChanged = false;
|
||||
bool doSearch = true;
|
||||
if (ch == KEY_F(3)) {
|
||||
if (size == 0) return true;
|
||||
|
@ -158,14 +156,14 @@ bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue
|
|||
mode->index++;
|
||||
mode->buffer[mode->index] = 0;
|
||||
if (mode->isFilter) {
|
||||
filterChange = 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) {
|
||||
filterChange = true;
|
||||
filterChanged = true;
|
||||
if (mode->index == 0) {
|
||||
this->filtering = false;
|
||||
IncMode_reset(mode);
|
||||
|
@ -173,7 +171,7 @@ bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue
|
|||
}
|
||||
} else {
|
||||
if (mode->isFilter) {
|
||||
filterChange = true;
|
||||
filterChanged = true;
|
||||
if (ch == 27) {
|
||||
this->filtering = false;
|
||||
IncMode_reset(mode);
|
||||
|
@ -182,17 +180,17 @@ bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue
|
|||
IncMode_reset(mode);
|
||||
}
|
||||
this->active = NULL;
|
||||
this->bar = this->defaultBar;
|
||||
Panel_setDefaultBar(panel);
|
||||
FunctionBar_draw(this->defaultBar, NULL);
|
||||
doSearch = false;
|
||||
}
|
||||
if (doSearch) {
|
||||
search(mode, panel, getPanelValue);
|
||||
}
|
||||
if (filterChange && lines) {
|
||||
if (filterChanged && lines) {
|
||||
updateWeakPanel(this, panel, lines);
|
||||
}
|
||||
return filterChange;
|
||||
return filterChanged;
|
||||
}
|
||||
|
||||
const char* IncSet_getListItemValue(Panel* panel, int i) {
|
||||
|
@ -202,13 +200,24 @@ const char* IncSet_getListItemValue(Panel* panel, int i) {
|
|||
return "";
|
||||
}
|
||||
|
||||
void IncSet_activate(IncSet* this, IncType type, FunctionBar** setBar) {
|
||||
void IncSet_activate(IncSet* this, IncType type, Panel* panel) {
|
||||
this->active = &(this->modes[type]);
|
||||
this->bar = this->active->bar;
|
||||
FunctionBar_draw(this->active->bar, this->active->buffer);
|
||||
setBar =
|
||||
panel->currentBar = this->active->bar;
|
||||
}
|
||||
|
||||
void IncSet_drawBar(IncSet* this) {
|
||||
FunctionBar_draw(this->bar, this->active ? this->active->buffer : NULL);
|
||||
if (this->active) {
|
||||
FunctionBar_draw(this->active->bar, this->active->buffer);
|
||||
} else {
|
||||
FunctionBar_draw(this->defaultBar, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
int IncSet_synthesizeEvent(IncSet* this, int x) {
|
||||
if (this->active) {
|
||||
return FunctionBar_synthesizeEvent(this->active->bar, x);
|
||||
} else {
|
||||
return FunctionBar_synthesizeEvent(this->defaultBar, x);
|
||||
}
|
||||
}
|
||||
|
|
5
IncSet.h
5
IncSet.h
|
@ -33,7 +33,6 @@ typedef struct IncMode_ {
|
|||
typedef struct IncSet_ {
|
||||
IncMode modes[2];
|
||||
IncMode* active;
|
||||
FunctionBar* bar;
|
||||
FunctionBar* defaultBar;
|
||||
bool filtering;
|
||||
} IncSet;
|
||||
|
@ -49,8 +48,10 @@ bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue
|
|||
|
||||
const char* IncSet_getListItemValue(Panel* panel, int i);
|
||||
|
||||
void IncSet_activate(IncSet* this, IncType type);
|
||||
void IncSet_activate(IncSet* this, IncType type, Panel* panel);
|
||||
|
||||
void IncSet_drawBar(IncSet* this);
|
||||
|
||||
int IncSet_synthesizeEvent(IncSet* this, int x);
|
||||
|
||||
#endif
|
||||
|
|
28
MainPanel.c
28
MainPanel.c
|
@ -21,24 +21,26 @@ typedef struct MainPanel_ {
|
|||
Panel super;
|
||||
State* state;
|
||||
IncSet* inc;
|
||||
FunctionBar* fuBar;
|
||||
Htop_Action *keys;
|
||||
pid_t pidSearch;
|
||||
} MainPanel;
|
||||
|
||||
typedef bool(*MainPanel_ForeachProcessFn)(Process*, size_t);
|
||||
|
||||
#define MainPanel_getFunctionBar(this_) (((Panel*)(this_))->defaultBar)
|
||||
|
||||
}*/
|
||||
|
||||
static const char* MainFunctions[] = {"Help ", "Setup ", "Search", "Filter", "Tree ", "SortBy", "Nice -", "Nice +", "Kill ", "Quit ", NULL};
|
||||
|
||||
void MainPanel_updateTreeFunctions(MainPanel* this, bool mode) {
|
||||
FunctionBar* bar = MainPanel_getFunctionBar(this);
|
||||
if (mode) {
|
||||
FunctionBar_setLabel(this->fuBar, KEY_F(5), "Sorted");
|
||||
FunctionBar_setLabel(this->fuBar, KEY_F(6), "Collap");
|
||||
FunctionBar_setLabel(bar, KEY_F(5), "Sorted");
|
||||
FunctionBar_setLabel(bar, KEY_F(6), "Collap");
|
||||
} else {
|
||||
FunctionBar_setLabel(this->fuBar, KEY_F(5), "Tree ");
|
||||
FunctionBar_setLabel(this->fuBar, KEY_F(6), "SortBy");
|
||||
FunctionBar_setLabel(bar, KEY_F(5), "Tree ");
|
||||
FunctionBar_setLabel(bar, KEY_F(6), "SortBy");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -65,15 +67,16 @@ static HandlerResult MainPanel_eventHandler(Panel* super, int ch) {
|
|||
|
||||
Htop_Reaction reaction = HTOP_OK;
|
||||
|
||||
if (ch == 27) {
|
||||
return HANDLED;
|
||||
}
|
||||
if (ch != ERR && this->inc->active) {
|
||||
bool redraw = IncSet_handleKey(this->inc, ch, super, (IncMode_GetPanelValue) MainPanel_getValue, NULL);
|
||||
if (redraw) {
|
||||
bool filterChanged = IncSet_handleKey(this->inc, ch, super, (IncMode_GetPanelValue) MainPanel_getValue, NULL);
|
||||
if (filterChanged) {
|
||||
this->state->pl->incFilter = IncSet_filter(this->inc);
|
||||
reaction = HTOP_REFRESH | HTOP_REDRAW_BAR;
|
||||
}
|
||||
reaction |= HTOP_KEEP_FOLLOWING;
|
||||
result = HANDLED;
|
||||
} else if (ch == 27) {
|
||||
return HANDLED;
|
||||
} else if (ch != ERR && this->keys[ch]) {
|
||||
reaction |= (this->keys[ch])(this->state);
|
||||
result = HANDLED;
|
||||
|
@ -169,10 +172,9 @@ PanelClass MainPanel_class = {
|
|||
|
||||
MainPanel* MainPanel_new() {
|
||||
MainPanel* this = AllocThis(MainPanel);
|
||||
this->fuBar = FunctionBar_new(MainFunctions, NULL, NULL);
|
||||
Panel_init((Panel*) this, 1, 1, 1, 1, Class(Process), false, this->fuBar);
|
||||
Panel_init((Panel*) this, 1, 1, 1, 1, Class(Process), false, FunctionBar_new(MainFunctions, NULL, NULL));
|
||||
this->keys = calloc(KEY_MAX, sizeof(Htop_Action));
|
||||
this->inc = IncSet_new(this->fuBar);
|
||||
this->inc = IncSet_new(MainPanel_getFunctionBar(this));
|
||||
|
||||
Action_setBindings(this->keys);
|
||||
Platform_setBindings(this->keys);
|
||||
|
|
|
@ -17,13 +17,14 @@ typedef struct MainPanel_ {
|
|||
Panel super;
|
||||
State* state;
|
||||
IncSet* inc;
|
||||
FunctionBar* fuBar;
|
||||
Htop_Action *keys;
|
||||
pid_t pidSearch;
|
||||
} MainPanel;
|
||||
|
||||
typedef bool(*MainPanel_ForeachProcessFn)(Process*, size_t);
|
||||
|
||||
#define MainPanel_getFunctionBar(this_) (((Panel*)(this_))->defaultBar)
|
||||
|
||||
|
||||
void MainPanel_updateTreeFunctions(MainPanel* this, bool mode);
|
||||
|
||||
|
|
|
@ -198,7 +198,7 @@ void OpenFilesScreen_run(OpenFilesScreen* this) {
|
|||
Panel_setSelected(panel, mevent.y - panel->y + panel->scrollV);
|
||||
ch = 0;
|
||||
} if (mevent.y == LINES - 1)
|
||||
ch = FunctionBar_synthesizeEvent(inc->bar, mevent.x);
|
||||
ch = IncSet_synthesizeEvent(inc, mevent.x);
|
||||
}
|
||||
|
||||
if (inc->active) {
|
||||
|
@ -211,11 +211,11 @@ void OpenFilesScreen_run(OpenFilesScreen* this) {
|
|||
continue;
|
||||
case KEY_F(3):
|
||||
case '/':
|
||||
IncSet_activate(inc, INC_SEARCH);
|
||||
IncSet_activate(inc, INC_SEARCH, panel);
|
||||
break;
|
||||
case KEY_F(4):
|
||||
case '\\':
|
||||
IncSet_activate(inc, INC_FILTER);
|
||||
IncSet_activate(inc, INC_FILTER, panel);
|
||||
break;
|
||||
case KEY_F(5):
|
||||
clear();
|
||||
|
|
2
Panel.c
2
Panel.c
|
@ -67,6 +67,8 @@ struct Panel_ {
|
|||
RichString header;
|
||||
};
|
||||
|
||||
#define Panel_setDefaultBar(this_) do{ (this_)->currentBar = (this_)->defaultBar; }while(0)
|
||||
|
||||
}*/
|
||||
|
||||
#ifndef MIN
|
||||
|
|
2
Panel.h
2
Panel.h
|
@ -56,6 +56,8 @@ struct Panel_ {
|
|||
RichString header;
|
||||
};
|
||||
|
||||
#define Panel_setDefaultBar(this_) do{ (this_)->currentBar = (this_)->defaultBar; }while(0)
|
||||
|
||||
|
||||
#ifndef MIN
|
||||
#define MIN(a,b) ((a)<(b)?(a):(b))
|
||||
|
|
|
@ -156,11 +156,16 @@ static void ScreenManager_drawPanels(ScreenManager* this, int focus) {
|
|||
}
|
||||
}
|
||||
|
||||
static Panel* setCurrentPanel(Panel* panel) {
|
||||
FunctionBar_draw(panel->currentBar, NULL);
|
||||
return panel;
|
||||
}
|
||||
|
||||
void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
|
||||
bool quit = false;
|
||||
int focus = 0;
|
||||
|
||||
Panel* panelFocus = (Panel*) Vector_get(this->panels, focus);
|
||||
Panel* panelFocus = setCurrentPanel((Panel*) Vector_get(this->panels, focus));
|
||||
|
||||
double oldTime = 0.0;
|
||||
|
||||
|
@ -180,7 +185,6 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
|
|||
|
||||
if (redraw) {
|
||||
ScreenManager_drawPanels(this, focus);
|
||||
FunctionBar_draw(panelFocus->currentBar, NULL);
|
||||
}
|
||||
|
||||
int prevCh = ch;
|
||||
|
@ -199,7 +203,7 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
|
|||
mevent.y > panel->y && mevent.y <= panel->y+panel->h &&
|
||||
(this->allowFocusChange || panelFocus == panel) ) {
|
||||
focus = i;
|
||||
panelFocus = panel;
|
||||
panelFocus = setCurrentPanel(panel);
|
||||
Panel_setSelected(panel, mevent.y - panel->y + panel->scrollV - 1);
|
||||
break;
|
||||
}
|
||||
|
@ -255,7 +259,7 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
|
|||
tryLeft:
|
||||
if (focus > 0)
|
||||
focus--;
|
||||
panelFocus = (Panel*) Vector_get(this->panels, focus);
|
||||
panelFocus = setCurrentPanel((Panel*) Vector_get(this->panels, focus));
|
||||
if (Panel_size(panelFocus) == 0 && focus > 0)
|
||||
goto tryLeft;
|
||||
break;
|
||||
|
@ -267,7 +271,7 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
|
|||
tryRight:
|
||||
if (focus < this->panelCount - 1)
|
||||
focus++;
|
||||
panelFocus = (Panel*) Vector_get(this->panels, focus);
|
||||
panelFocus = setCurrentPanel((Panel*) Vector_get(this->panels, focus));
|
||||
if (Panel_size(panelFocus) == 0 && focus < this->panelCount - 1)
|
||||
goto tryRight;
|
||||
break;
|
||||
|
|
|
@ -79,7 +79,6 @@ static inline void appendLine(const char* line, Vector* lines, Panel* panel, con
|
|||
}
|
||||
|
||||
void TraceScreen_run(TraceScreen* this) {
|
||||
// if (this->process->pid == getpid()) return;
|
||||
char buffer[1001];
|
||||
int fdpair[2];
|
||||
int err = pipe(fdpair);
|
||||
|
@ -167,7 +166,7 @@ void TraceScreen_run(TraceScreen* this) {
|
|||
follow = false;
|
||||
ch = 0;
|
||||
} if (mevent.y == LINES - 1)
|
||||
ch = FunctionBar_synthesizeEvent(inc->bar, mevent.x);
|
||||
ch = IncSet_synthesizeEvent(inc, mevent.x);
|
||||
}
|
||||
|
||||
if (inc->active) {
|
||||
|
@ -186,11 +185,11 @@ void TraceScreen_run(TraceScreen* this) {
|
|||
break;
|
||||
case KEY_F(3):
|
||||
case '/':
|
||||
IncSet_activate(inc, INC_SEARCH);
|
||||
IncSet_activate(inc, INC_SEARCH, panel);
|
||||
break;
|
||||
case KEY_F(4):
|
||||
case '\\':
|
||||
IncSet_activate(inc, INC_FILTER);
|
||||
IncSet_activate(inc, INC_FILTER, panel);
|
||||
break;
|
||||
case 'f':
|
||||
case KEY_F(8):
|
||||
|
|
Loading…
Reference in New Issue