2006-03-04 18:16:49 +00:00
|
|
|
/*
|
|
|
|
htop - htop.c
|
2011-05-26 16:32:50 +00:00
|
|
|
(C) 2004-2011 Hisham H. Muhammad
|
2006-03-04 18:16:49 +00:00
|
|
|
Released under the GNU GPL, see the COPYING file
|
|
|
|
in the source distribution for its full text.
|
|
|
|
*/
|
|
|
|
|
2015-01-22 01:27:31 +00:00
|
|
|
#include "config.h"
|
2011-12-26 21:35:57 +00:00
|
|
|
|
2006-03-04 18:16:49 +00:00
|
|
|
#include "FunctionBar.h"
|
2015-01-22 01:27:31 +00:00
|
|
|
#include "Hashtable.h"
|
2011-12-26 21:35:57 +00:00
|
|
|
#include "ColumnsPanel.h"
|
2015-01-22 01:27:31 +00:00
|
|
|
#include "CRT.h"
|
|
|
|
#include "MainPanel.h"
|
|
|
|
#include "ProcessList.h"
|
|
|
|
#include "ScreenManager.h"
|
|
|
|
#include "Settings.h"
|
|
|
|
#include "UsersTable.h"
|
2015-03-15 23:29:13 +00:00
|
|
|
#include "Platform.h"
|
2006-03-04 18:16:49 +00:00
|
|
|
|
2011-12-26 21:35:57 +00:00
|
|
|
#include <getopt.h>
|
2015-01-22 01:27:31 +00:00
|
|
|
#include <locale.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2011-12-26 21:35:57 +00:00
|
|
|
#include <string.h>
|
2014-04-22 21:19:24 +00:00
|
|
|
#include <time.h>
|
2015-01-22 01:27:31 +00:00
|
|
|
#include <unistd.h>
|
2011-12-26 21:35:57 +00:00
|
|
|
|
2006-03-04 18:16:49 +00:00
|
|
|
//#link m
|
|
|
|
|
2008-03-09 08:58:38 +00:00
|
|
|
static void printVersionFlag() {
|
2010-02-25 02:04:24 +00:00
|
|
|
fputs("htop " VERSION " - " COPYRIGHT "\n"
|
|
|
|
"Released under the GNU GPL.\n\n",
|
|
|
|
stdout);
|
2006-03-04 18:16:49 +00:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2014-04-09 21:02:50 +00:00
|
|
|
static const char* defaultFunctions[] = {"Help ", "Setup ", "Search", "Filter", "Tree ", "SortBy", "Nice -", "Nice +", "Kill ", "Quit ", NULL};
|
|
|
|
|
2008-03-09 08:58:38 +00:00
|
|
|
static void printHelpFlag() {
|
2010-02-25 02:04:24 +00:00
|
|
|
fputs("htop " VERSION " - " COPYRIGHT "\n"
|
|
|
|
"Released under the GNU GPL.\n\n"
|
2012-08-10 21:54:41 +00:00
|
|
|
"-C --no-color Use a monochrome color scheme\n"
|
|
|
|
"-d --delay=DELAY Set the delay between updates, in tenths of seconds\n"
|
|
|
|
"-h --help Print this help screen\n"
|
|
|
|
"-s --sort-key=COLUMN Sort by COLUMN (try --sort-key=help for a list)\n"
|
|
|
|
"-u --user=USERNAME Show only processes of a given user\n"
|
|
|
|
"-p --pid=PID,[,PID,PID...] Show only the given PIDs\n"
|
2010-02-25 02:04:24 +00:00
|
|
|
"-v --version Print version info\n"
|
|
|
|
"\n"
|
|
|
|
"Long options may be passed with a single dash.\n\n"
|
|
|
|
"Press F1 inside htop for online help.\n"
|
|
|
|
"See 'man htop' for more information.\n",
|
|
|
|
stdout);
|
2006-03-04 18:16:49 +00:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2014-11-20 01:17:52 +00:00
|
|
|
// ----------------------------------------
|
|
|
|
|
2015-01-22 01:27:31 +00:00
|
|
|
typedef struct CommandLineSettings_ {
|
|
|
|
Hashtable* pidWhiteList;
|
|
|
|
uid_t userId;
|
|
|
|
int sortKey;
|
|
|
|
int delay;
|
|
|
|
bool useColors;
|
|
|
|
} CommandLineSettings;
|
|
|
|
|
|
|
|
static CommandLineSettings parseArguments(int argc, char** argv) {
|
|
|
|
|
|
|
|
CommandLineSettings flags = {
|
|
|
|
.pidWhiteList = NULL,
|
|
|
|
.userId = -1, // -1 is guaranteed to be an invalid uid_t (see setreuid(2))
|
|
|
|
.sortKey = 0,
|
|
|
|
.delay = -1,
|
|
|
|
.useColors = true,
|
|
|
|
};
|
2014-11-20 01:17:52 +00:00
|
|
|
|
2010-02-25 02:04:24 +00:00
|
|
|
static struct option long_opts[] =
|
|
|
|
{
|
|
|
|
{"help", no_argument, 0, 'h'},
|
|
|
|
{"version", no_argument, 0, 'v'},
|
|
|
|
{"delay", required_argument, 0, 'd'},
|
|
|
|
{"sort-key", required_argument, 0, 's'},
|
|
|
|
{"user", required_argument, 0, 'u'},
|
|
|
|
{"no-color", no_argument, 0, 'C'},
|
|
|
|
{"no-colour",no_argument, 0, 'C'},
|
2012-08-10 21:54:41 +00:00
|
|
|
{"pid", required_argument, 0, 'p'},
|
2015-01-22 01:27:31 +00:00
|
|
|
{"io", no_argument, 0, 'i'},
|
2010-02-25 02:04:24 +00:00
|
|
|
{0,0,0,0}
|
|
|
|
};
|
2008-03-09 02:33:23 +00:00
|
|
|
|
2015-01-22 01:27:31 +00:00
|
|
|
int opt, opti=0;
|
2010-02-25 02:04:24 +00:00
|
|
|
/* Parse arguments */
|
2015-01-22 01:27:31 +00:00
|
|
|
while ((opt = getopt_long(argc, argv, "hvCs:d:u:p:i", long_opts, &opti))) {
|
2010-02-25 02:04:24 +00:00
|
|
|
if (opt == EOF) break;
|
|
|
|
switch (opt) {
|
|
|
|
case 'h':
|
|
|
|
printHelpFlag();
|
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
printVersionFlag();
|
|
|
|
break;
|
|
|
|
case 's':
|
2011-09-08 04:47:48 +00:00
|
|
|
if (strcmp(optarg, "help") == 0) {
|
2015-03-15 23:29:13 +00:00
|
|
|
for (int j = 1; j < Platform_numberOfFields; j++) {
|
2015-01-22 01:27:31 +00:00
|
|
|
const char* name = Process_fields[j].name;
|
|
|
|
if (name) printf ("%s\n", name);
|
|
|
|
}
|
2010-02-25 02:04:24 +00:00
|
|
|
exit(0);
|
|
|
|
}
|
2015-01-22 01:27:31 +00:00
|
|
|
flags.sortKey = ColumnsPanel_fieldNameToIndex(optarg);
|
|
|
|
if (flags.sortKey == -1) {
|
2010-02-25 02:04:24 +00:00
|
|
|
fprintf(stderr, "Error: invalid column \"%s\".\n", optarg);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'd':
|
2015-01-22 01:27:31 +00:00
|
|
|
if (sscanf(optarg, "%16d", &(flags.delay)) == 1) {
|
|
|
|
if (flags.delay < 1) flags.delay = 1;
|
|
|
|
if (flags.delay > 100) flags.delay = 100;
|
2011-08-26 21:04:26 +00:00
|
|
|
} else {
|
|
|
|
fprintf(stderr, "Error: invalid delay value \"%s\".\n", optarg);
|
|
|
|
exit(1);
|
|
|
|
}
|
2010-02-25 02:04:24 +00:00
|
|
|
break;
|
|
|
|
case 'u':
|
2015-01-22 01:27:31 +00:00
|
|
|
if (!Action_setUserOnly(optarg, &(flags.userId))) {
|
2011-08-26 21:04:26 +00:00
|
|
|
fprintf(stderr, "Error: invalid user \"%s\".\n", optarg);
|
|
|
|
exit(1);
|
|
|
|
}
|
2010-02-25 02:04:24 +00:00
|
|
|
break;
|
|
|
|
case 'C':
|
2015-01-22 01:27:31 +00:00
|
|
|
flags.useColors = false;
|
2012-08-10 21:54:41 +00:00
|
|
|
break;
|
2015-01-22 01:27:31 +00:00
|
|
|
case 'p': {
|
|
|
|
char* argCopy = strdup(optarg);
|
2014-04-21 22:16:16 +00:00
|
|
|
char* saveptr;
|
2015-01-22 01:27:31 +00:00
|
|
|
char* pid = strtok_r(argCopy, ",", &saveptr);
|
2012-08-10 21:54:41 +00:00
|
|
|
|
2015-01-22 01:27:31 +00:00
|
|
|
if( !flags.pidWhiteList ) {
|
|
|
|
flags.pidWhiteList = Hashtable_new(8, false);
|
2012-08-10 21:54:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
while( pid ) {
|
|
|
|
unsigned int num_pid = atoi(pid);
|
2015-01-22 01:27:31 +00:00
|
|
|
Hashtable_put(flags.pidWhiteList, num_pid, (void *) 1);
|
2014-04-21 22:16:16 +00:00
|
|
|
pid = strtok_r(NULL, ",", &saveptr);
|
2012-08-10 21:54:41 +00:00
|
|
|
}
|
|
|
|
free(argCopy);
|
|
|
|
|
2010-02-25 02:04:24 +00:00
|
|
|
break;
|
2014-04-21 22:16:16 +00:00
|
|
|
}
|
2011-08-26 21:04:26 +00:00
|
|
|
default:
|
|
|
|
exit(1);
|
2006-03-04 18:16:49 +00:00
|
|
|
}
|
|
|
|
}
|
2015-01-22 01:27:31 +00:00
|
|
|
return flags;
|
|
|
|
}
|
2010-02-25 02:04:24 +00:00
|
|
|
|
2015-01-22 01:27:31 +00:00
|
|
|
static void millisleep(unsigned long millisec) {
|
|
|
|
struct timespec req = {
|
|
|
|
.tv_sec = 0,
|
|
|
|
.tv_nsec = millisec * 1000000L
|
|
|
|
};
|
|
|
|
while(nanosleep(&req,&req)==-1) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char** argv) {
|
|
|
|
|
|
|
|
char *lc_ctype = getenv("LC_CTYPE");
|
|
|
|
if(lc_ctype != NULL)
|
|
|
|
setlocale(LC_CTYPE, lc_ctype);
|
|
|
|
else if ((lc_ctype = getenv("LC_ALL")))
|
|
|
|
setlocale(LC_CTYPE, lc_ctype);
|
|
|
|
else
|
|
|
|
setlocale(LC_CTYPE, "");
|
|
|
|
|
|
|
|
CommandLineSettings flags = parseArguments(argc, argv); // may exit()
|
2010-02-25 02:04:24 +00:00
|
|
|
|
2006-03-13 17:29:18 +00:00
|
|
|
if (access(PROCDIR, R_OK) != 0) {
|
|
|
|
fprintf(stderr, "Error: could not read procfs (compiled to look in %s).\n", PROCDIR);
|
|
|
|
exit(1);
|
|
|
|
}
|
2012-12-05 15:12:20 +00:00
|
|
|
|
2014-11-27 22:10:23 +00:00
|
|
|
Process_setupColumnWidths();
|
2006-03-04 18:16:49 +00:00
|
|
|
|
2015-01-22 01:27:31 +00:00
|
|
|
UsersTable* ut = UsersTable_new();
|
|
|
|
ProcessList* pl = ProcessList_new(ut, flags.pidWhiteList, flags.userId);
|
|
|
|
|
|
|
|
Settings* settings = Settings_new(pl->cpuCount);
|
|
|
|
pl->settings = settings;
|
|
|
|
|
2015-01-23 05:08:21 +00:00
|
|
|
Header* header = Header_new(pl, settings, 2);
|
|
|
|
|
|
|
|
Header_populateFromSettings(header);
|
|
|
|
|
2015-01-22 01:27:31 +00:00
|
|
|
if (flags.delay != -1)
|
|
|
|
settings->delay = flags.delay;
|
|
|
|
if (!flags.useColors)
|
2010-02-25 02:04:24 +00:00
|
|
|
settings->colorScheme = COLORSCHEME_MONOCHROME;
|
2011-11-03 22:12:12 +00:00
|
|
|
|
2006-03-04 18:16:49 +00:00
|
|
|
CRT_init(settings->delay, settings->colorScheme);
|
2011-12-01 12:31:57 +00:00
|
|
|
|
2014-04-09 21:02:50 +00:00
|
|
|
FunctionBar* defaultBar = FunctionBar_new(defaultFunctions, NULL, NULL);
|
|
|
|
|
2015-01-22 01:27:31 +00:00
|
|
|
MainPanel* panel = MainPanel_new(defaultBar);
|
|
|
|
ProcessList_setPanel(pl, (Panel*) panel);
|
|
|
|
|
|
|
|
MainPanel_updateTreeFunctions(defaultBar, settings->treeView);
|
|
|
|
|
|
|
|
if (flags.sortKey > 0) {
|
|
|
|
settings->sortKey = flags.sortKey;
|
|
|
|
settings->treeView = false;
|
|
|
|
settings->direction = 1;
|
2008-03-14 18:50:49 +00:00
|
|
|
}
|
2015-01-22 01:27:31 +00:00
|
|
|
ProcessList_printHeader(pl, Panel_getHeader((Panel*)panel));
|
2006-03-04 18:16:49 +00:00
|
|
|
|
2012-11-10 00:31:37 +00:00
|
|
|
IncSet* inc = IncSet_new(defaultBar);
|
|
|
|
|
2015-01-22 01:27:31 +00:00
|
|
|
State state = {
|
|
|
|
.inc = inc,
|
|
|
|
.settings = settings,
|
|
|
|
.ut = ut,
|
|
|
|
.pl = pl,
|
|
|
|
.panel = (Panel*) panel,
|
|
|
|
.header = header,
|
|
|
|
};
|
|
|
|
MainPanel_setState(panel, &state);
|
|
|
|
|
2015-01-23 05:08:21 +00:00
|
|
|
ScreenManager* scr = ScreenManager_new(0, header->height, 0, -1, HORIZONTAL, header, settings, true);
|
|
|
|
ScreenManager_add(scr, (Panel*) panel, defaultBar, -1);
|
2015-01-22 01:27:31 +00:00
|
|
|
|
2006-03-04 18:16:49 +00:00
|
|
|
ProcessList_scan(pl);
|
2014-04-21 22:37:57 +00:00
|
|
|
millisleep(75);
|
2014-06-04 19:45:55 +00:00
|
|
|
ProcessList_scan(pl);
|
2015-01-22 01:27:31 +00:00
|
|
|
|
|
|
|
ScreenManager_run(scr, NULL, NULL);
|
2006-03-04 18:16:49 +00:00
|
|
|
|
2015-01-22 01:27:31 +00:00
|
|
|
/*
|
2006-03-04 18:16:49 +00:00
|
|
|
FunctionBar_draw(defaultBar, NULL);
|
|
|
|
|
|
|
|
int acc = 0;
|
|
|
|
bool follow = false;
|
|
|
|
|
|
|
|
struct timeval tv;
|
|
|
|
double oldTime = 0.0;
|
|
|
|
|
2011-03-22 20:37:08 +00:00
|
|
|
int ch = ERR;
|
2006-03-04 18:16:49 +00:00
|
|
|
int closeTimeout = 0;
|
|
|
|
|
2014-11-20 01:17:52 +00:00
|
|
|
bool drawPanel = true;
|
2012-12-05 15:12:20 +00:00
|
|
|
|
2014-04-09 21:02:50 +00:00
|
|
|
bool collapsed = false;
|
|
|
|
|
2014-11-20 01:17:52 +00:00
|
|
|
Htop_Action keys[KEY_MAX] = { NULL };
|
|
|
|
setBindings(keys);
|
2014-11-24 20:55:03 +00:00
|
|
|
Platform_setBindings(keys);
|
|
|
|
|
|
|
|
bool quit = false;
|
|
|
|
int sortTimeout = 0;
|
|
|
|
int resetSortTimeout = 5;
|
|
|
|
bool doRefresh = true;
|
|
|
|
bool forceRecalculate = false;
|
2014-11-20 01:17:52 +00:00
|
|
|
|
2006-03-04 18:16:49 +00:00
|
|
|
while (!quit) {
|
|
|
|
gettimeofday(&tv, NULL);
|
2014-04-21 22:16:16 +00:00
|
|
|
double newTime = ((double)tv.tv_sec * 10) + ((double)tv.tv_usec / 100000);
|
2014-11-20 01:17:52 +00:00
|
|
|
bool timeToRecalculate = (newTime - oldTime > settings->delay);
|
|
|
|
if (newTime < oldTime) timeToRecalculate = true; // clock was adjusted?
|
2015-01-23 05:08:21 +00:00
|
|
|
int following = follow ? MainPanel_selectedPid((MainPanel*)panel) : -1;
|
2014-11-20 01:17:52 +00:00
|
|
|
if (timeToRecalculate) {
|
2012-12-05 15:12:20 +00:00
|
|
|
Header_draw(header);
|
2006-03-04 18:16:49 +00:00
|
|
|
oldTime = newTime;
|
2012-12-05 15:12:20 +00:00
|
|
|
}
|
2006-03-04 18:16:49 +00:00
|
|
|
if (doRefresh) {
|
2014-11-20 01:17:52 +00:00
|
|
|
if (timeToRecalculate || forceRecalculate) {
|
2006-03-04 18:16:49 +00:00
|
|
|
ProcessList_scan(pl);
|
2014-11-20 01:17:52 +00:00
|
|
|
forceRecalculate = false;
|
2009-02-17 18:13:25 +00:00
|
|
|
}
|
2015-01-22 01:27:31 +00:00
|
|
|
if (sortTimeout == 0 || settings->treeView) {
|
2006-03-04 18:16:49 +00:00
|
|
|
ProcessList_sort(pl);
|
2014-11-20 01:17:52 +00:00
|
|
|
sortTimeout = 1;
|
2006-03-04 18:16:49 +00:00
|
|
|
}
|
2014-11-20 01:17:52 +00:00
|
|
|
ProcessList_rebuildPanel(pl, true, following, IncSet_filter(inc));
|
|
|
|
drawPanel = true;
|
2006-03-04 18:16:49 +00:00
|
|
|
}
|
|
|
|
doRefresh = true;
|
2014-04-09 21:02:50 +00:00
|
|
|
|
2015-01-22 01:27:31 +00:00
|
|
|
if (settings->treeView) {
|
2014-04-09 21:02:50 +00:00
|
|
|
Process* p = (Process*) Panel_getSelected(panel);
|
|
|
|
if (p) {
|
|
|
|
if (!p->showChildren && !collapsed) {
|
|
|
|
FunctionBar_setLabel(defaultBar, KEY_F(6), "Expand");
|
|
|
|
FunctionBar_draw(defaultBar, NULL);
|
|
|
|
} else if (p->showChildren && collapsed) {
|
|
|
|
FunctionBar_setLabel(defaultBar, KEY_F(6), "Collap");
|
|
|
|
FunctionBar_draw(defaultBar, NULL);
|
|
|
|
}
|
|
|
|
collapsed = !p->showChildren;
|
|
|
|
}
|
2014-11-20 01:17:52 +00:00
|
|
|
} else {
|
|
|
|
collapsed = false;
|
2014-04-09 21:02:50 +00:00
|
|
|
}
|
2006-03-04 18:16:49 +00:00
|
|
|
|
2014-11-20 01:17:52 +00:00
|
|
|
if (drawPanel) {
|
2012-12-05 15:12:20 +00:00
|
|
|
Panel_draw(panel, true);
|
2014-04-09 21:02:50 +00:00
|
|
|
}
|
2012-12-05 15:12:20 +00:00
|
|
|
|
2006-03-04 18:16:49 +00:00
|
|
|
int prev = ch;
|
2012-11-10 00:31:37 +00:00
|
|
|
if (inc->active)
|
2011-09-24 00:30:47 +00:00
|
|
|
move(LINES-1, CRT_cursorX);
|
2006-03-04 18:16:49 +00:00
|
|
|
ch = getch();
|
|
|
|
|
|
|
|
if (ch == ERR) {
|
2012-11-10 00:31:37 +00:00
|
|
|
if (!inc->active)
|
2014-11-20 01:17:52 +00:00
|
|
|
sortTimeout--;
|
|
|
|
if (prev == ch && !timeToRecalculate) {
|
2006-03-04 18:16:49 +00:00
|
|
|
closeTimeout++;
|
2011-03-28 19:06:06 +00:00
|
|
|
if (closeTimeout == 100) {
|
2006-03-04 18:16:49 +00:00
|
|
|
break;
|
2011-03-28 19:06:06 +00:00
|
|
|
}
|
2006-03-04 18:16:49 +00:00
|
|
|
} else
|
|
|
|
closeTimeout = 0;
|
2014-11-20 01:17:52 +00:00
|
|
|
drawPanel = false;
|
2006-03-04 18:16:49 +00:00
|
|
|
continue;
|
|
|
|
}
|
2014-11-20 01:17:52 +00:00
|
|
|
drawPanel = true;
|
|
|
|
|
|
|
|
Htop_Reaction reaction = HTOP_OK;
|
2006-03-04 18:16:49 +00:00
|
|
|
|
|
|
|
if (ch == KEY_MOUSE) {
|
|
|
|
MEVENT mevent;
|
|
|
|
int ok = getmouse(&mevent);
|
|
|
|
if (ok == OK) {
|
2011-05-26 16:32:50 +00:00
|
|
|
if (mevent.bstate & BUTTON1_CLICKED) {
|
|
|
|
if (mevent.y == panel->y) {
|
|
|
|
int x = panel->scrollH + mevent.x + 1;
|
|
|
|
ProcessField field = ProcessList_keyAt(pl, x);
|
2015-01-22 01:27:31 +00:00
|
|
|
if (field == settings->sortKey) {
|
|
|
|
Settings_invertSortOrder(settings);
|
|
|
|
settings->treeView = false;
|
2014-11-20 01:17:52 +00:00
|
|
|
reaction |= HTOP_REDRAW_BAR;
|
2011-05-26 16:32:50 +00:00
|
|
|
} else {
|
2015-01-22 01:27:31 +00:00
|
|
|
reaction |= setSortKey(settings, field);
|
2011-05-26 16:32:50 +00:00
|
|
|
}
|
2014-11-20 01:17:52 +00:00
|
|
|
sortTimeout = 0;
|
|
|
|
ch = ERR;
|
2011-05-26 16:32:50 +00:00
|
|
|
} else if (mevent.y >= panel->y + 1 && mevent.y < LINES - 1) {
|
|
|
|
Panel_setSelected(panel, mevent.y - panel->y + panel->scrollV - 1);
|
|
|
|
follow = true;
|
2014-11-20 01:17:52 +00:00
|
|
|
ch = ERR;
|
2011-05-26 16:32:50 +00:00
|
|
|
} if (mevent.y == LINES - 1) {
|
2012-11-10 00:31:37 +00:00
|
|
|
ch = FunctionBar_synthesizeEvent(inc->bar, mevent.x);
|
2008-03-14 18:50:49 +00:00
|
|
|
}
|
2011-05-26 16:32:50 +00:00
|
|
|
} else if (mevent.bstate & BUTTON4_CLICKED) {
|
|
|
|
ch = KEY_UP;
|
|
|
|
#if NCURSES_MOUSE_VERSION > 1
|
|
|
|
} else if (mevent.bstate & BUTTON5_CLICKED) {
|
|
|
|
ch = KEY_DOWN;
|
|
|
|
#endif
|
2006-03-04 18:16:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-10 00:31:37 +00:00
|
|
|
if (inc->active) {
|
|
|
|
doRefresh = IncSet_handleKey(inc, ch, panel, getMainPanelValue, NULL);
|
2014-04-25 19:05:25 +00:00
|
|
|
if (!inc->active) {
|
|
|
|
follow = true;
|
|
|
|
}
|
2012-11-10 00:31:37 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isdigit((char)ch)) {
|
|
|
|
if (Panel_size(panel) == 0) continue;
|
|
|
|
pid_t pid = ch-48 + acc;
|
2014-04-09 17:47:32 +00:00
|
|
|
for (int i = 0; i < ProcessList_size(pl); i++) {
|
2012-11-10 00:31:37 +00:00
|
|
|
Panel_setSelected(panel, i);
|
2014-04-09 17:47:32 +00:00
|
|
|
Process* p = (Process*) Panel_getSelected(panel);
|
|
|
|
if (p && p->pid == pid) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-11-10 00:31:37 +00:00
|
|
|
acc = pid * 10;
|
|
|
|
if (acc > 10000000)
|
|
|
|
acc = 0;
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
acc = 0;
|
|
|
|
}
|
|
|
|
|
2014-11-20 01:17:52 +00:00
|
|
|
if(ch != ERR && keys[ch]) {
|
2015-01-22 01:27:31 +00:00
|
|
|
reaction |= (keys[ch])(&state);
|
2014-11-20 01:17:52 +00:00
|
|
|
} else {
|
|
|
|
doRefresh = false;
|
|
|
|
sortTimeout = resetSortTimeout;
|
|
|
|
Panel_onKey(panel, ch);
|
2006-03-04 18:16:49 +00:00
|
|
|
}
|
2014-11-20 01:17:52 +00:00
|
|
|
|
|
|
|
// Reaction handlers:
|
2007-11-08 23:23:01 +00:00
|
|
|
|
2014-11-20 01:17:52 +00:00
|
|
|
if (reaction & HTOP_REDRAW_BAR) {
|
2015-01-22 01:27:31 +00:00
|
|
|
updateTreeFunctions(defaultBar, settings->treeView);
|
2014-11-20 01:17:52 +00:00
|
|
|
IncSet_drawBar(inc);
|
2006-03-04 18:16:49 +00:00
|
|
|
}
|
2014-11-20 01:17:52 +00:00
|
|
|
if (reaction & HTOP_UPDATE_PANELHDR) {
|
2012-10-04 23:59:45 +00:00
|
|
|
ProcessList_printHeader(pl, Panel_getHeader(panel));
|
|
|
|
}
|
2014-11-20 01:17:52 +00:00
|
|
|
if (reaction & HTOP_REFRESH) {
|
2011-09-08 01:17:26 +00:00
|
|
|
doRefresh = true;
|
2014-11-20 01:17:52 +00:00
|
|
|
sortTimeout = 0;
|
|
|
|
}
|
|
|
|
if (reaction & HTOP_RECALCULATE) {
|
|
|
|
forceRecalculate = true;
|
|
|
|
sortTimeout = 0;
|
|
|
|
}
|
|
|
|
if (reaction & HTOP_SAVE_SETTINGS) {
|
2006-03-04 18:16:49 +00:00
|
|
|
settings->changed = true;
|
|
|
|
}
|
2014-11-20 01:17:52 +00:00
|
|
|
if (reaction & HTOP_QUIT) {
|
|
|
|
quit = true;
|
|
|
|
}
|
|
|
|
follow = (reaction & HTOP_KEEP_FOLLOWING);
|
2006-03-04 18:16:49 +00:00
|
|
|
}
|
2015-01-22 01:27:31 +00:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
2006-03-04 18:16:49 +00:00
|
|
|
attron(CRT_colors[RESET_COLOR]);
|
|
|
|
mvhline(LINES-1, 0, ' ', COLS);
|
|
|
|
attroff(CRT_colors[RESET_COLOR]);
|
|
|
|
refresh();
|
|
|
|
|
|
|
|
CRT_done();
|
|
|
|
if (settings->changed)
|
|
|
|
Settings_write(settings);
|
|
|
|
Header_delete(header);
|
|
|
|
ProcessList_delete(pl);
|
2015-01-22 01:27:31 +00:00
|
|
|
|
|
|
|
/*
|
2006-03-04 18:16:49 +00:00
|
|
|
FunctionBar_delete((Object*)defaultBar);
|
2011-09-08 01:17:26 +00:00
|
|
|
Panel_delete((Object*)panel);
|
2015-01-22 01:27:31 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
ScreenManager_delete(scr);
|
2014-11-20 01:17:52 +00:00
|
|
|
|
|
|
|
IncSet_delete(inc);
|
2006-03-04 18:16:49 +00:00
|
|
|
UsersTable_delete(ut);
|
|
|
|
Settings_delete(settings);
|
2014-11-20 01:17:52 +00:00
|
|
|
|
2015-01-22 01:27:31 +00:00
|
|
|
if(flags.pidWhiteList) {
|
|
|
|
Hashtable_delete(flags.pidWhiteList);
|
2012-08-10 21:54:41 +00:00
|
|
|
}
|
2006-03-04 18:16:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|