mirror of
https://github.com/xzeldon/htop.git
synced 2025-07-12 12:14:36 +03:00
Mega-commit with features and tweaks for 1.0:
* Performance improvements * Support for splitting CPU meters into two or four columns (thanks to Wim Heirman) * Switch from PLPA, which is now deprecated, to HWLOC. * Bring back support for native Linux sched_setaffinity, so we don't have to use HWLOC where we don't need to. * Support for typing in user names and column fields in selection panels.
This commit is contained in:
37
Panel.c
37
Panel.c
@ -93,6 +93,7 @@ void Panel_init(Panel* this, int x, int y, int w, int h, char* type, bool owner)
|
||||
this->w = w;
|
||||
this->h = h;
|
||||
this->eventHandler = NULL;
|
||||
this->eventHandlerBuffer = NULL;
|
||||
this->items = Vector_new(type, owner, DEFAULT_SIZE, ListItem_compare);
|
||||
this->scrollV = 0;
|
||||
this->scrollH = 0;
|
||||
@ -108,6 +109,7 @@ void Panel_init(Panel* this, int x, int y, int w, int h, char* type, bool owner)
|
||||
|
||||
void Panel_done(Panel* this) {
|
||||
assert (this != NULL);
|
||||
free(this->eventHandlerBuffer);
|
||||
Vector_delete(this->items);
|
||||
RichString_end(this->header);
|
||||
}
|
||||
@ -405,3 +407,38 @@ bool Panel_onKey(Panel* this, int key) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
HandlerResult Panel_selectByTyping(Panel* this, int ch) {
|
||||
int size = Panel_size(this);
|
||||
if (!this->eventHandlerBuffer)
|
||||
this->eventHandlerBuffer = calloc(100, 1);
|
||||
|
||||
if (isalnum(ch)) {
|
||||
int len = strlen(this->eventHandlerBuffer);
|
||||
if (len < 99) {
|
||||
this->eventHandlerBuffer[len] = ch;
|
||||
this->eventHandlerBuffer[len+1] = '\0';
|
||||
}
|
||||
for (int try = 0; try < 2; try++) {
|
||||
len = strlen(this->eventHandlerBuffer);
|
||||
for (int i = 0; i < size; i++) {
|
||||
char* cur = ((ListItem*) Panel_get(this, i))->value;
|
||||
while (*cur == ' ') cur++;
|
||||
if (strncasecmp(cur, this->eventHandlerBuffer, len) == 0) {
|
||||
Panel_setSelected(this, i);
|
||||
return HANDLED;
|
||||
}
|
||||
}
|
||||
this->eventHandlerBuffer[0] = ch;
|
||||
this->eventHandlerBuffer[1] = '\0';
|
||||
}
|
||||
return HANDLED;
|
||||
} else if (ch != ERR) {
|
||||
this->eventHandlerBuffer[0] = '\0';
|
||||
}
|
||||
if (ch == 13) {
|
||||
return BREAK_LOOP;
|
||||
}
|
||||
return IGNORED;
|
||||
}
|
||||
|
Reference in New Issue
Block a user