1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
package flamegraph
import (
"strings"
"charm.land/bubbles/v2/key"
tea "charm.land/bubbletea/v2"
)
func keyString(msg tea.KeyPressMsg) string {
if s := msg.String(); s != "" {
return s
}
return msg.Text
}
func isSearchOpenKey(msg tea.KeyPressMsg) bool { return keyString(msg) == "/" }
func isNextMatchKey(msg tea.KeyPressMsg) bool { return keyString(msg) == "n" }
func isPrevMatchKey(msg tea.KeyPressMsg) bool { return keyString(msg) == "N" }
func isPauseKey(msg tea.KeyPressMsg) bool {
k := keyString(msg)
return k == " " || k == "space" || msg.Code == tea.KeySpace
}
func isResetBaselineKey(msg tea.KeyPressMsg) bool {
return keyString(msg) == "r"
}
func isCycleOrderKey(msg tea.KeyPressMsg) bool { return keyString(msg) == "o" }
func isCycleMetricKey(msg tea.KeyPressMsg) bool {
return keyString(msg) == "b"
}
func isToggleHeightKey(msg tea.KeyPressMsg) bool { return keyString(msg) == "v" }
func isHelpToggleKey(msg tea.KeyPressMsg) bool { return keyString(msg) == "?" }
func isZoomInKey(msg tea.KeyPressMsg, keys flameKeyMap) bool {
return key.Matches(msg, keys.ZoomIn) || msg.Code == tea.KeyEnter || strings.EqualFold(keyString(msg), "enter")
}
func isZoomUndoKey(msg tea.KeyPressMsg, keys flameKeyMap) bool {
return key.Matches(msg, keys.ZoomUndo) || msg.Code == tea.KeyBackspace || msg.Code == tea.KeyEsc
}
func isZoomResetKey(msg tea.KeyPressMsg, keys flameKeyMap) bool {
return key.Matches(msg, keys.ZoomReset)
}
func isMoveShallowerKey(msg tea.KeyPressMsg, keys flameKeyMap) bool {
k := keyString(msg)
return key.Matches(msg, keys.MoveShallower) || msg.Code == tea.KeyDown || keyMatchesDirection(k, "down", 'B')
}
func isMoveDeeperKey(msg tea.KeyPressMsg, keys flameKeyMap) bool {
k := keyString(msg)
return key.Matches(msg, keys.MoveDeeper) || msg.Code == tea.KeyUp || keyMatchesDirection(k, "up", 'A')
}
func isPrevSiblingKey(msg tea.KeyPressMsg, keys flameKeyMap) bool {
k := keyString(msg)
return key.Matches(msg, keys.PrevSibling) || msg.Code == tea.KeyLeft || keyMatchesDirection(k, "left", 'D')
}
func isNextSiblingKey(msg tea.KeyPressMsg, keys flameKeyMap) bool {
k := keyString(msg)
return key.Matches(msg, keys.NextSibling) || msg.Code == tea.KeyRight || keyMatchesDirection(k, "right", 'C')
}
func isJumpTopKey(msg tea.KeyPressMsg, keys flameKeyMap) bool {
k := strings.ToLower(keyString(msg))
return key.Matches(msg, keys.JumpTop) || msg.Code == tea.KeyPgUp || k == "pgup" || k == "pageup"
}
func isJumpRootKey(msg tea.KeyPressMsg, keys flameKeyMap) bool {
k := strings.ToLower(keyString(msg))
return key.Matches(msg, keys.JumpRoot) || msg.Code == tea.KeyPgDown || k == "pgdown" || k == "pgdn" || k == "pagedown"
}
func keyMatchesDirection(keyName, plain string, ansiFinal byte) bool {
if keyName == plain || strings.HasSuffix(keyName, "+"+plain) {
return true
}
return isArrowEscapeSequence(keyName, ansiFinal)
}
func isArrowEscapeSequence(value string, ansiFinal byte) bool {
body, ok := strings.CutPrefix(value, "\x1b")
if !ok || len(body) < 2 {
return false
}
switch body[0] {
case '[':
return body[len(body)-1] == ansiFinal
case 'O':
return len(body) == 2 && body[1] == ansiFinal
default:
return false
}
}
|