mirror of https://github.com/xzeldon/htop.git
New logic for highlighting basenames with spaces
This commit is contained in:
parent
61bd770689
commit
f2a190b0e9
18
Process.c
18
Process.c
|
@ -165,6 +165,7 @@ typedef struct Process_ {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int exit_signal;
|
int exit_signal;
|
||||||
|
int basenameOffset;
|
||||||
bool updated;
|
bool updated;
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
@ -404,14 +405,19 @@ static inline void Process_writeCommand(Process* this, int attr, int baseattr, R
|
||||||
RichString_append(str, attr, this->comm);
|
RichString_append(str, attr, this->comm);
|
||||||
if (this->pl->highlightBaseName) {
|
if (this->pl->highlightBaseName) {
|
||||||
int finish = RichString_size(str) - 1;
|
int finish = RichString_size(str) - 1;
|
||||||
int space = RichString_findChar(str, ' ', start);
|
int space = start + this->basenameOffset;
|
||||||
if (space != -1)
|
if (space != -1)
|
||||||
finish = space - 1;
|
finish = space - 1;
|
||||||
for (;;) {
|
int colon = RichString_findChar(str, ':', start);
|
||||||
int slash = RichString_findChar(str, '/', start);
|
if (colon != -1 && colon < finish) {
|
||||||
if (slash == -1 || slash > finish)
|
finish = colon;
|
||||||
break;
|
} else {
|
||||||
start = slash + 1;
|
for (int i = finish - start; i > 0; i--) {
|
||||||
|
if (this->comm[i] == '/') {
|
||||||
|
start += i+1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
RichString_setAttrn(str, baseattr, start, finish);
|
RichString_setAttrn(str, baseattr, start, finish);
|
||||||
}
|
}
|
||||||
|
|
|
@ -144,6 +144,7 @@ typedef struct Process_ {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int exit_signal;
|
int exit_signal;
|
||||||
|
int basenameOffset;
|
||||||
bool updated;
|
bool updated;
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
|
|
@ -667,15 +667,15 @@ static void ProcessList_readOomData(Process* process, const char* dirname, const
|
||||||
snprintf(filename, MAX_NAME, "%s/%s/oom_score", dirname, name);
|
snprintf(filename, MAX_NAME, "%s/%s/oom_score", dirname, name);
|
||||||
FILE* file = fopen(filename, "r");
|
FILE* file = fopen(filename, "r");
|
||||||
if (!file)
|
if (!file)
|
||||||
return;
|
return;
|
||||||
char buffer[256];
|
char buffer[256];
|
||||||
if (!fgets(buffer, 255, file)) {
|
if (!fgets(buffer, 255, file)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
unsigned int oom;
|
unsigned int oom;
|
||||||
int ok = sscanf(buffer, "%u", &oom);
|
int ok = sscanf(buffer, "%u", &oom);
|
||||||
if (ok >= 1) {
|
if (ok >= 1) {
|
||||||
process->oom = oom;
|
process->oom = oom;
|
||||||
}
|
}
|
||||||
fclose(file);
|
fclose(file);
|
||||||
}
|
}
|
||||||
|
@ -695,12 +695,20 @@ static bool ProcessList_readCmdlineFile(Process* process, const char* dirname, c
|
||||||
char command[4096+1]; // max cmdline length on Linux
|
char command[4096+1]; // max cmdline length on Linux
|
||||||
int amtRead = xread(fd, command, sizeof(command) - 1);
|
int amtRead = xread(fd, command, sizeof(command) - 1);
|
||||||
close(fd);
|
close(fd);
|
||||||
|
int tokenEnd = 0;
|
||||||
if (amtRead > 0) {
|
if (amtRead > 0) {
|
||||||
for (int i = 0; i < amtRead; i++)
|
for (int i = 0; i < amtRead; i++)
|
||||||
if (command[i] == '\0' || command[i] == '\n') {
|
if (command[i] == '\0' || command[i] == '\n') {
|
||||||
|
if (tokenEnd == 0) {
|
||||||
|
tokenEnd = i;
|
||||||
|
}
|
||||||
command[i] = ' ';
|
command[i] = ' ';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (tokenEnd == 0) {
|
||||||
|
tokenEnd = amtRead;
|
||||||
|
}
|
||||||
|
process->basenameOffset = tokenEnd;
|
||||||
command[amtRead] = '\0';
|
command[amtRead] = '\0';
|
||||||
free(process->comm);
|
free(process->comm);
|
||||||
process->comm = strdup(command);
|
process->comm = strdup(command);
|
||||||
|
|
Loading…
Reference in New Issue