Skip to content

Commit 7bf3efa

Browse files
committed
feat(tui): add size and maxPages configuration support
Add support for configuring result size and maximum pages in the interactive TUI mode. This allows users to control pagination behavior when running queries in interactive mode, matching the flexibility available in non-interactive mode. Changes: - Add size and maxPages parameters to runInteractive function - Store size and maxPages in the model struct - Pass size and maxPages from CLI flags to TUI initialization - Use configured values when executing queries instead of hardcoded defaults (100 size, 1 maxPage)
1 parent a943df2 commit 7bf3efa

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

loggly.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ func main() {
240240
assert(*token != "", "-token required")
241241

242242
if *tui {
243-
runInteractive(ctx, *account, query, *token, *from, *to)
243+
runInteractive(ctx, *account, *token, *size, *maxPages, query, *from, *to)
244244
return
245245
}
246246

tui.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,13 @@ func (i valueItem) Title() string { return i.value }
133133
func (i valueItem) Description() string { return fmt.Sprintf("%d occurrences", i.count) }
134134

135135
type model struct {
136-
ctx context.Context
137-
account string
138-
token string
139-
from string
140-
to string
136+
ctx context.Context
137+
account string
138+
token string
139+
from string
140+
to string
141+
size int
142+
maxPages int64
141143

142144
queryInput textinput.Model
143145
fieldsList list.Model
@@ -190,7 +192,7 @@ var (
190192
Foreground(lipgloss.Color("241"))
191193
)
192194

193-
func initialModel(ctx context.Context, account, token, query, from, to string) model {
195+
func initialModel(ctx context.Context, account, token string, size int, maxPages int64, query, from, to string) model {
194196
ti := textinput.New()
195197
ti.Placeholder = "Enter your Loggly query..."
196198
ti.Focus()
@@ -225,6 +227,8 @@ func initialModel(ctx context.Context, account, token, query, from, to string) m
225227
ctx: ctx,
226228
account: account,
227229
token: token,
230+
size: size,
231+
maxPages: maxPages,
228232
from: from,
229233
to: to,
230234
queryInput: ti,
@@ -494,7 +498,7 @@ func (m *model) executeQuery() tea.Cmd {
494498
}
495499

496500
c := search.New(m.account, m.token).SetConcurrency(1)
497-
q := search.NewQuery(query).Size(100).From(m.from).To(m.to).MaxPage(1)
501+
q := search.NewQuery(query).Size(m.size).From(m.from).To(m.to).MaxPage(m.maxPages)
498502
resChan, errChan := c.Fetch(m.ctx, *q)
499503

500504
var results []map[string]any
@@ -685,9 +689,9 @@ func (m *model) showDetailView(item resultItem) {
685689
m.detailView.SetContent(string(data))
686690
}
687691

688-
func runInteractive(ctx context.Context, account, query, token, from, to string) {
692+
func runInteractive(ctx context.Context, account, token string, size int, maxPages int64, query, from, to string) {
689693
p := tea.NewProgram(
690-
initialModel(ctx, account, token, query, from, to),
694+
initialModel(ctx, account, token, size, maxPages, query, from, to),
691695
tea.WithAltScreen(),
692696
)
693697

0 commit comments

Comments
 (0)