| skipped 4 lines |
5 | 5 | | "github.com/liamg/dismember/pkg/proc" |
6 | 6 | | "github.com/spf13/cobra" |
7 | 7 | | "io" |
| 8 | + | "os" |
8 | 9 | | ) |
9 | 10 | | |
10 | 11 | | func init() { |
| skipped 43 lines |
54 | 55 | | }) |
55 | 56 | | } |
56 | 57 | | |
57 | | - | drawBranch(cmd.OutOrStdout(), rootWithStatus, nil, all) |
| 58 | + | uid := os.Getuid() |
| 59 | + | drawBranch(cmd.OutOrStdout(), rootWithStatus, "", true, all, uid) |
58 | 60 | | return nil |
59 | 61 | | } |
60 | 62 | | |
61 | | - | func drawBranch(w io.Writer, parent procWithStatus, lasts []bool, all []procWithStatus) { |
| 63 | + | func drawBranch(w io.Writer, parent procWithStatus, prefix string, last bool, all []procWithStatus, uid int) { |
62 | 64 | | |
63 | 65 | | var children []procWithStatus |
64 | 66 | | for _, process := range all { |
| skipped 3 lines |
68 | 70 | | children = append(children, process) |
69 | 71 | | } |
70 | 72 | | |
71 | | - | var done bool |
72 | | - | _, _ = fmt.Fprint(w, ansiDim) |
73 | | - | if len(lasts) > 1 { |
74 | | - | for _, last := range lasts[1:] { |
75 | | - | if !last { |
76 | | - | _, _ = fmt.Fprint(w, " │ ") |
77 | | - | } else if !done { |
78 | | - | done = true |
79 | | - | _, _ = fmt.Fprint(w, " │ ") |
80 | | - | } else { |
81 | | - | _, _ = fmt.Fprint(w, " ") |
82 | | - | } |
83 | | - | } |
84 | | - | } |
85 | | - | |
86 | | - | if len(lasts) > 0 { |
| 73 | + | _, _ = fmt.Print(ansiDim + prefix) |
| 74 | + | if prefix != "" { |
87 | 75 | | symbol := '├' |
88 | | - | if lasts[len(lasts)-1] { |
| 76 | + | if last { |
89 | 77 | | symbol = '└' |
90 | 78 | | } |
91 | 79 | | _, _ = fmt.Fprintf(w, " %c─ ", symbol) |
92 | 80 | | } |
93 | 81 | | |
94 | 82 | | _, _ = fmt.Fprint(w, ansiReset) |
| 83 | + | //owner, err := parent.process.Ownership() |
| 84 | + | //if err != nil { |
| 85 | + | // |
| 86 | + | //} |
95 | 87 | | _, _ = fmt.Fprintf(w, "%s %s(%s%d%s)%s\n", parent.status.Name, ansiDim, ansiReset, parent.process, ansiDim, ansiReset) |
| 88 | + | _, _ = fmt.Fprint(w, ansiReset) |
| 89 | + | |
| 90 | + | if last { |
| 91 | + | prefix += " " |
| 92 | + | } else { |
| 93 | + | prefix += " │ " |
| 94 | + | } |
96 | 95 | | |
97 | 96 | | for i, child := range children { |
98 | | - | drawBranch(w, child, append(lasts, i == len(children)-1), all) |
| 97 | + | drawBranch(w, child, prefix, i == len(children)-1, all) |
99 | 98 | | } |
100 | 99 | | } |
101 | 100 | | |