summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2015-08-12 17:16:50 -0300
committerHisham Muhammad <hisham@gobolinux.org>2015-08-12 17:16:50 -0300
commit4d44c35519094d76c639bdf6e2f5d4b35c943f91 (patch)
tree868a1e1c2b0e1ef51567408ffd421dd11cc3b987
parent4e135bb6b652ec174c876a09ca022689eaa469d7 (diff)
parentfc0e44662c0644fdca75260335734b8cd1090986 (diff)
Merge pull request #148 from nckx/display-basename
[PATCH] New setting: "Show program path"
-rw-r--r--Action.c6
-rw-r--r--DisplayOptionsPanel.c1
-rw-r--r--Process.c40
-rw-r--r--Settings.c4
-rw-r--r--Settings.h1
-rw-r--r--htop.1.in3
6 files changed, 39 insertions, 16 deletions
diff --git a/Action.c b/Action.c
index af6f2be9..19cc7e35 100644
--- a/Action.c
+++ b/Action.c
@@ -211,6 +211,11 @@ static Htop_Reaction actionToggleUserlandThreads(State* st) {
return HTOP_RECALCULATE | HTOP_SAVE_SETTINGS;
}
+static Htop_Reaction actionToggleProgramPath(State* st) {
+ st->settings->showProgramPath = !st->settings->showProgramPath;
+ return HTOP_REFRESH | HTOP_SAVE_SETTINGS;
+}
+
static Htop_Reaction actionToggleTreeView(State* st) {
st->settings->treeView = !st->settings->treeView;
if (st->settings->treeView) st->settings->direction = 1;
@@ -501,6 +506,7 @@ void Action_setBindings(Htop_Action* keys) {
keys['P'] = actionSortByCPU;
keys['H'] = actionToggleUserlandThreads;
keys['K'] = actionToggleKernelThreads;
+ keys['p'] = actionToggleProgramPath;
keys['t'] = actionToggleTreeView;
keys[KEY_F(5)] = actionToggleTreeView;
keys[KEY_F(4)] = actionIncFilter;
diff --git a/DisplayOptionsPanel.c b/DisplayOptionsPanel.c
index 9e119091..c544162f 100644
--- a/DisplayOptionsPanel.c
+++ b/DisplayOptionsPanel.c
@@ -87,6 +87,7 @@ DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager*
Panel_add(super, (Object*) CheckItem_new(strdup("Hide userland threads"), &(settings->hideUserlandThreads), false));
Panel_add(super, (Object*) CheckItem_new(strdup("Display threads in a different color"), &(settings->highlightThreads), false));
Panel_add(super, (Object*) CheckItem_new(strdup("Show custom thread names"), &(settings->showThreadNames), false));
+ Panel_add(super, (Object*) CheckItem_new(strdup("Show program path"), &(settings->showProgramPath), true));
Panel_add(super, (Object*) CheckItem_new(strdup("Highlight program \"basename\""), &(settings->highlightBaseName), false));
Panel_add(super, (Object*) CheckItem_new(strdup("Highlight large numbers in memory counters"), &(settings->highlightMegabytes), false));
Panel_add(super, (Object*) CheckItem_new(strdup("Leave a margin around header"), &(settings->headerMargin), false));
diff --git a/Process.c b/Process.c
index 1962c5d0..6c75d92f 100644
--- a/Process.c
+++ b/Process.c
@@ -275,25 +275,33 @@ void Process_printTime(RichString* str, unsigned long long totalHundredths) {
}
static inline void Process_writeCommand(Process* this, int attr, int baseattr, RichString* str) {
- int start = RichString_size(str);
- RichString_append(str, attr, this->comm);
- if (this->settings->highlightBaseName) {
- int finish = RichString_size(str) - 1;
- if (this->basenameOffset != -1)
- finish = (start + this->basenameOffset) - 1;
- int colon = RichString_findChar(str, ':', start);
- if (colon != -1 && colon < finish) {
- finish = colon;
- } else {
- for (int i = finish - start; i >= 0; i--) {
- if (this->comm[i] == '/') {
- start += i+1;
- break;
- }
+ int start = RichString_size(str), finish = 0;
+ char* comm = this->comm;
+
+ if (this->settings->highlightBaseName || !this->settings->showProgramPath) {
+ int i, basename = 0;
+ for (i = 0; i < this->basenameOffset; i++) {
+ if (comm[i] == '/') {
+ basename = i + 1;
+ } else if (comm[i] == ':') {
+ finish = i + 1;
+ break;
}
}
- RichString_setAttrn(str, baseattr, start, finish);
+ if (!finish) {
+ if (this->settings->showProgramPath)
+ start += basename;
+ else
+ comm += basename;
+ finish = this->basenameOffset - basename;
+ }
+ finish += start - 1;
}
+
+ RichString_append(str, attr, comm);
+
+ if (this->settings->highlightBaseName)
+ RichString_setAttrn(str, baseattr, start, finish);
}
void Process_outputRate(RichString* str, char* buffer, int n, double rate, int coloring) {
diff --git a/Settings.c b/Settings.c
index 4f4c45e7..59317959 100644
--- a/Settings.c
+++ b/Settings.c
@@ -46,6 +46,7 @@ typedef struct Settings_ {
bool countCPUsFromZero;
bool detailedCPUTime;
bool treeView;
+ bool showProgramPath;
bool hideThreads;
bool shadowOtherUsers;
bool showThreadNames;
@@ -186,6 +187,8 @@ static bool Settings_read(Settings* this, const char* fileName) {
this->shadowOtherUsers = atoi(option[1]);
} else if (String_eq(option[0], "show_thread_names")) {
this->showThreadNames = atoi(option[1]);
+ } else if (String_eq(option[0], "show_program_path")) {
+ this->showProgramPath = atoi(option[1]);
} else if (String_eq(option[0], "highlight_base_name")) {
this->highlightBaseName = atoi(option[1]);
} else if (String_eq(option[0], "highlight_megabytes")) {
@@ -272,6 +275,7 @@ bool Settings_write(Settings* this) {
fprintf(fd, "hide_userland_threads=%d\n", (int) this->hideUserlandThreads);
fprintf(fd, "shadow_other_users=%d\n", (int) this->shadowOtherUsers);
fprintf(fd, "show_thread_names=%d\n", (int) this->showThreadNames);
+ fprintf(fd, "show_program_path=%d\n", (int) this->showProgramPath);
fprintf(fd, "highlight_base_name=%d\n", (int) this->highlightBaseName);
fprintf(fd, "highlight_megabytes=%d\n", (int) this->highlightMegabytes);
fprintf(fd, "highlight_threads=%d\n", (int) this->highlightThreads);
diff --git a/Settings.h b/Settings.h
index 73a418a9..d9dc0683 100644
--- a/Settings.h
+++ b/Settings.h
@@ -37,6 +37,7 @@ typedef struct Settings_ {
bool countCPUsFromZero;
bool detailedCPUTime;
bool treeView;
+ bool showProgramPath;
bool hideThreads;
bool shadowOtherUsers;
bool showThreadNames;
diff --git a/htop.1.in b/htop.1.in
index ce11a5e0..59c028ee 100644
--- a/htop.1.in
+++ b/htop.1.in
@@ -151,6 +151,9 @@ Hide user threads: on systems that represent them differently than ordinary
processes (such as recent NPTL-based systems), this can hide threads from
userspace processes in the process list. (This is a toggle key.)
.TP
+.B p
+Show full paths to running programs, where applicable. (This is a toggle key.)
+.TP
.B Ctrl-L
Refresh: redraw screen and recalculate values.
.TP

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