diff options
Diffstat (limited to 'internal/tui/flamegraph/renderer.go')
| -rw-r--r-- | internal/tui/flamegraph/renderer.go | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/internal/tui/flamegraph/renderer.go b/internal/tui/flamegraph/renderer.go index 6fba0b6..ad74173 100644 --- a/internal/tui/flamegraph/renderer.go +++ b/internal/tui/flamegraph/renderer.go @@ -14,6 +14,7 @@ import ( ) const pathSeparator = "\x1f" +const pathSeparatorByte = '\x1f' const minFlameWidth = 60 // BuildTerminalLayout converts a live trie snapshot into terminal frame cells. @@ -224,7 +225,7 @@ func renderRow(frames []indexedFrame, width int, selectedPath string, subtreeSet continue } label := padOrTrim(frame.Name, cellWidth) - style := styleForFrame(item.idx, frame, selectedPath, subtreeSet, matchSet, selectedIdx, isDark, searchActive).Width(cellWidth) + style := styleForFrame(item.idx, frame, selectedPath, subtreeSet, matchSet, selectedIdx, isDark, searchActive) cell := style.Render(label) b.WriteString(cell) cursor = frame.Col + cellWidth @@ -255,14 +256,24 @@ func computeSubtreeSetInto(frames []tuiFrame, selectedIdx int, subtree map[int]b for idx, frame := range frames { path := frame.Path if path == selectedPath || - strings.HasPrefix(path, selectedPath+pathSeparator) || - strings.HasPrefix(selectedPath, path+pathSeparator) { + hasPathBoundaryPrefix(path, selectedPath) || + hasPathBoundaryPrefix(selectedPath, path) { subtree[idx] = true } } return subtree } +func hasPathBoundaryPrefix(value, prefix string) bool { + if len(value) <= len(prefix) { + return false + } + if !strings.HasPrefix(value, prefix) { + return false + } + return value[len(prefix)] == pathSeparatorByte +} + func styleForFrame(idx int, frame tuiFrame, selectedPath string, subtreeSet, matchSet map[int]bool, selectedIdx int, isDark, searchActive bool) lipgloss.Style { base := lipgloss.NewStyle(). Foreground(common.ColorBackground). |
