mirror of https://github.com/xzeldon/htop.git
Merge branch 'hishamhm-pull-850'
This commit is contained in:
commit
46ab1aa3bd
13
Action.c
13
Action.c
|
@ -248,10 +248,21 @@ static Htop_Reaction actionIncFilter(State* st) {
|
|||
}
|
||||
|
||||
static Htop_Reaction actionIncSearch(State* st) {
|
||||
IncSet_reset(((MainPanel*)st->panel)->inc, INC_SEARCH);
|
||||
IncSet_activate(((MainPanel*)st->panel)->inc, INC_SEARCH, st->panel);
|
||||
return HTOP_REFRESH | HTOP_KEEP_FOLLOWING;
|
||||
}
|
||||
|
||||
static Htop_Reaction actionIncNext(State* st) {
|
||||
IncSet_next(((MainPanel*)st->panel)->inc, INC_SEARCH, st->panel, (IncMode_GetPanelValue) MainPanel_getValue);
|
||||
return HTOP_REFRESH | HTOP_KEEP_FOLLOWING;
|
||||
}
|
||||
|
||||
static Htop_Reaction actionIncPrev(State* st) {
|
||||
IncSet_prev(((MainPanel*)st->panel)->inc, INC_SEARCH, st->panel, (IncMode_GetPanelValue) MainPanel_getValue);
|
||||
return HTOP_REFRESH | HTOP_KEEP_FOLLOWING;
|
||||
}
|
||||
|
||||
static Htop_Reaction actionHigherPriority(State* st) {
|
||||
bool changed = changePriority((MainPanel*)st->panel, -1);
|
||||
return changed ? HTOP_REFRESH : HTOP_OK;
|
||||
|
@ -559,6 +570,8 @@ void Action_setBindings(Htop_Action* keys) {
|
|||
keys['\\'] = actionIncFilter;
|
||||
keys[KEY_F(3)] = actionIncSearch;
|
||||
keys['/'] = actionIncSearch;
|
||||
keys['n'] = actionIncNext;
|
||||
keys['N'] = actionIncPrev;
|
||||
|
||||
keys[']'] = actionHigherPriority;
|
||||
keys[KEY_F(7)] = actionHigherPriority;
|
||||
|
|
42
IncSet.c
42
IncSet.c
|
@ -52,6 +52,10 @@ static void IncMode_reset(IncMode* mode) {
|
|||
mode->buffer[0] = 0;
|
||||
}
|
||||
|
||||
void IncSet_reset(IncSet* this, IncType type) {
|
||||
IncMode_reset(&this->modes[type]);
|
||||
}
|
||||
|
||||
static const char* const searchFunctions[] = {"Next ", "Cancel ", " Search: ", NULL};
|
||||
static const char* const searchKeys[] = {"F3", "Esc", " "};
|
||||
static int searchEvents[] = {KEY_F(3), 27, ERR};
|
||||
|
@ -132,6 +136,30 @@ static bool search(IncMode* mode, Panel* panel, IncMode_GetPanelValue getPanelVa
|
|||
return found;
|
||||
}
|
||||
|
||||
static bool IncMode_find(IncMode* mode, Panel* panel, IncMode_GetPanelValue getPanelValue, int step) {
|
||||
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;
|
||||
if (String_contains_i(getPanelValue(panel, i), mode->buffer)) {
|
||||
Panel_setSelected(panel, i);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool IncSet_next(IncSet* this, IncType type, Panel* panel, IncMode_GetPanelValue getPanelValue) {
|
||||
return IncMode_find(&this->modes[type], panel, getPanelValue, 1);
|
||||
}
|
||||
|
||||
bool IncSet_prev(IncSet* this, IncType type, Panel* panel, IncMode_GetPanelValue getPanelValue) {
|
||||
return IncMode_find(&this->modes[type], panel, getPanelValue, -1);
|
||||
}
|
||||
|
||||
bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue getPanelValue, Vector* lines) {
|
||||
if (ch == ERR)
|
||||
return true;
|
||||
|
@ -141,17 +169,7 @@ bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue
|
|||
bool doSearch = true;
|
||||
if (ch == KEY_F(3)) {
|
||||
if (size == 0) return true;
|
||||
int here = Panel_getSelectedIndex(panel);
|
||||
int i = here;
|
||||
for(;;) {
|
||||
i++;
|
||||
if (i == size) i = 0;
|
||||
if (i == here) break;
|
||||
if (String_contains_i(getPanelValue(panel, i), mode->buffer)) {
|
||||
Panel_setSelected(panel, i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
IncMode_find(mode, panel, getPanelValue, 1);
|
||||
doSearch = false;
|
||||
} else if (ch < 255 && isprint((char)ch)) {
|
||||
if (mode->index < INCMODE_MAX) {
|
||||
|
@ -187,8 +205,10 @@ bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue
|
|||
IncMode_reset(mode);
|
||||
}
|
||||
} else {
|
||||
if (ch == 27) {
|
||||
IncMode_reset(mode);
|
||||
}
|
||||
}
|
||||
this->active = NULL;
|
||||
Panel_setDefaultBar(panel);
|
||||
FunctionBar_draw(this->defaultBar, NULL);
|
||||
|
|
6
IncSet.h
6
IncSet.h
|
@ -41,10 +41,16 @@ typedef struct IncSet_ {
|
|||
typedef const char* (*IncMode_GetPanelValue)(Panel*, int);
|
||||
|
||||
|
||||
extern void IncSet_reset(IncSet* this, IncType type);
|
||||
|
||||
extern IncSet* IncSet_new(FunctionBar* bar);
|
||||
|
||||
extern void IncSet_delete(IncSet* this);
|
||||
|
||||
extern bool IncSet_next(IncSet* this, IncType type, Panel* panel, IncMode_GetPanelValue getPanelValue);
|
||||
|
||||
extern bool IncSet_prev(IncSet* this, IncType type, Panel* panel, IncMode_GetPanelValue getPanelValue);
|
||||
|
||||
extern bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue getPanelValue, Vector* lines);
|
||||
|
||||
extern const char* IncSet_getListItemValue(Panel* panel, int i);
|
||||
|
|
Loading…
Reference in New Issue