New setting: "Show program path"

Add a setting to hide all but the last component from the programme
path, leaving only the "basename". Makes htop more usable on smaller
screens, or systems with longer than average paths. Off by default.

"Highlight program basename" will still be respected, to further
visually separate process names from their arguments.
This commit is contained in:
Tobias Geerinckx-Rice 2015-07-29 21:14:29 +02:00
parent c33d32e66b
commit 293eec4265
4 changed files with 30 additions and 16 deletions

View File

@ -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));

View File

@ -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) {

View File

@ -45,6 +45,7 @@ typedef struct Settings_ {
bool countCPUsFromZero;
bool detailedCPUTime;
bool treeView;
bool showProgramPath;
bool hideThreads;
bool shadowOtherUsers;
bool showThreadNames;
@ -185,6 +186,8 @@ static bool Settings_read(Settings* this, const char* fileName, int cpuCount) {
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")) {
@ -271,6 +274,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);

View File

@ -36,6 +36,7 @@ typedef struct Settings_ {
bool countCPUsFromZero;
bool detailedCPUTime;
bool treeView;
bool showProgramPath;
bool hideThreads;
bool shadowOtherUsers;
bool showThreadNames;