-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.go
More file actions
99 lines (84 loc) · 2.12 KB
/
model.go
File metadata and controls
99 lines (84 loc) · 2.12 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package main
import (
"time"
"charm.land/bubbles/v2/help"
"charm.land/bubbles/v2/key"
"charm.land/bubbles/v2/progress"
"charm.land/bubbles/v2/table"
tea "charm.land/bubbletea/v2"
"tiny-timer/status"
)
type tickMsg time.Time
type promptMsg struct {
title string
logDB bool
}
type viewMode int
const (
timerView viewMode = iota
tableView
)
type promptType int
const (
promptLogAndReset promptType = iota // Log session to DB and reset timer (d key)
promptEditTitle // Edit title without logging (t key)
promptSetDuration // Set target duration in minutes (m key)
)
type session struct {
id int
datetime string
duration int64
completed bool
title string
}
// keyMap defines a set of keybindings. To work for help it must satisfy
// key.Map. It could also very easily be a map[string]key.Binding.
type keyMap struct {
Done key.Binding
History key.Binding
Title key.Binding
Minutes key.Binding
Reset key.Binding
Quit key.Binding
Confirm key.Binding
Cancel key.Binding
Backspace key.Binding
}
// ShortHelp returns keybindings to be shown in the mini help view. It's part
// of the key.Map interface.
func (k keyMap) ShortHelp() []key.Binding {
return []key.Binding{k.Done, k.History, k.Title, k.Minutes, k.Reset, k.Quit}
}
// FullHelp returns keybindings for the expanded help view. It's part of the
// key.Map interface.
func (k keyMap) FullHelp() [][]key.Binding {
return [][]key.Binding{
{k.Done, k.History, k.Title, k.Minutes, k.Reset}, // first column
{k.Quit}, // second column
}
}
type model struct {
progress progress.Model
startTime int64
targetDuration int64
title string
mode viewMode
table table.Model
countUpMode bool
inputBuffer string
promptActive bool
promptType promptType
help help.Model
keys keyMap
status *status.StatusCmp
}
// Start the event loop
func (m model) Init() tea.Cmd {
return tickCmd()
}
// Configure the event loop to run
func tickCmd() tea.Cmd {
return tea.Tick(time.Second*1, func(t time.Time) tea.Msg {
return tickMsg(t)
})
}