-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathview.go
More file actions
108 lines (90 loc) · 2.37 KB
/
view.go
File metadata and controls
108 lines (90 loc) · 2.37 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
100
101
102
103
104
105
106
107
108
package main
import (
"fmt"
"strings"
"time"
"charm.land/bubbles/v2/key"
tea "charm.land/bubbletea/v2"
)
// promptKeyMap defines keybindings for prompt mode
type promptKeyMap struct {
Confirm key.Binding
Cancel key.Binding
}
func (k promptKeyMap) ShortHelp() []key.Binding {
return []key.Binding{k.Confirm, k.Cancel}
}
func (k promptKeyMap) FullHelp() [][]key.Binding {
return [][]key.Binding{
{k.Confirm, k.Cancel},
}
}
// tableKeyMap defines keybindings for table view mode
type tableKeyMap struct {
Quit key.Binding
}
func (k tableKeyMap) ShortHelp() []key.Binding {
return []key.Binding{k.Quit}
}
func (k tableKeyMap) FullHelp() [][]key.Binding {
return [][]key.Binding{
{k.Quit},
}
}
// Handler that draws the UI of the application
func (m model) View() tea.View {
if m.promptActive {
pad := strings.Repeat(" ", padding)
var promptText string
if m.promptType == 2 {
promptText = "Enter duration in minutes: " + m.inputBuffer
} else {
promptText = "Enter task title: " + m.inputBuffer
}
promptKeys := promptKeyMap{
Confirm: m.keys.Confirm,
Cancel: m.keys.Cancel,
}
return tea.NewView("\n" + pad + promptText + "\n\n" + pad + m.help.View(promptKeys))
}
if m.mode == tableView {
pad := strings.Repeat(" ", padding)
// Apply padding to each line of the table
tableLines := strings.Split(m.table.View(), "\n")
paddedTable := make([]string, len(tableLines))
for i, line := range tableLines {
paddedTable[i] = pad + line
}
tableKeys := tableKeyMap{
Quit: m.keys.Quit,
}
m.status.SetKeyMap(tableKeys)
statusView := m.status.View()
return tea.NewView("\n" +
strings.Join(paddedTable, "\n") + "\n\n" +
statusView)
}
elapsed := time.Now().Unix() - m.startTime
remaining := m.targetDuration - elapsed
if m.countUpMode {
remaining = elapsed
}
if remaining < 0 {
// When it completes, display the original duration of the timer
remaining = 0
}
pad := strings.Repeat(" ", padding)
// Display title if provided
titleLine := ""
if m.title != "" {
titleLine = pad + m.title + "\n\n"
}
// Ensure status component has the full keymap for timer view
m.status.SetKeyMap(m.keys)
// status.View() handles displaying status messages OR help text
statusView := m.status.View()
return tea.NewView("\n" +
titleLine +
pad + m.progress.View() + fmt.Sprintf(" %s \n\n", formatDurationAsMMSS(remaining)) +
statusView)
}