Files
wehub-resource-sync 36b3af2e3d
PR Check / Code Quality: Format (push) Failing after 1s
PR Check / Code Quality: Lint (darwin) (push) Failing after 0s
PR Check / Code Quality: Lint (freebsd) (push) Failing after 1s
PR Check / Code Quality: Lint (windows) (push) Failing after 1s
PR Check / Code Quality: Lint (linux) (push) Failing after 1s
PR Check / Security: Vulnerability Scan (push) Failing after 0s
Update Documentation / update-docs (push) Failing after 2s
PR Check / Code Quality: Vendor (push) Failing after 1s
PR Check / Code Quality: Coverage (push) Failing after 0s
PR Check / Tests: Unit (macos-latest) (push) Has been cancelled
PR Check / Tests: Unit (ubuntu-24.04) (push) Has been cancelled
PR Check / Tests: Unit (ubuntu-24.04-arm) (push) Has been cancelled
PR Check / Tests: Unit (windows-latest) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:22:06 +08:00

66 lines
1.5 KiB
Go

package output
import (
"io"
"strings"
"github.com/pranshuparmar/witr/pkg/model"
)
func PrintTree(w io.Writer, chain []model.Process, children []model.Process, colorEnabled bool) {
p := NewPrinter(w)
for i, proc := range chain {
indent := strings.Repeat(" ", i)
if i > 0 {
if colorEnabled {
p.Printf("%s%s└─ %s", indent, ColorMagenta, ColorReset)
} else {
p.Printf("%s└─ ", indent)
}
}
if colorEnabled {
cmdColor := ansiString("")
if i == len(chain)-1 {
cmdColor = ColorGreen
}
p.Printf("%s%s%s (%spid %d%s)\n", cmdColor, ChainName(proc), ColorReset, ColorDim, proc.PID, ColorReset)
} else {
p.Printf("%s (pid %d)\n", ChainName(proc), proc.PID)
}
}
if len(children) == 0 {
return
}
baseIndent := strings.Repeat(" ", len(chain))
limit := 10
count := len(children)
for i, child := range children {
if i >= limit {
remaining := count - limit
if colorEnabled {
p.Printf("%s%s└─ %s... and %d more\n", baseIndent, ColorMagenta, ColorReset, remaining)
} else {
p.Printf("%s└─ ... and %d more\n", baseIndent, remaining)
}
break
}
connector := "├─ "
isLast := (i == count-1) || (i == limit-1 && count <= limit)
if isLast {
connector = "└─ "
}
if colorEnabled {
p.Printf("%s%s%s%s%s (%spid %d%s)\n", baseIndent, ColorMagenta, connector, ColorReset, ChainName(child), ColorDim, child.PID, ColorReset)
} else {
p.Printf("%s%s%s (pid %d)\n", baseIndent, connector, ChainName(child), child.PID)
}
}
}