diff options
-rw-r--r-- | CategoriesPanel.c | 6 | ||||
-rw-r--r-- | IncSet.c | 213 | ||||
-rw-r--r-- | IncSet.h | 56 | ||||
-rw-r--r-- | ListItem.c | 16 | ||||
-rw-r--r-- | ListItem.h | 2 | ||||
-rw-r--r-- | Makefile.am | 10 | ||||
-rw-r--r-- | OpenFilesScreen.c | 141 | ||||
-rw-r--r-- | OpenFilesScreen.h | 1 | ||||
-rw-r--r-- | ProcessList.c | 7 | ||||
-rw-r--r-- | ProcessList.h | 3 | ||||
-rw-r--r-- | RichString.c | 27 | ||||
-rw-r--r-- | RichString.h | 8 | ||||
-rw-r--r-- | ScreenManager.c | 2 | ||||
-rw-r--r-- | TraceScreen.c | 146 | ||||
-rw-r--r-- | TraceScreen.h | 1 | ||||
-rw-r--r-- | Vector.c | 48 | ||||
-rw-r--r-- | Vector.h | 4 | ||||
-rw-r--r-- | htop.c | 161 | ||||
-rw-r--r-- | htop.h | 6 |
19 files changed, 559 insertions, 299 deletions
diff --git a/CategoriesPanel.c b/CategoriesPanel.c index 0114ae4b..449a5be6 100644 --- a/CategoriesPanel.c +++ b/CategoriesPanel.c @@ -101,6 +101,12 @@ static HandlerResult CategoriesPanel_eventHandler(Panel* super, int ch) { result = HANDLED; break; } + default: + if (isalpha(ch)) + result = Panel_selectByTyping(super, ch); + if (result == BREAK_LOOP) + result = IGNORED; + break; } if (result == HANDLED) { diff --git a/IncSet.c b/IncSet.c new file mode 100644 index 00000000..2b9e052b --- /dev/null +++ b/IncSet.c @@ -0,0 +1,213 @@ +/* +htop - IncSet.c +(C) 2005-2012 Hisham H. Muhammad +Released under the GNU GPL, see the COPYING file +in the source distribution for its full text. +*/ + +#include "IncSet.h" +#include "String.h" +#include "Panel.h" +#include "ListItem.h" +#include "CRT.h" +#include <string.h> +#include <stdlib.h> + +/*{ + +#include "FunctionBar.h" +#include "Panel.h" +#include <stdbool.h> + +#define INCMODE_MAX 40 + +typedef enum { + INC_SEARCH = 0, + INC_FILTER = 1 +} IncType; + +#define IncSet_filter(inc_) (inc_->filtering ? inc_->modes[INC_FILTER].buffer : NULL) + +typedef struct IncMode_ { + char buffer[INCMODE_MAX]; + int index; + FunctionBar* bar; + bool isFilter; +} IncMode; + +typedef struct IncSet_ { + IncMode modes[2]; + IncMode* active; + FunctionBar* bar; + FunctionBar* defaultBar; + bool filtering; +} IncSet; + +typedef const char* (*IncMode_GetPanelValue)(Panel*, int); + +}*/ + +static void IncMode_reset(IncMode* mode) { + mode->index = 0; + mode->buffer[0] = 0; +} + +static const char* searchFunctions[] = {"Next ", "Cancel ", " Search: ", NULL}; +static const char* searchKeys[] = {"F3", "Esc", " "}; +static int searchEvents[] = {KEY_F(3), 27, ERR}; + +static inline void IncMode_initSearch(IncMode* search) { + memset(search, 0, sizeof(IncMode)); + search->bar = FunctionBar_new(searchFunctions, searchKeys, searchEvents); + search->isFilter = false; +} + +static const char* filterFunctions[] = {"Done ", "Clear ", " Filter: ", NULL}; +static const char* filterKeys[] = {"Enter", "Esc", " "}; +static int filterEvents[] = {13, 27, ERR}; + +static inline void IncMode_initFilter(IncMode* filter) { + memset(filter, 0, sizeof(IncMode)); + filter->bar = FunctionBar_new(filterFunctions, filterKeys, filterEvents); + filter->isFilter = true; +} + +static inline void IncMode_done(IncMode* mode) { + FunctionBar_delete((Object*)mode->bar); +} + +IncSet* IncSet_new(FunctionBar* bar) { + IncSet* this = calloc(sizeof(IncSet), 1); + IncMode_initSearch(&(this->modes[INC_SEARCH])); + IncMode_initFilter(&(this->modes[INC_FILTER])); + this->active = NULL; + this->filtering = false; + this->bar = bar; + this->defaultBar = bar; + return this; +} + +void IncSet_delete(IncSet* this) { + IncMode_done(&(this->modes[0])); + IncMode_done(&(this->modes[1])); + free(this); +} + +static void updateWeakPanel(IncSet* this, Panel* panel, Vector* lines) { + Object* selected = Panel_getSelected(panel); + Panel_prune(panel); + if (this->filtering) { + int n = 0; + const char* incFilter = this->modes[INC_FILTER].buffer; + for (int i = 0; i < Vector_size(lines); i++) { + 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); + n++; + } + } + } else { + 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); + } + } +} + +static void search(IncMode* mode, Panel* panel, IncMode_GetPanelValue getPanelValue) { + int size = Panel_size(panel); + bool found = false; + for (int i = 0; i < size; i++) { + if (String_contains_i(getPanelValue(panel, i), mode->buffer)) { + Panel_setSelected(panel, i); + found = true; + break; + } + } + if (found) + FunctionBar_draw(mode->bar, mode->buffer); + else + FunctionBar_drawAttr(mode->bar, mode->buffer, CRT_colors[FAILED_SEARCH]); +} + +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 filterChange = false; + 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; + } + } + doSearch = false; + } else if (isprint((char)ch) && (mode->index < INCMODE_MAX)) { + mode->buffer[mode->index] = ch; + mode->index++; + mode->buffer[mode->index] = 0; + if (mode->isFilter) { + filterChange = 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; + if (mode->index == 0) { + this->filtering = false; + IncMode_reset(mode); + } + } + } else { + if (mode->isFilter) { + filterChange = true; + if (ch == 27) { + this->filtering = false; + IncMode_reset(mode); + } + } else { + IncMode_reset(mode); + } + this->active = NULL; + this->bar = this->defaultBar; + FunctionBar_draw(this->defaultBar, NULL); + doSearch = false; + } + if (doSearch) { + search(mode, panel, getPanelValue); + } + if (filterChange && lines) { + updateWeakPanel(this, panel, lines); + } + return filterChange; +} + +const char* IncSet_getListItemValue(Panel* panel, int i) { + ListItem* l = (ListItem*) Panel_get(panel, i); + if (l) + return l->value; + return ""; +} + +void IncSet_activate(IncSet* this, IncType type) { + this->active = &(this->modes[type]); + this->bar = this->active->bar; + FunctionBar_draw(this->active->bar, this->active->buffer); +} + +void IncSet_drawBar(IncSet* this) { + FunctionBar_draw(this->bar, this->active ? this->active->buffer : NULL); +} diff --git a/IncSet.h b/IncSet.h new file mode 100644 index 00000000..fe425330 --- /dev/null +++ b/IncSet.h @@ -0,0 +1,56 @@ +/* Do not edit this file. It was automatically generated. */ + +#ifndef HEADER_IncSet +#define HEADER_IncSet +/* +htop - IncSet.h +(C) 2005-2012 Hisham H. Muhammad +Released under the GNU GPL, see the COPYING file +in the source distribution for its full text. +*/ + + +#include "FunctionBar.h" +#include "Panel.h" +#include <stdbool.h> + +#define INCMODE_MAX 40 + +typedef enum { + INC_SEARCH = 0, + INC_FILTER = 1 +} IncType; + +#define IncSet_filter(inc_) (inc_->filtering ? inc_->modes[INC_FILTER].buffer : NULL) + +typedef struct IncMode_ { + char buffer[INCMODE_MAX]; + int index; + FunctionBar* bar; + bool isFilter; +} IncMode; + +typedef struct IncSet_ { + IncMode modes[2]; + IncMode* active; + FunctionBar* bar; + FunctionBar* defaultBar; + bool filtering; +} IncSet; + +typedef const char* (*IncMode_GetPanelValue)(Panel*, int); + + +IncSet* IncSet_new(FunctionBar* bar); + +void IncSet_delete(IncSet* this); + +bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue getPanelValue, Vector* lines); + +const char* IncSet_getListItemValue(Panel* panel, int i); + +void IncSet_activate(IncSet* this, IncType type); + +void IncSet_drawBar(IncSet* this); + +#endif @@ -41,10 +41,12 @@ static void ListItem_delete(Object* cast) { static void ListItem_display(Object* cast, RichString* out) { ListItem* this = (ListItem*)cast; assert (this != NULL); + /* int len = strlen(this->value)+1; char buffer[len+1]; snprintf(buffer, len, "%s", this->value); - RichString_write(out, CRT_colors[DEFAULT_COLOR], buffer); + */ + RichString_write(out, CRT_colors[DEFAULT_COLOR], this->value/*buffer*/); } ListItem* ListItem_new(const char* value, int key) { @@ -57,11 +59,13 @@ ListItem* ListItem_new(const char* value, int key) { return this; } -void ListItem_append(ListItem* this, char* text) { - char* buf = malloc(strlen(this->value) + strlen(text) + 1); - sprintf(buf, "%s%s", this->value, text); - free(this->value); - this->value = buf; +void ListItem_append(ListItem* this, const char* text) { + int oldLen = strlen(this->value); + int textLen = strlen(text); + int newLen = strlen(this->value) + textLen; + this->value = realloc(this->value, newLen + 1); + memcpy(this->value + oldLen, text, textLen); + this->value[newLen] = '\0'; } const char* ListItem_getRef(ListItem* this) { @@ -26,7 +26,7 @@ extern char* LISTITEM_CLASS; ListItem* ListItem_new(const char* value, int key); -void ListItem_append(ListItem* this, char* text); +void ListItem_append(ListItem* this, const char* text); const char* ListItem_getRef(ListItem* this); diff --git a/Makefile.am b/Makefile.am index 05a72e7e..0aa33596 100644 --- a/Makefile.am +++ b/Makefile.am @@ -20,16 +20,16 @@ LoadAverageMeter.c MemoryMeter.c Meter.c MetersPanel.c Object.c Panel.c \ BatteryMeter.c Process.c ProcessList.c RichString.c ScreenManager.c Settings.c \ IOPriorityPanel.c SignalsPanel.c String.c SwapMeter.c TasksMeter.c TraceScreen.c \ UptimeMeter.c UsersTable.c Vector.c AvailableColumnsPanel.c AffinityPanel.c \ -HostnameMeter.c OpenFilesScreen.c Affinity.c IOPriority.c +HostnameMeter.c OpenFilesScreen.c Affinity.c IOPriority.c IncSet.c myhtopheaders = AvailableColumnsPanel.h AvailableMetersPanel.h \ CategoriesPanel.h CheckItem.h ClockMeter.h ColorsPanel.h ColumnsPanel.h \ IOPriorityPanel.h CPUMeter.h CRT.h DisplayOptionsPanel.h FunctionBar.h \ Hashtable.h Header.h htop.h ListItem.h LoadAverageMeter.h MemoryMeter.h \ BatteryMeter.h Meter.h MetersPanel.h Object.h Panel.h ProcessList.h RichString.h \ -ScreenManager.h Settings.h SignalsPanel.h String.h \ -SwapMeter.h TasksMeter.h TraceScreen.h UptimeMeter.h UsersTable.h Vector.h \ -Process.h AffinityPanel.h HostnameMeter.h OpenFilesScreen.h Affinity.h IOPriority.h +ScreenManager.h Settings.h SignalsPanel.h String.h SwapMeter.h TasksMeter.h \ +TraceScreen.h UptimeMeter.h UsersTable.h Vector.h Process.h AffinityPanel.h \ +HostnameMeter.h OpenFilesScreen.h Affinity.h IOPriority.h IncSet.h SUFFIXES = .h @@ -37,7 +37,7 @@ BUILT_SOURCES = $(myhtopheaders) htop_SOURCES = $(myhtopheaders) $(myhtopsources) config.h profile: - $(MAKE) all CFLAGS="" AM_CPPFLAGS="-pg -O2" + $(MAKE) all CFLAGS="-pg" AM_CPPFLAGS="-pg -O2 -DNDEBUG" debug: $(MAKE) all CFLAGS="" AM_CPPFLAGS="-ggdb -DDEBUG" diff --git a/OpenFilesScreen.c b/OpenFilesScreen.c index 9adf8b4b..30d02af0 100644 --- a/OpenFilesScreen.c +++ b/OpenFilesScreen.c @@ -10,6 +10,8 @@ in the source distribution for its full text. #include "CRT.h" #include "ProcessList.h" #include "ListItem.h" +#include "IncSet.h" +#include "String.h" #include <string.h> #include <stdio.h> @@ -42,23 +44,20 @@ typedef struct OpenFilesScreen_ { pid_t pid; Panel* display; FunctionBar* bar; - bool tracing; } OpenFilesScreen; }*/ -static const char* ofsFunctions[] = {"Refresh", "Done ", NULL}; +static const char* ofsFunctions[] = {"Search ", "Filter ", "Refresh", "Done ", NULL}; -static const char* ofsKeys[] = {"F5", "Esc"}; +static const char* ofsKeys[] = {"F3", "F4", "F5", "Esc"}; -static int ofsEvents[] = {KEY_F(5), 27}; +static int ofsEvents[] = {KEY_F(3), KEY_F(4), KEY_F(5), 27}; OpenFilesScreen* OpenFilesScreen_new(Process* process) { OpenFilesScreen* this = (OpenFilesScreen*) malloc(sizeof(OpenFilesScreen)); this->process = process; - this->display = Panel_new(0, 1, COLS, LINES-3, LISTITEM_CLASS, true, ListItem_compare); - this->bar = FunctionBar_new(ofsFunctions, ofsKeys, ofsEvents); - this->tracing = true; + this->display = Panel_new(0, 1, COLS, LINES-3, LISTITEM_CLASS, false, ListItem_compare); if (Process_isThread(process)) this->pid = process->tgid; else @@ -68,30 +67,29 @@ OpenFilesScreen* OpenFilesScreen_new(Process* process) { void OpenFilesScreen_delete(OpenFilesScreen* this) { Panel_delete((Object*)this->display); - FunctionBar_delete((Object*)this->bar); free(this); } -static void OpenFilesScreen_draw(OpenFilesScreen* this) { +static void OpenFilesScreen_draw(OpenFilesScreen* this, IncSet* inc) { attrset(CRT_colors[METER_TEXT]); mvhline(0, 0, ' ', COLS); - mvprintw(0, 0, "Files open in process %d - %s", this->pid, this->process->comm); + mvprintw(0, 0, "Snapshot of files open in process %d - %s", this->pid, this->process->comm); attrset(CRT_colors[DEFAULT_COLOR]); Panel_draw(this->display, true); - FunctionBar_draw(this->bar, NULL); + IncSet_drawBar(inc); } static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) { char command[1025]; snprintf(command, 1024, "lsof -P -p %d -F 2> /dev/null", pid); FILE* fd = popen(command, "r"); - OpenFiles_ProcessData* process = calloc(sizeof(OpenFiles_ProcessData), 1); - OpenFiles_FileData* file = NULL; - OpenFiles_ProcessData* item = process; + OpenFiles_ProcessData* pdata = calloc(sizeof(OpenFiles_ProcessData), 1); + OpenFiles_FileData* fdata = NULL; + OpenFiles_ProcessData* item = pdata; bool anyRead = false; if (!fd) { - process->error = 127; - return process; + pdata->error = 127; + return pdata; } while (!feof(fd)) { int cmd = fgetc(fd); @@ -107,53 +105,60 @@ static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) { *newline = '\0'; if (cmd == 'f') { OpenFiles_FileData* nextFile = calloc(sizeof(OpenFiles_ProcessData), 1); - if (file == NULL) { - process->files = nextFile; + if (fdata == NULL) { + pdata->files = nextFile; } else { - file->next = nextFile; + fdata->next = nextFile; } - file = nextFile; - item = (OpenFiles_ProcessData*) file; + fdata = nextFile; + item = (OpenFiles_ProcessData*) fdata; } item->data[cmd] = entry; } - process->error = pclose(fd); - return process; + pdata->error = pclose(fd); + return pdata; } -static void OpenFilesScreen_scan(OpenFilesScreen* this) { +static inline void addLine(const char* line, Vector* lines, Panel* panel, const char* incFilter) { + Vector_add(lines, (Object*) ListItem_new(line, 0)); + if (!incFilter || String_contains_i(line, incFilter)) + Panel_add(panel, (Object*)Vector_get(lines, Vector_size(lines)-1)); +} + +static void OpenFilesScreen_scan(OpenFilesScreen* this, Vector* lines, IncSet* inc) { Panel* panel = this->display; - int idx = MAX(Panel_getSelectedIndex(panel), 0); + int idx = Panel_getSelectedIndex(panel); Panel_prune(panel); - OpenFiles_ProcessData* process = OpenFilesScreen_getProcessData(this->pid); - if (process->error == 127) { - Panel_add(panel, (Object*) ListItem_new("Could not execute 'lsof'. Please make sure it is available in your $PATH.", 0)); - } else if (process->error == 1) { - Panel_add(panel, (Object*) ListItem_new("Failed listing open files.", 0)); + OpenFiles_ProcessData* pdata = OpenFilesScreen_getProcessData(this->pid); + if (pdata->error == 127) { + addLine("Could not execute 'lsof'. Please make sure it is available in your $PATH.", lines, panel, IncSet_filter(inc)); + } else if (pdata->error == 1) { + addLine("Failed listing open files.", lines, panel, IncSet_filter(inc)); } else { - OpenFiles_FileData* file = process->files; - while (file) { + OpenFiles_FileData* fdata = pdata->files; + while (fdata) { char entry[1024]; sprintf(entry, "%5s %4s %10s %10s %10s %s", - file->data['f'] ? file->data['f'] : "", - file->data['t'] ? file->data['t'] : "", - file->data['D'] ? file->data['D'] : "", - file->data['s'] ? file->data['s'] : "", - file->data['i'] ? file->data['i'] : "", - file->data['n'] ? file->data['n'] : ""); - Panel_add(panel, (Object*) ListItem_new(entry, 0)); + fdata->data['f'] ? fdata->data['f'] : "", + fdata->data['t'] ? fdata->data['t'] : "", + fdata->data['D'] ? fdata->data['D'] : "", + fdata->data['s'] ? fdata->data['s'] : "", + fdata->data['i'] ? fdata->data['i'] : "", + fdata->data['n'] ? fdata->data['n'] : ""); + addLine(entry, lines, panel, IncSet_filter(inc)); for (int i = 0; i < 255; i++) - if (file->data[i]) - free(file->data[i]); - OpenFiles_FileData* old = file; - file = file->next; + if (fdata->data[i]) + free(fdata->data[i]); + OpenFiles_FileData* old = fdata; + fdata = fdata->next; free(old); } for (int i = 0; i < 255; i++) - if (process->data[i]) - free(process->data[i]); + if (pdata->data[i]) + free(pdata->data[i]); } - free(process); + free(pdata); + Vector_insertionSort(lines); Vector_insertionSort(panel->items); Panel_setSelected(panel, idx); } @@ -161,14 +166,24 @@ static void OpenFilesScreen_scan(OpenFilesScreen* this) { void OpenFilesScreen_run(OpenFilesScreen* this) { Panel* panel = this->display; Panel_setHeader(panel, " FD TYPE DEVICE SIZE NODE NAME"); - OpenFilesScreen_scan(this); - OpenFilesScreen_draw(this); - //CRT_disableDelay(); + + FunctionBar* bar = FunctionBar_new(ofsFunctions, ofsKeys, ofsEvents); + IncSet* inc = IncSet_new(bar); + + Vector* lines = Vector_new(panel->items->type, true, DEFAULT_SIZE, ListItem_compare); + + OpenFilesScreen_scan(this, lines, inc); + OpenFilesScreen_draw(this, inc); bool looping = true; while (looping) { + Panel_draw(panel, true); + + if (inc->active) + move(LINES-1, CRT_cursorX); int ch = getch(); + if (ch == KEY_MOUSE) { MEVENT mevent; int ok = getmouse(&mevent); @@ -177,19 +192,33 @@ void OpenFilesScreen_run(OpenFilesScreen* this) { Panel_setSelected(panel, mevent.y - panel->y + panel->scrollV); ch = 0; } if (mevent.y == LINES - 1) - ch = FunctionBar_synthesizeEvent(this->bar, mevent.x); + ch = FunctionBar_synthesizeEvent(inc->bar, mevent.x); } + + if (inc->active) { + IncSet_handleKey(inc, ch, panel, IncSet_getListItemValue, lines); + continue; + } + switch(ch) { case ERR: continue; + case KEY_F(3): + case '/': + IncSet_activate(inc, INC_SEARCH); + break; + case KEY_F(4): + case '\\': + IncSet_activate(inc, INC_FILTER); + break; case KEY_F(5): clear(); - OpenFilesScreen_scan(this); - OpenFilesScreen_draw(this); + OpenFilesScreen_scan(this, lines, inc); + OpenFilesScreen_draw(this, inc); break; case '\014': // Ctrl+L clear(); - OpenFilesScreen_draw(this); + OpenFilesScreen_draw(this, inc); break; case 'q': case 27: @@ -198,11 +227,13 @@ void OpenFilesScreen_run(OpenFilesScreen* this) { break; case KEY_RESIZE: Panel_resize(panel, COLS, LINES-2); - OpenFilesScreen_draw(this); + OpenFilesScreen_draw(this, inc); break; default: Panel_onKey(panel, ch); } } - //CRT_enableDelay(); + + FunctionBar_delete((Object*)bar); + IncSet_delete(inc); } diff --git a/OpenFilesScreen.h b/OpenFilesScreen.h index 248cac4b..ce15ea34 100644 --- a/OpenFilesScreen.h +++ b/OpenFilesScreen.h @@ -29,7 +29,6 @@ typedef struct OpenFilesScreen_ { pid_t pid; Panel* display; FunctionBar* bar; - bool tracing; } OpenFilesScreen; diff --git a/ProcessList.c b/ProcessList.c index 04adac54..0138919a 100644 --- a/ProcessList.c +++ b/ProcessList.c @@ -112,7 +112,6 @@ typedef struct ProcessList_ { int following; bool userOnly; uid_t userId; - bool filtering; const char* incFilter; Hashtable* pidWhiteList; @@ -918,18 +917,16 @@ void ProcessList_expandTree(ProcessList* this) { } } -void ProcessList_rebuildPanel(ProcessList* this, bool flags, int following, bool userOnly, uid_t userId, bool filtering, const char* incFilter) { +void ProcessList_rebuildPanel(ProcessList* this, bool flags, int following, bool userOnly, uid_t userId, const char* incFilter) { if (!flags) { following = this->following; userOnly = this->userOnly; userId = this->userId; - filtering = this->filtering; incFilter = this->incFilter; } else { this->following = following; this->userOnly = userOnly; this->userId = userId; - this->filtering = filtering; this->incFilter = incFilter; } @@ -946,7 +943,7 @@ void ProcessList_rebuildPanel(ProcessList* this, bool flags, int following, bool if ( (!p->show) || (userOnly && (p->st_uid != userId)) - || (filtering && !(String_contains_i(p->comm, incFilter))) + || (incFilter && !(String_contains_i(p->comm, incFilter))) || (this->pidWhiteList && !Hashtable_get(this->pidWhiteList, p->pid)) ) hidden = true; diff --git a/ProcessList.h b/ProcessList.h index 34bd5e8b..7385a294 100644 --- a/ProcessList.h +++ b/ProcessList.h @@ -95,7 +95,6 @@ typedef struct ProcessList_ { int following; bool userOnly; uid_t userId; - bool filtering; const char* incFilter; Hashtable* pidWhiteList; @@ -185,6 +184,6 @@ ProcessField ProcessList_keyAt(ProcessList* this, int at); void ProcessList_expandTree(ProcessList* this); -void ProcessList_rebuildPanel(ProcessList* this, bool flags, int following, bool userOnly, uid_t userId, bool filtering, const char* incFilter); +void ProcessList_rebuildPanel(ProcessList* this, bool flags, int following, bool userOnly, uid_t userId, const char* incFilter); #endif diff --git a/RichString.c b/RichString.c index eca2293e..33f5880d 100644 --- a/RichString.c +++ b/RichString.c @@ -83,16 +83,15 @@ static inline void RichString_setLen(RichString* this, int len) { #ifdef HAVE_LIBNCURSESW -inline void RichString_appendn(RichString* this, int attrs, const char* data_c, int len) { +static inline void RichString_writeFrom(RichString* this, int attrs, const char* data_c, int from, int len) { wchar_t data[len+1]; len = mbstowcs(data, data_c, len); if (len<0) return; - int oldLen = this->chlen; - int newLen = len + oldLen; + int newLen = from + len; RichString_setLen(this, newLen); - for (int i = oldLen, j = 0; i < newLen; i++, j++) { - memset(&this->chptr[i], 0, sizeof(this->chptr[i])); + memset(&this->chptr[from], 0, sizeof(CharType) * (newLen - from)); + for (int i = from, j = 0; i < newLen; i++, j++) { this->chptr[i].chars[0] = data[j]; this->chptr[i].attr = attrs; } @@ -120,11 +119,10 @@ int RichString_findChar(RichString* this, char c, int start) { #else -inline void RichString_appendn(RichString* this, int attrs, const char* data_c, int len) { - int oldLen = this->chlen; - int newLen = len + oldLen; +static inline void RichString_writeFrom(RichString* this, int attrs, const char* data_c, int from, int len) { + int newLen = from + len; RichString_setLen(this, newLen); - for (int i = oldLen, j = 0; i < newLen; i++, j++) + for (int i = from, j = 0; i < newLen; i++, j++) this->chptr[i] = (isprint(data_c[j]) ? data_c[j] : '?') | attrs; this->chptr[newLen] = 0; } @@ -160,11 +158,14 @@ void RichString_setAttr(RichString* this, int attrs) { RichString_setAttrn(this, attrs, 0, this->chlen - 1); } -inline void RichString_append(RichString* this, int attrs, const char* data) { - RichString_appendn(this, attrs, data, strlen(data)); +void RichString_append(RichString* this, int attrs, const char* data) { + RichString_writeFrom(this, attrs, data, this->chlen, strlen(data)); +} + +void RichString_appendn(RichString* this, int attrs, const char* data, int len) { + RichString_writeFrom(this, attrs, data, this->chlen, len); } void RichString_write(RichString* this, int attrs, const char* data) { - RichString_setLen(this, 0); - RichString_appendn(this, attrs, data, strlen(data)); + RichString_writeFrom(this, attrs, data, 0, strlen(data)); } diff --git a/RichString.h b/RichString.h index 1b4d244a..f22692de 100644 --- a/RichString.h +++ b/RichString.h @@ -61,16 +61,12 @@ typedef struct RichString_ { #ifdef HAVE_LIBNCURSESW -extern void RichString_appendn(RichString* this, int attrs, const char* data_c, int len); - extern void RichString_setAttrn(RichString* this, int attrs, int start, int finish); int RichString_findChar(RichString* this, char c, int start); #else -extern void RichString_appendn(RichString* this, int attrs, const char* data_c, int len); - void RichString_setAttrn(RichString* this, int attrs, int start, int finish); int RichString_findChar(RichString* this, char c, int start); @@ -81,7 +77,9 @@ void RichString_prune(RichString* this); void RichString_setAttr(RichString* this, int attrs); -extern void RichString_append(RichString* this, int attrs, const char* data); +void RichString_append(RichString* this, int attrs, const char* data); + +void RichString_appendn(RichString* this, int attrs, const char* data, int len); void RichString_write(RichString* this, int attrs, const char* data); diff --git a/ScreenManager.c b/ScreenManager.c index 744ea2b0..777e9de3 100644 --- a/ScreenManager.c +++ b/ScreenManager.c @@ -144,7 +144,7 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) { this->lastScan = now; } Header_draw(this->header); - ProcessList_rebuildPanel(this->header->pl, false, false, false, false, false, NULL); + ProcessList_rebuildPanel(this->header->pl, false, false, false, false, NULL); } for (int i = 0; i < panels; i++) { Panel* panel = (Panel*) Vector_get(this->panels, i); diff --git a/TraceScreen.c b/TraceScreen.c index c7250f67..5fc48023 100644 --- a/TraceScreen.c +++ b/TraceScreen.c @@ -10,6 +10,8 @@ in the source distribution for its full text. #include "CRT.h" #include "ProcessList.h" #include "ListItem.h" +#include "IncSet.h" +#include "String.h" #include <stdio.h> #include <unistd.h> @@ -30,39 +32,49 @@ in the source distribution for its full text. typedef struct TraceScreen_ { Process* process; Panel* display; - FunctionBar* bar; bool tracing; } TraceScreen; }*/ -static const char* tsFunctions[] = {"AutoScroll ", "Stop Tracing ", "Done ", NULL}; +static const char* tsFunctions[] = {"Search ", "Filter ", "AutoScroll ", "Stop Tracing ", "Done ", NULL}; -static const char* tsKeys[] = {"F4", "F5", "Esc"}; +static const char* tsKeys[] = {"F3", "F4", "F8", "F9", "Esc"}; -static int tsEvents[] = {KEY_F(4), KEY_F(5), 27}; +static int tsEvents[] = {KEY_F(3), KEY_F(4), KEY_F(8), KEY_F(9), 27}; TraceScreen* TraceScreen_new(Process* process) { TraceScreen* this = (TraceScreen*) malloc(sizeof(TraceScreen)); this->process = process; - this->display = Panel_new(0, 1, COLS, LINES-2, LISTITEM_CLASS, true, ListItem_compare); - this->bar = FunctionBar_new(tsFunctions, tsKeys, tsEvents); + this->display = Panel_new(0, 1, COLS, LINES-2, LISTITEM_CLASS, false, ListItem_compare); this->tracing = true; return this; } void TraceScreen_delete(TraceScreen* this) { Panel_delete((Object*)this->display); - FunctionBar_delete((Object*)this->bar); free(this); } -static void TraceScreen_draw(TraceScreen* this) { +static void TraceScreen_draw(TraceScreen* this, IncSet* inc) { attrset(CRT_colors[PANEL_HEADER_FOCUS]); mvhline(0, 0, ' ', COLS); mvprintw(0, 0, "Trace of process %d - %s", this->process->pid, this->process->comm); attrset(CRT_colors[DEFAULT_COLOR]); - FunctionBar_draw(this->bar, NULL); + IncSet_drawBar(inc); +} + +static inline void addLine(const char* line, Vector* lines, Panel* panel, const char* incFilter) { + Vector_add(lines, (Object*) ListItem_new(line, 0)); + if (!incFilter || String_contains_i(line, incFilter)) + Panel_add(panel, (Object*)Vector_get(lines, Vector_size(lines)-1)); +} + +static inline void appendLine(const char* line, Vector* lines, Panel* panel, const char* incFilter) { + ListItem* last = (ListItem*)Vector_get(lines, Vector_size(lines)-1); + ListItem_append(last, line); + if (incFilter && Panel_get(panel, Panel_size(panel)-1) != (Object*)last && String_contains_i(line, incFilter)) + Panel_add(panel, (Object*)last); } void TraceScreen_run(TraceScreen* this) { @@ -86,47 +98,63 @@ void TraceScreen_run(TraceScreen* this) { FILE* strace = fdopen(fdpair[0], "r"); Panel* panel = this->display; int fd_strace = fileno(strace); - TraceScreen_draw(this); CRT_disableDelay(); bool contLine = false; bool follow = false; bool looping = true; + |