apps/jotts/tui/model.go 1018 B raw
1
package tui
2
3
import (
4
	"time"
5
6
	"charm.land/bubbles/v2/help"
7
	tea "charm.land/bubbletea/v2"
8
)
9
10
type sessionState uint8
11
12
const (
13
	stateList sessionState = iota
14
	stateContent
15
	stateForm
16
)
17
18
type Model struct {
19
	backend  Backend
20
	isRemote bool
21
22
	state sessionState
23
	list  listModel
24
	cont  contentModel
25
	form  formModel
26
27
	width, height int
28
	ready         bool
29
30
	showHelp      bool
31
	confirmDelete bool
32
33
	status      string
34
	statusOK    bool
35
	statusUntil time.Time
36
37
	help help.Model
38
	keys keyMap
39
}
40
41
func newModel(backend Backend, notes []Note, width, height int) Model {
42
	m := Model{
43
		backend:  backend,
44
		isRemote: backend.RemoteURL() != "",
45
		state:    stateList,
46
		list:     newListModel(notes),
47
		cont:     newContentModel(),
48
		form:     newFormModel(),
49
		help:     help.New(),
50
		keys:     defaultKeys(),
51
		width:    width,
52
		height:   height,
53
		ready:    true,
54
	}
55
	m.applyLayout()
56
	if n, ok := m.list.Selected(); ok {
57
		m.cont.SetNote(&n)
58
	}
59
	return m
60
}
61
62
func (m Model) Init() tea.Cmd {
63
	return tea.RequestWindowSize
64
}