mirror of
https://github.com/xzeldon/htop.git
synced 2024-12-24 15:15:44 +00:00
affinity panel: use the tree collapsing as in the process list
With one exception, the root node does also have a `-`/`+` as a prefix.
This commit is contained in:
parent
b0f1336f79
commit
19359cec5a
@ -27,7 +27,7 @@ in the source distribution for its full text.
|
||||
typedef struct MaskItem_ {
|
||||
Object super;
|
||||
const char* text;
|
||||
const char* indent;
|
||||
const char* indent; /* used also as an condition whether this is a tree node */
|
||||
int value; /* tri-state: 0 - off, 1 - some set, 2 - all set */
|
||||
int sub_tree; /* tri-state: 0 - no sub-tree, 1 - open sub-tree, 2 - closed sub-tree */
|
||||
Vector *children;
|
||||
@ -64,11 +64,12 @@ static void MaskItem_display(Object* cast, RichString* out) {
|
||||
RichString_append(out, CRT_colors[CHECK_MARK], " ");
|
||||
RichString_append(out, CRT_colors[CHECK_BOX], "]");
|
||||
RichString_append(out, CRT_colors[CHECK_TEXT], " ");
|
||||
if (this->indent)
|
||||
if (this->indent) {
|
||||
RichString_append(out, CRT_colors[PROCESS_TREE], this->indent);
|
||||
if (this->sub_tree) {
|
||||
RichString_append(out, CRT_colors[ PROCESS_TREE],
|
||||
this->sub_tree == 1 ? "[-]" : "[+]");
|
||||
RichString_append(out, CRT_colors[PROCESS_TREE],
|
||||
this->sub_tree == 2
|
||||
? CRT_treeStr[TREE_STR_OPEN]
|
||||
: CRT_treeStr[TREE_STR_SHUT]);
|
||||
RichString_append(out, CRT_colors[CHECK_TEXT], " ");
|
||||
}
|
||||
RichString_append(out, CRT_colors[CHECK_TEXT], this->text);
|
||||
@ -84,7 +85,7 @@ static ObjectClass MaskItem_class = {
|
||||
static MaskItem* MaskItem_newMask(const char* text, const char* indent, hwloc_bitmap_t cpuset, bool owner) {
|
||||
MaskItem* this = AllocThis(MaskItem);
|
||||
this->text = xStrdup(text);
|
||||
this->indent = xStrdup(indent);
|
||||
this->indent = xStrdup(indent); /* nonnull for tree node */
|
||||
this->value = 0;
|
||||
this->ownCpuset = owner;
|
||||
this->cpuset = cpuset;
|
||||
@ -98,7 +99,7 @@ static MaskItem* MaskItem_newMask(const char* text, const char* indent, hwloc_bi
|
||||
static MaskItem* MaskItem_newSingleton(const char* text, int cpu, bool isSet) {
|
||||
MaskItem* this = AllocThis(MaskItem);
|
||||
this->text = xStrdup(text);
|
||||
this->indent = NULL;
|
||||
this->indent = NULL; /* not a tree node */
|
||||
this->sub_tree = 0;
|
||||
this->children = Vector_new(Class(MaskItem), true, DEFAULT_SIZE);
|
||||
|
||||
@ -279,9 +280,8 @@ static MaskItem *AffinityPanel_addObject(AffinityPanel* this, hwloc_obj_t obj, u
|
||||
size_t len = strlen(&indent_buf[off]);
|
||||
off += len, left -= len;
|
||||
}
|
||||
xSnprintf(&indent_buf[off], left, "%s%s ",
|
||||
obj->next_sibling ? CRT_treeStr[TREE_STR_RTEE] : CRT_treeStr[TREE_STR_BEND],
|
||||
CRT_treeStr[TREE_STR_HORZ]);
|
||||
xSnprintf(&indent_buf[off], left, "%s",
|
||||
obj->next_sibling ? CRT_treeStr[TREE_STR_RTEE] : CRT_treeStr[TREE_STR_BEND]);
|
||||
size_t len = strlen(&indent_buf[off]);
|
||||
off += len, left -= len;
|
||||
}
|
||||
@ -302,8 +302,8 @@ static MaskItem *AffinityPanel_addObject(AffinityPanel* this, hwloc_obj_t obj, u
|
||||
item->sub_tree = 2;
|
||||
}
|
||||
|
||||
/* "[x] " + "|- " * depth + ("[+] ")? + name */
|
||||
unsigned width = 4 + 3 * depth + (item->sub_tree ? 4 : 0) + strlen(buf);
|
||||
/* "[x] " + "|- " * depth + ("- ")?(if root node) + name */
|
||||
unsigned width = 4 + 3 * depth + (2 * !depth) + strlen(buf);
|
||||
if (width > this->width)
|
||||
this->width = width;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user