mirror of
https://github.com/xzeldon/htop.git
synced 2024-12-23 22:55:46 +00:00
Add "Tree view is always sorted by PID" option to mimic htop 2 behavior
This commit is contained in:
parent
3d1703f16f
commit
e8c6994f40
3
Action.c
3
Action.c
@ -160,6 +160,9 @@ static bool collapseIntoParent(Panel* panel) {
|
||||
Htop_Reaction Action_setSortKey(Settings* settings, ProcessField sortKey) {
|
||||
settings->sortKey = sortKey;
|
||||
settings->direction = 1;
|
||||
if (settings->treeViewAlwaysByPID) {
|
||||
settings->treeView = false;
|
||||
}
|
||||
return HTOP_REFRESH | HTOP_SAVE_SETTINGS | HTOP_UPDATE_PANELHDR | HTOP_KEEP_FOLLOWING;
|
||||
}
|
||||
|
||||
|
@ -97,6 +97,7 @@ DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager*
|
||||
|
||||
Panel_setHeader(super, "Display options");
|
||||
Panel_add(super, (Object*) CheckItem_newByRef("Tree view", &(settings->treeView)));
|
||||
Panel_add(super, (Object*) CheckItem_newByRef("- Tree view is always sorted by PID (htop 2 behavior)", &(settings->treeViewAlwaysByPID)));
|
||||
Panel_add(super, (Object*) CheckItem_newByRef("Shadow other users' processes", &(settings->shadowOtherUsers)));
|
||||
Panel_add(super, (Object*) CheckItem_newByRef("Hide kernel threads", &(settings->hideKernelThreads)));
|
||||
Panel_add(super, (Object*) CheckItem_newByRef("Hide userland process threads", &(settings->hideUserlandThreads)));
|
||||
|
@ -25,7 +25,7 @@ static const char* const MainFunctions[] = {"Help ", "Setup ", "Search", "Filt
|
||||
|
||||
void MainPanel_updateTreeFunctions(MainPanel* this, bool mode) {
|
||||
FunctionBar* bar = MainPanel_getFunctionBar(this);
|
||||
FunctionBar_setLabel(bar, KEY_F(5), mode ? "Sorted" : "Tree ");
|
||||
FunctionBar_setLabel(bar, KEY_F(5), mode ? "List " : "Tree ");
|
||||
}
|
||||
|
||||
void MainPanel_pidSearch(MainPanel* this, int ch) {
|
||||
@ -65,6 +65,9 @@ static HandlerResult MainPanel_eventHandler(Panel* super, int ch) {
|
||||
} else {
|
||||
reaction |= Action_setSortKey(settings, field);
|
||||
}
|
||||
if (settings->treeViewAlwaysByPID) {
|
||||
settings->treeView = false;
|
||||
}
|
||||
reaction |= HTOP_RECALCULATE | HTOP_REDRAW_BAR | HTOP_SAVE_SETTINGS;
|
||||
result = HANDLED;
|
||||
} else if (ch != ERR && this->inc->active) {
|
||||
|
@ -505,7 +505,12 @@ long Process_compare(const void* v1, const void* v2) {
|
||||
p1 = (const Process*)v2;
|
||||
}
|
||||
|
||||
switch (settings->sortKey) {
|
||||
ProcessField key = settings->sortKey;
|
||||
if (settings->treeView && settings->treeViewAlwaysByPID) {
|
||||
key = PID;
|
||||
}
|
||||
|
||||
switch (key) {
|
||||
case PERCENT_CPU:
|
||||
case PERCENT_NORM_CPU:
|
||||
return SPACESHIP_NUMBER(p2->percent_cpu, p1->percent_cpu);
|
||||
|
@ -82,7 +82,8 @@ void ProcessList_setPanel(ProcessList* this, Panel* panel) {
|
||||
void ProcessList_printHeader(ProcessList* this, RichString* header) {
|
||||
RichString_prune(header);
|
||||
|
||||
const ProcessField* fields = this->settings->fields;
|
||||
const Settings* settings = this->settings;
|
||||
const ProcessField* fields = settings->fields;
|
||||
|
||||
for (int i = 0; fields[i]; i++) {
|
||||
const char* field = Process_fields[fields[i]].title;
|
||||
@ -90,10 +91,17 @@ void ProcessList_printHeader(ProcessList* this, RichString* header) {
|
||||
field = "- ";
|
||||
}
|
||||
|
||||
int color = (this->settings->sortKey == fields[i]) ?
|
||||
CRT_colors[PANEL_SELECTION_FOCUS] : CRT_colors[PANEL_HEADER_FOCUS];
|
||||
int color;
|
||||
if (settings->treeView && settings->treeViewAlwaysByPID) {
|
||||
color = CRT_colors[PANEL_HEADER_FOCUS];
|
||||
} else if (settings->sortKey == fields[i]) {
|
||||
color = CRT_colors[PANEL_SELECTION_FOCUS];
|
||||
} else {
|
||||
color = CRT_colors[PANEL_HEADER_FOCUS];
|
||||
}
|
||||
|
||||
RichString_appendWide(header, color, field);
|
||||
if (COMM == fields[i] && this->settings->showMergedCommand) {
|
||||
if (COMM == fields[i] && settings->showMergedCommand) {
|
||||
RichString_appendAscii(header, color, "(merged)");
|
||||
}
|
||||
}
|
||||
|
@ -141,6 +141,8 @@ static bool Settings_read(Settings* this, const char* fileName, int initialCpuCo
|
||||
this->direction = atoi(option[1]);
|
||||
} else if (String_eq(option[0], "tree_view")) {
|
||||
this->treeView = atoi(option[1]);
|
||||
} else if (String_eq(option[0], "tree_view_always_by_pid")) {
|
||||
this->treeViewAlwaysByPID = atoi(option[1]);
|
||||
} else if (String_eq(option[0], "hide_kernel_threads")) {
|
||||
this->hideKernelThreads = atoi(option[1]);
|
||||
} else if (String_eq(option[0], "hide_userland_threads")) {
|
||||
@ -287,6 +289,7 @@ bool Settings_write(Settings* this) {
|
||||
fprintf(fd, "strip_exe_from_cmdline=%d\n", (int) this->stripExeFromCmdline);
|
||||
fprintf(fd, "show_merged_command=%d\n", (int) this->showMergedCommand);
|
||||
fprintf(fd, "tree_view=%d\n", (int) this->treeView);
|
||||
fprintf(fd, "tree_view_always_by_pid=%d\n", (int) this->treeViewAlwaysByPID);
|
||||
fprintf(fd, "header_margin=%d\n", (int) this->headerMargin);
|
||||
fprintf(fd, "detailed_cpu_time=%d\n", (int) this->detailedCPUTime);
|
||||
fprintf(fd, "cpu_count_from_one=%d\n", (int) this->countCPUsFromOne);
|
||||
|
@ -44,6 +44,7 @@ typedef struct Settings_ {
|
||||
bool degreeFahrenheit;
|
||||
#endif
|
||||
bool treeView;
|
||||
bool treeViewAlwaysByPID;
|
||||
bool showProgramPath;
|
||||
bool shadowOtherUsers;
|
||||
bool showThreadNames;
|
||||
|
Loading…
Reference in New Issue
Block a user