diff options
author | Tobias Geerinckx-Rice <tobias.geerinckx.rice@gmail.com> | 2015-07-29 21:14:29 +0200 |
---|---|---|
committer | Tobias Geerinckx-Rice <tobias.geerinckx.rice@gmail.com> | 2015-08-07 14:20:14 +0200 |
commit | 293eec4265e1a2555bffe351c5a85d6f55f1a52b (patch) | |
tree | 7fc12e4bdad9afaf36aa11b4ab1fd075eef6f051 /Process.c | |
parent | c33d32e66b80da0558da3fdfbfc2fe03cf5f4114 (diff) |
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.
Diffstat (limited to 'Process.c')
-rw-r--r-- | Process.c | 40 |
1 files changed, 24 insertions, 16 deletions
@@ -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) { |