Skip to content

Commit 8062b2e

Browse files
committed
feat(tui): improve list filtering and layout sizing
- Enable filtering on results list for better navigation - Update FilterValue() to use full JSON data for better search - Hide help text on fields and values lists to save space - Adjust pane width calculation to use cell-based sizing - Expand query input width to use full available space - Increase detail view height for better content visibility - Remove redundant resultsList size setting after items update
1 parent 304b868 commit 8062b2e

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

tui.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,10 @@ type resultItem struct {
112112
data map[string]any
113113
}
114114

115-
func (i resultItem) FilterValue() string { return fmt.Sprintf("Result %d", i.index+1) }
115+
func (i resultItem) FilterValue() string {
116+
data, _ := json.Marshal(i.data)
117+
return string(data)
118+
}
116119
func (i resultItem) Title() string {
117120
data, _ := json.Marshal(i.data)
118121
preview := string(data)
@@ -207,11 +210,13 @@ func initialModel(ctx context.Context, config Config, query string) model {
207210
fieldsList := list.New([]list.Item{}, list.NewDefaultDelegate(), 20, 20)
208211
fieldsList.Title = "Fields"
209212
fieldsList.SetShowStatusBar(false)
213+
fieldsList.SetShowHelp(false)
210214
fieldsList.SetFilteringEnabled(true)
211215

212216
valuesList := list.New([]list.Item{}, list.NewDefaultDelegate(), 20, 20)
213217
valuesList.Title = "Values"
214218
valuesList.SetShowStatusBar(false)
219+
valuesList.SetShowHelp(false)
215220
valuesList.SetFilteringEnabled(true)
216221

217222
// Results list showing compact previews
@@ -223,6 +228,7 @@ func initialModel(ctx context.Context, config Config, query string) model {
223228
resultsList.SetShowPagination(true)
224229
resultsList.SetShowTitle(true)
225230
resultsList.DisableQuitKeybindings()
231+
resultsList.SetFilteringEnabled(true)
226232

227233
// Detail viewport for full JSON view
228234
detailView := viewport.New(0, 0)
@@ -389,15 +395,18 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
389395
func (m *model) updateSizes() {
390396
// Each pane with border takes content_width + 2 (for left/right border)
391397
// We have 3 panes, so 6 chars total for borders
392-
leftPaneWidth := m.width / 7 // 16% for fields
393-
midPaneWidth := m.width / 7 // ~16% for values
398+
cellWidth := m.width / 12
399+
leftPaneWidth := cellWidth * 2 // ~16% for fields
400+
midPaneWidth := cellWidth * 2 // ~16% for values
394401

395402
// Calculate results width: total - fields - values - all borders
396403
borderWidth := 6 // 2 chars per pane * 3 panes
397404
rightPaneWidth := m.width - leftPaneWidth - midPaneWidth - borderWidth
398405

399406
paneHeight := m.height - 8
400407

408+
m.queryInput.Width = m.width - 4
409+
401410
// Set sizes to content area (borders will be added by lipgloss)
402411
m.fieldsList.SetSize(leftPaneWidth, paneHeight-2)
403412
m.valuesList.SetSize(midPaneWidth, paneHeight-2)
@@ -411,7 +420,7 @@ func (m *model) updateSizes() {
411420

412421
// Detail view uses most of the screen
413422
m.detailView.Width = m.width - 10
414-
m.detailView.Height = m.height - 12
423+
m.detailView.Height = m.height - 6
415424

416425
m.debugView = fmt.Sprintf("Sizes: total=%d, left=%d, mid=%d, right=%d, hight=%d", m.width, leftPaneWidth, midPaneWidth, rightPaneWidth, paneHeight)
417426
}
@@ -447,7 +456,7 @@ func (m model) View() string {
447456
if m.currentPane == queryPane {
448457
queryStyle = activeStyle
449458
}
450-
querySection := queryStyle.Width(m.width - 4).Render(
459+
querySection := queryStyle.Width(m.width - 2).Render(
451460
lipgloss.JoinVertical(lipgloss.Left,
452461
titleStyle.Render("Query"),
453462
m.queryInput.View(),
@@ -676,10 +685,6 @@ func (m *model) updateResultsView() {
676685
}
677686

678687
m.resultsList.SetItems(items)
679-
// Ensure size is set after adding items
680-
if m.resultsWidth > 0 && m.paneHeight > 0 {
681-
m.resultsList.SetSize(m.resultsWidth, m.paneHeight)
682-
}
683688
}
684689

685690
func replaceExisitingSearch(query, field, value string) string {

0 commit comments

Comments
 (0)