-
Notifications
You must be signed in to change notification settings - Fork 0
/
list-screen.go
69 lines (57 loc) · 1.5 KB
/
list-screen.go
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"github.com/charmbracelet/bubbles/textinput"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
)
var docStyle = lipgloss.NewStyle().Margin(1, 2)
type item struct {
title, desc string
}
func (i item) Title() string { return i.title }
func (i item) Description() string { return i.desc }
func (i item) FilterValue() string { return i.title }
type listScreen struct {
model *model
}
func (t *listScreen) Reset() {
t.model.list.ResetFilter()
t.model.queryTextInput.Reset()
}
func (t *listScreen) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.KeyMsg:
switch msg.String() {
case "space", " ":
t.model.selectedTopic = append(t.model.selectedTopic, t.model.list.SelectedItem())
t.model.list.RemoveItem(t.model.list.Index())
return t.model, nil
}
switch msg.Type {
case tea.KeyEsc:
tm := textinput.NewModel()
tm.Placeholder = "Your query"
tm.Focus()
tm.CharLimit = 156
tm.Width = 20
m := model{
queryTextInput: tm,
}
setCurrentScreen(&searchScreen{model: &m})
case tea.KeyCtrlC:
return t.model, tea.Quit
case tea.KeyEnter:
setCurrentScreen(&resultsScreen{model: t.model})
return t.model, nil
}
case tea.WindowSizeMsg:
h, v := docStyle.GetFrameSize()
t.model.list.SetSize(msg.Width-h, msg.Height-v)
}
var cmd tea.Cmd
t.model.list, cmd = t.model.list.Update(msg)
return t.model, cmd
}
func (t listScreen) View() string {
return docStyle.Render(t.model.list.View())
}