-
Notifications
You must be signed in to change notification settings - Fork 2
/
mainmodel.go
58 lines (48 loc) · 1.1 KB
/
mainmodel.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
package main
import (
"github.com/charmbracelet/bubbles/list"
tea "github.com/charmbracelet/bubbletea"
)
type sessionState uint
const (
articleList sessionState = iota
article
)
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 Model struct {
state sessionState
list list.Model
}
func New() *Model {
items := []list.Item{item{title: "Best book ever", desc: ""}, item{title: "Huberman Lab is my Favourite Podcast", desc: ""}}
list := list.New(items, list.NewDefaultDelegate(), 0, 0)
return &Model{state: articleList, list: list}
}
func (m Model) Init() tea.Cmd {
return nil
}
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
var cmd tea.Cmd
switch m.state {
default:
m.list, cmd = m.list.Update(msg)
}
switch msg := msg.(type) {
case tea.KeyMsg:
if msg.String() == "ctrl+c" || msg.String() == "q" {
cmd = tea.Quit
}
}
return m, cmd
}
func (m Model) View() string {
switch m.state {
default:
return m.list.View()
}
}