repos / pico

pico services mono repo
git clone https://github.com/picosh/pico.git

commit
c4c4e8b
parent
30b695c
author
Eric Bower
date
2025-05-13 12:04:40 -0400 EDT
fix(tui): logs now properly filter when typing
1 files changed,  +34, -17
M pkg/tui/logs.go
+34, -17
 1@@ -46,27 +46,34 @@ func (m *LogsPage) Footer() []Shortcut {
 2 	return []Shortcut{}
 3 }
 4 
 5+func (m *LogsPage) filterLogLine(match string, ll *LogLine) bool {
 6+	if match == "" {
 7+		return true
 8+	}
 9+
10+	lvlMatch := matched(ll.Level, match)
11+	msgMatch := matched(ll.Msg, match)
12+	serviceMatch := matched(ll.Service, match)
13+	errMatch := matched(ll.ErrMsg, match)
14+	urlMatch := matched(ll.Url, match)
15+	statusMatch := matched(fmt.Sprintf("%d", ll.Status), match)
16+
17+	if !lvlMatch && !msgMatch && !serviceMatch && !errMatch && !urlMatch && !statusMatch {
18+		return false
19+	}
20+
21+	return true
22+}
23+
24 func (m *LogsPage) filterLogs() {
25 	match := m.input.GetValue()
26-	m.filtered = []int{}
27+	filtered := []int{}
28 	for idx, ll := range m.logs {
29-		if match == "" {
30-			m.filtered = append(m.filtered, idx)
31-			continue
32-		}
33-
34-		lvlMatch := matched(ll.Level, match)
35-		msgMatch := matched(ll.Msg, match)
36-		serviceMatch := matched(ll.Service, match)
37-		errMatch := matched(ll.ErrMsg, match)
38-		urlMatch := matched(ll.Url, match)
39-		statusMatch := matched(fmt.Sprintf("%d", ll.Status), match)
40-		if !lvlMatch && !msgMatch && !serviceMatch && !errMatch && !urlMatch && !statusMatch {
41-			continue
42+		if m.filterLogLine(match, ll) {
43+			filtered = append(m.filtered, idx)
44 		}
45-
46-		m.filtered = append(m.filtered, idx)
47 	}
48+	m.filtered = filtered
49 
50 	// scroll to bottom
51 	if len(m.filtered) > 0 {
52@@ -74,6 +81,15 @@ func (m *LogsPage) filterLogs() {
53 	}
54 }
55 
56+func (m *LogsPage) CaptureEvent(ev vaxis.Event) (vxfw.Command, error) {
57+	switch ev.(type) {
58+	case vaxis.Key:
59+		m.filterLogs()
60+		return vxfw.RedrawCmd{}, nil
61+	}
62+	return nil, nil
63+}
64+
65 func (m *LogsPage) HandleEvent(ev vaxis.Event, phase vxfw.EventPhase) (vxfw.Command, error) {
66 	switch msg := ev.(type) {
67 	case PageIn:
68@@ -84,7 +100,8 @@ func (m *LogsPage) HandleEvent(ev vaxis.Event, phase vxfw.EventPhase) (vxfw.Comm
69 	case PageOut:
70 		m.done()
71 	case LogLineLoaded:
72-		m.logs = append(m.logs, NewLogLine(msg.Line))
73+		ll := NewLogLine(msg.Line)
74+		m.logs = append(m.logs, ll)
75 		m.filterLogs()
76 		return vxfw.RedrawCmd{}, nil
77 	}