-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsearch.go
More file actions
51 lines (41 loc) · 1.02 KB
/
search.go
File metadata and controls
51 lines (41 loc) · 1.02 KB
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
package main
import (
"strings"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/huh"
"github.com/spf13/cobra"
)
func searchPosts(cmd *cobra.Command, args []string) error {
var query string
// Use huh for search input
form := huh.NewForm(
huh.NewGroup(
huh.NewInput().
Title("Search journal entries").
Value(&query).
Placeholder("Enter search query..."),
),
)
if err := form.Run(); err != nil {
return err
}
query = strings.TrimSpace(query)
if query == "" {
// If empty query, just list recent posts
return listPosts(cmd, args)
}
// Run the list model in search mode with the query
model := newPostListModel(cfg, 50, "Search Results", false)
model.query = query
model.loading = true
p := tea.NewProgram(model, tea.WithAltScreen())
finalModel, err := p.Run()
if err != nil {
return err
}
// If a post was selected, display it with media
if finalModel.(postListModel).selected != nil {
return displayPost(cmd, finalModel.(postListModel).selected)
}
return nil
}