summaryrefslogtreecommitdiff
path: root/internal/tui
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-05-13 09:45:09 +0300
committerPaul Buetow <paul@buetow.org>2026-05-13 09:45:09 +0300
commit6c7a5d5fb3e88068799fb414e316b6bec31015e9 (patch)
treec47a73f3fd3d3a1089f77e00934bcdb45168965c /internal/tui
parent50d5220ed5a2187dbf548d70f3d795a39f7bfd00 (diff)
split globalfilter presentation and parsing into sub-packages
Move ParseDurationNs to globalfilter/parser and move CompareOpSymbol, AppendStringSummary, AppendNumericSummary, FilterSummary to globalfilter/presenter. The domain Filter type retains only matching, equality, clone, and active-predicate logic. All callers updated; tests for the new sub-packages added. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'internal/tui')
-rw-r--r--internal/tui/dashboard/model.go3
-rw-r--r--internal/tui/eventstream/filter.go9
-rw-r--r--internal/tui/eventstream/filter_test.go8
-rw-r--r--internal/tui/eventstream/render.go3
-rw-r--r--internal/tui/filterstack.go11
-rw-r--r--internal/tui/tracefilter/model.go3
6 files changed, 24 insertions, 13 deletions
diff --git a/internal/tui/dashboard/model.go b/internal/tui/dashboard/model.go
index 123600a..8548481 100644
--- a/internal/tui/dashboard/model.go
+++ b/internal/tui/dashboard/model.go
@@ -7,6 +7,7 @@ import (
"time"
"ior/internal/globalfilter"
+ "ior/internal/globalfilter/presenter"
"ior/internal/statsengine"
common "ior/internal/tui/common"
"ior/internal/tui/eventstream"
@@ -1104,7 +1105,7 @@ func (m Model) View() tea.View {
}
func (m Model) filterSummary() string {
- summary := "filter: " + m.globalFilter.Summary()
+ summary := "filter: " + presenter.FilterSummary(m.globalFilter)
if len(m.filterStack) > 0 {
summary += " | stack: " + strings.Join(m.filterStack, " | ")
}
diff --git a/internal/tui/eventstream/filter.go b/internal/tui/eventstream/filter.go
index 61d8c33..801b8ba 100644
--- a/internal/tui/eventstream/filter.go
+++ b/internal/tui/eventstream/filter.go
@@ -1,6 +1,9 @@
package eventstream
-import "ior/internal/globalfilter"
+import (
+ "ior/internal/globalfilter"
+ "ior/internal/globalfilter/parser"
+)
type CompareOp = globalfilter.CompareOp
type NumericFilter = globalfilter.NumericFilter
@@ -16,6 +19,8 @@ const (
OpLte = globalfilter.OpLte
)
+// ParseDurationNs delegates to parser.ParseDurationNs, re-exporting the
+// duration parsing helper for eventstream callers.
func ParseDurationNs(input string) (int64, error) {
- return globalfilter.ParseDurationNs(input)
+ return parser.ParseDurationNs(input)
}
diff --git a/internal/tui/eventstream/filter_test.go b/internal/tui/eventstream/filter_test.go
index 0413904..efedbe4 100644
--- a/internal/tui/eventstream/filter_test.go
+++ b/internal/tui/eventstream/filter_test.go
@@ -3,6 +3,8 @@ package eventstream
import (
"strings"
"testing"
+
+ "ior/internal/globalfilter/presenter"
)
func sampleEvent() StreamEvent {
@@ -31,8 +33,8 @@ func TestFilterZeroValueMatchesAll(t *testing.T) {
if f.IsActive() {
t.Fatalf("zero-value filter should be inactive")
}
- if got := f.Summary(); got != "all" {
- t.Fatalf("Summary() = %q, want all", got)
+ if got := presenter.FilterSummary(f); got != "all" {
+ t.Fatalf("FilterSummary() = %q, want all", got)
}
}
@@ -120,7 +122,7 @@ func TestFilterSummaryIncludesActivePredicates(t *testing.T) {
PID: &NumericFilter{Op: OpEq, Value: 1234},
LatencyNs: &NumericFilter{Op: OpGt, Value: 1000000},
}
- got := f.Summary()
+ got := presenter.FilterSummary(f)
for _, wantPart := range []string{"errors", "syscall~read", "pid=1234", "latency>1ms"} {
if !strings.Contains(got, wantPart) {
t.Fatalf("Summary() = %q, missing %q", got, wantPart)
diff --git a/internal/tui/eventstream/render.go b/internal/tui/eventstream/render.go
index 4d7970b..cd4d528 100644
--- a/internal/tui/eventstream/render.go
+++ b/internal/tui/eventstream/render.go
@@ -5,6 +5,7 @@ import (
"strconv"
"strings"
+ "ior/internal/globalfilter/presenter"
"ior/internal/tui/common"
"charm.land/lipgloss/v2"
@@ -75,7 +76,7 @@ func renderStatusLine(paused bool, totalCount, filteredCount, bufferLen, bufferC
}
func renderFilterLine(filter Filter) string {
- summary := filter.Summary()
+ summary := presenter.FilterSummary(filter)
if summary == "all" {
summary = common.HighlightStyle.Render(summary)
}
diff --git a/internal/tui/filterstack.go b/internal/tui/filterstack.go
index dbd26a0..016d845 100644
--- a/internal/tui/filterstack.go
+++ b/internal/tui/filterstack.go
@@ -4,6 +4,7 @@ import (
"strings"
"ior/internal/globalfilter"
+ "ior/internal/globalfilter/presenter"
)
// filterStack manages the trace filter chain: the active filter, the undo
@@ -124,14 +125,14 @@ func globalFilterActionLabel(prev, next globalfilter.Filter, action string) stri
parts = appendNumericFilterChange(parts, "bytes", prev.Bytes, next.Bytes, false)
parts = appendNumericFilterChange(parts, "ret", prev.RetVal, next.RetVal, false)
if len(parts) == 0 {
- return next.Summary()
+ return presenter.FilterSummary(next)
}
return strings.Join(parts, " ")
}
// appendStringFilterChange appends a change token to parts for a string
// filter field. It emits "clear name" when the filter is removed, or delegates
-// to globalfilter.AppendStringSummary for the canonical "name~pattern" format.
+// to presenter.AppendStringSummary for the canonical "name~pattern" format.
func appendStringFilterChange(parts []string, name string, prev, next *globalfilter.StringFilter) []string {
if sameStringFilter(prev, next) {
return parts
@@ -139,12 +140,12 @@ func appendStringFilterChange(parts []string, name string, prev, next *globalfil
if next == nil || strings.TrimSpace(next.Pattern) == "" {
return append(parts, "clear "+name)
}
- return globalfilter.AppendStringSummary(parts, name, next)
+ return presenter.AppendStringSummary(parts, name, next)
}
// appendNumericFilterChange appends a change token to parts for a numeric
// filter field. It emits "clear name" when the filter is removed, or delegates
-// to globalfilter.AppendNumericSummary for the canonical "nameOPvalue" format.
+// to presenter.AppendNumericSummary for the canonical "nameOPvalue" format.
func appendNumericFilterChange(parts []string, name string, prev, next *globalfilter.NumericFilter, duration bool) []string {
if sameNumericFilter(prev, next) {
return parts
@@ -152,7 +153,7 @@ func appendNumericFilterChange(parts []string, name string, prev, next *globalfi
if next == nil {
return append(parts, "clear "+name)
}
- return globalfilter.AppendNumericSummary(parts, name, next, duration)
+ return presenter.AppendNumericSummary(parts, name, next, duration)
}
func sameStringFilter(a, b *globalfilter.StringFilter) bool {
diff --git a/internal/tui/tracefilter/model.go b/internal/tui/tracefilter/model.go
index caef948..b46d50a 100644
--- a/internal/tui/tracefilter/model.go
+++ b/internal/tui/tracefilter/model.go
@@ -6,6 +6,7 @@ import (
"strings"
"ior/internal/globalfilter"
+ "ior/internal/globalfilter/parser"
"charm.land/bubbles/v2/textinput"
tea "charm.land/bubbletea/v2"
@@ -323,7 +324,7 @@ func parseNumericFilter(value string, opIndex int, duration bool) (*globalfilter
err error
)
if duration {
- number, err = globalfilter.ParseDurationNs(value)
+ number, err = parser.ParseDurationNs(value)
} else {
number, err = strconv.ParseInt(value, 10, 64)
}