summaryrefslogtreecommitdiffstats
path: root/htop.c
diff options
context:
space:
mode:
authorDaniel Lange <DLange@git.local>2020-11-16 12:13:47 +0100
committerDaniel Lange <DLange@git.local>2020-11-16 12:55:07 +0100
commit0951090fa45255cd0ae0df907240868c31689014 (patch)
tree8d923fa842a2a0be65ff2d786bcd6a01cfbcf66a /htop.c
parent0411fdbcef51c1b2a39d9eeaa140a5b7c00bd3d2 (diff)
parenta83f515f0fb75a079601be0d2e0e24b9402c9e15 (diff)
Merge branch 'hili-new-old' of adsr/htop into highlight-new-old-processes
Diffstat (limited to 'htop.c')
-rw-r--r--htop.c50
1 files changed, 40 insertions, 10 deletions
diff --git a/htop.c b/htop.c
index 7fbc04c9..b36bd4b0 100644
--- a/htop.c
+++ b/htop.c
@@ -50,8 +50,9 @@ static void printHelpFlag(void) {
"-d --delay=DELAY Set the delay between updates, in tenths of seconds\n"
"-F --filter=FILTER Show only the commands matching the given filter\n"
"-h --help Print this help screen\n"
+ "-H --highlight-changes[=DELAY] Highlight new and old processes\n"
"-M --no-mouse Disable the mouse\n"
- "-p --pid=PID,[,PID,PID...] Show only the given PIDs\n"
+ "-p --pid=PID[,PID,PID...] Show only the given PIDs\n"
"-s --sort-key=COLUMN Sort by COLUMN (try --sort-key=help for a list)\n"
"-t --tree Show the tree view by default\n"
"-u --user[=USERNAME] Show only processes for a given user (or $USER)\n"
@@ -76,6 +77,8 @@ typedef struct CommandLineSettings_ {
bool enableMouse;
bool treeView;
bool allowUnicode;
+ bool highlightChanges;
+ int highlightDelaySecs;
} CommandLineSettings;
static CommandLineSettings parseArguments(int argc, char** argv) {
@@ -90,6 +93,8 @@ static CommandLineSettings parseArguments(int argc, char** argv) {
.enableMouse = true,
.treeView = false,
.allowUnicode = true,
+ .highlightChanges = false,
+ .highlightDelaySecs = -1,
};
static struct option long_opts[] =
@@ -106,12 +111,13 @@ static CommandLineSettings parseArguments(int argc, char** argv) {
{"tree", no_argument, 0, 't'},
{"pid", required_argument, 0, 'p'},
{"filter", required_argument, 0, 'F'},
- {0, 0, 0, 0}
+ {"highlight-changes", optional_argument, 0, 'H'},
+ {0,0,0,0}
};
- int opt, opti = 0;
+ int opt, opti=0;
/* Parse arguments */
- while ((opt = getopt_long(argc, argv, "hVMCs:td:u::Up:F:", long_opts, &opti))) {
+ while ((opt = getopt_long(argc, argv, "hVMCs:td:u::Up:F:H::", long_opts, &opti))) {
if (opt == EOF) break;
switch (opt) {
case 'h':
@@ -186,11 +192,11 @@ static CommandLineSettings parseArguments(int argc, char** argv) {
char* saveptr;
char* pid = strtok_r(argCopy, ",", &saveptr);
- if (!flags.pidMatchList) {
+ if(!flags.pidMatchList) {
flags.pidMatchList = Hashtable_new(8, false);
}
- while (pid) {
+ while(pid) {
unsigned int num_pid = atoi(pid);
// deepcode ignore CastIntegerToAddress: we just want a non-NUll pointer here
Hashtable_put(flags.pidMatchList, num_pid, (void *) 1);
@@ -206,6 +212,24 @@ static CommandLineSettings parseArguments(int argc, char** argv) {
break;
}
+ case 'H': {
+ const char *delay = optarg;
+ if (!delay && optind < argc && argv[optind] != NULL &&
+ (argv[optind][0] != '\0' && argv[optind][0] != '-')) {
+ delay = argv[optind++];
+ }
+ if (delay) {
+ if (sscanf(delay, "%16d", &(flags.highlightDelaySecs)) == 1) {
+ if (flags.highlightDelaySecs < 1)
+ flags.highlightDelaySecs = 1;
+ } else {
+ fprintf(stderr, "Error: invalid highlight delay value \"%s\".\n", delay);
+ exit(1);
+ }
+ }
+ flags.highlightChanges = true;
+ break;
+ }
default:
exit(1);
}
@@ -218,7 +242,7 @@ static void millisleep(unsigned long millisec) {
.tv_sec = 0,
.tv_nsec = millisec * 1000000L
};
- while (nanosleep(&req, &req) == -1) {
+ while(nanosleep(&req,&req)==-1) {
continue;
}
}
@@ -242,7 +266,7 @@ static void setCommFilter(State* state, char** commFilter) {
int main(int argc, char** argv) {
- char* lc_ctype = getenv("LC_CTYPE");
+ char *lc_ctype = getenv("LC_CTYPE");
if (lc_ctype != NULL) {
setlocale(LC_CTYPE, lc_ctype);
} else if ((lc_ctype = getenv("LC_ALL"))) {
@@ -284,6 +308,12 @@ int main(int argc, char** argv) {
if (flags.treeView) {
settings->treeView = true;
}
+ if (flags.highlightChanges) {
+ settings->highlightChanges = true;
+ }
+ if (flags.highlightDelaySecs != -1) {
+ settings->highlightDelaySecs = flags.highlightDelaySecs;
+ }
CRT_init(settings->delay, settings->colorScheme, flags.allowUnicode);
@@ -323,7 +353,7 @@ int main(int argc, char** argv) {
ScreenManager_run(scr, NULL, NULL);
attron(CRT_colors[RESET_COLOR]);
- mvhline(LINES - 1, 0, ' ', COLS);
+ mvhline(LINES-1, 0, ' ', COLS);
attroff(CRT_colors[RESET_COLOR]);
refresh();
@@ -339,7 +369,7 @@ int main(int argc, char** argv) {
UsersTable_delete(ut);
Settings_delete(settings);
- if (flags.pidMatchList) {
+ if(flags.pidMatchList) {
Hashtable_delete(flags.pidMatchList);
}
return 0;

© 2014-2024 Faster IT GmbH | imprint | privacy policy