Address items from review

This commit is contained in:
Adam Saponara 2020-10-31 20:36:53 -04:00
parent dde71c6637
commit a83f515f0f
5 changed files with 16 additions and 11 deletions

View File

@ -6,7 +6,6 @@ Released under the GNU GPLv2, see the COPYING file
in the source distribution for its full text. in the source distribution for its full text.
*/ */
#include "config.h" // IWYU pragma: keep #include "config.h" // IWYU pragma: keep
#include "Process.h" #include "Process.h"
@ -383,10 +382,10 @@ void Process_display(const Object* cast, RichString* out) {
if (this->tag == true) if (this->tag == true)
RichString_setAttr(out, CRT_colors[PROCESS_TAG]); RichString_setAttr(out, CRT_colors[PROCESS_TAG]);
if (this->settings->highlightChanges) { if (this->settings->highlightChanges) {
if (Process_isNew(this))
out->highlightAttr = CRT_colors[PROCESS_NEW];
if (Process_isTomb(this)) if (Process_isTomb(this))
out->highlightAttr = CRT_colors[PROCESS_TOMB]; out->highlightAttr = CRT_colors[PROCESS_TOMB];
else if (Process_isNew(this))
out->highlightAttr = CRT_colors[PROCESS_NEW];
} }
assert(out->chlen > 0); assert(out->chlen > 0);
} }
@ -421,13 +420,14 @@ void Process_toggleTag(Process* this) {
} }
bool Process_isNew(const Process* this) { bool Process_isNew(const Process* this) {
if (this->processList && this->processList->scanTs >= this->seenTs) assert(this->processList);
return (this->processList->scanTs - this->seenTs <= this->processList->settings->highlightDelaySecs); if (this->processList->scanTs >= this->seenTs)
return this->processList->scanTs - this->seenTs <= this->processList->settings->highlightDelaySecs;
return false; return false;
} }
bool Process_isTomb(const Process* this) { bool Process_isTomb(const Process* this) {
return (this->tombTs > 0); return this->tombTs > 0;
} }
bool Process_setPriority(Process* this, int priority) { bool Process_setPriority(Process* this, int priority) {

View File

@ -9,8 +9,8 @@ in the source distribution for its full text.
*/ */
#include <stdbool.h> #include <stdbool.h>
#include <sys/types.h>
#include <time.h> #include <time.h>
#include <sys/types.h>
#include "Object.h" #include "Object.h"
#include "RichString.h" #include "RichString.h"
@ -78,6 +78,7 @@ typedef struct Process_ {
bool tag; bool tag;
bool showChildren; bool showChildren;
bool show; bool show;
bool wasShown;
unsigned int pgrp; unsigned int pgrp;
unsigned int session; unsigned int session;
unsigned int tty_nr; unsigned int tty_nr;

View File

@ -14,6 +14,7 @@ in the source distribution for its full text.
#include "CRT.h" #include "CRT.h"
#include "XUtils.h" #include "XUtils.h"
ProcessList* ProcessList_init(ProcessList* this, const ObjectClass* klass, UsersTable* usersTable, Hashtable* pidMatchList, uid_t userId) { ProcessList* ProcessList_init(ProcessList* this, const ObjectClass* klass, UsersTable* usersTable, Hashtable* pidMatchList, uid_t userId) {
this->processes = Vector_new(klass, true, DEFAULT_SIZE); this->processes = Vector_new(klass, true, DEFAULT_SIZE);
this->processTable = Hashtable_new(140, false); this->processTable = Hashtable_new(140, false);
@ -306,6 +307,7 @@ void ProcessList_scan(ProcessList* this, bool pauseProcessUpdate) {
for (int i = 0; i < Vector_size(this->processes); i++) { for (int i = 0; i < Vector_size(this->processes); i++) {
Process* p = (Process*) Vector_get(this->processes, i); Process* p = (Process*) Vector_get(this->processes, i);
p->updated = false; p->updated = false;
p->wasShown = p->show;
p->show = true; p->show = true;
} }
@ -334,7 +336,7 @@ void ProcessList_scan(ProcessList* this, bool pauseProcessUpdate) {
} }
} else if (p->updated == false) { } else if (p->updated == false) {
// process no longer exists // process no longer exists
if (this->settings->highlightChanges) { if (this->settings->highlightChanges && p->wasShown) {
// mark tombed // mark tombed
p->tombTs = this->scanTs + this->settings->highlightDelaySecs; p->tombTs = this->scanTs + this->settings->highlightDelaySecs;
} else { } else {

View File

@ -313,6 +313,7 @@ Settings* Settings_new(int initialCpuCount) {
this->updateProcessNames = false; this->updateProcessNames = false;
this->showProgramPath = true; this->showProgramPath = true;
this->highlightThreads = true; this->highlightThreads = true;
this->highlightChanges = false;
this->highlightDelaySecs = DEFAULT_HIGHLIGHT_SECS; this->highlightDelaySecs = DEFAULT_HIGHLIGHT_SECS;
#ifdef HAVE_LIBHWLOC #ifdef HAVE_LIBHWLOC
this->topologyAffinity = false; this->topologyAffinity = false;

7
htop.c
View File

@ -50,14 +50,14 @@ static void printHelpFlag(void) {
"-d --delay=DELAY Set the delay between updates, in tenths of seconds\n" "-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" "-F --filter=FILTER Show only the commands matching the given filter\n"
"-h --help Print this help screen\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" "-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" "-s --sort-key=COLUMN Sort by COLUMN (try --sort-key=help for a list)\n"
"-t --tree Show the tree view by default\n" "-t --tree Show the tree view by default\n"
"-u --user[=USERNAME] Show only processes for a given user (or $USER)\n" "-u --user[=USERNAME] Show only processes for a given user (or $USER)\n"
"-U --no-unicode Do not use unicode but plain ASCII\n" "-U --no-unicode Do not use unicode but plain ASCII\n"
"-V --version Print version info\n" "-V --version Print version info\n"
"-H --highlight-changes[=DELAY] Highlight new and old processes\n"
"\n" "\n"
"Long options may be passed with a single dash.\n\n" "Long options may be passed with a single dash.\n\n"
"Press F1 inside htop for online help.\n" "Press F1 inside htop for online help.\n"
@ -212,7 +212,8 @@ static CommandLineSettings parseArguments(int argc, char** argv) {
} }
if (delay) { if (delay) {
if (sscanf(delay, "%16d", &(flags.highlightDelaySecs)) == 1) { if (sscanf(delay, "%16d", &(flags.highlightDelaySecs)) == 1) {
if (flags.highlightDelaySecs < 1) flags.highlightDelaySecs = 1; if (flags.highlightDelaySecs < 1)
flags.highlightDelaySecs = 1;
} else { } else {
fprintf(stderr, "Error: invalid highlight delay value \"%s\".\n", delay); fprintf(stderr, "Error: invalid highlight delay value \"%s\".\n", delay);
exit(1); exit(1);