-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.go
More file actions
91 lines (75 loc) · 1.92 KB
/
model.go
File metadata and controls
91 lines (75 loc) · 1.92 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
package main
import (
"os/exec"
"time"
"github.com/charmbracelet/bubbles/viewport"
tea "github.com/charmbracelet/bubbletea"
)
type Panel int
const (
PanelStories Panel = iota
PanelOutput
)
type Model struct {
prd PRD
stories []Story
completedCount int
currentIteration int
maxIterations int
currentStoryID string
iterationStart time.Time
storyStartTimes map[string]time.Time
storyDurations map[string]time.Duration
processRunning bool
processDone bool
processError error
initError error
runningCmd *exec.Cmd
outputLines []string
outputViewport viewport.Model
storyScroll int
showHelp bool
searchMode bool
searchQuery string
prdUpdateNotif string
prdUpdateNotifEnd time.Time
width int
height int
focusedPanel Panel
prdPath string
promptPath string
projectRoot string
msgChan chan interface{}
}
func NewModel(prdPath, promptPath, projectRoot string, maxIterations int) Model {
prd, err := LoadPRD(prdPath)
m := Model{
prd: prd,
stories: prd.UserStories,
completedCount: CountCompleted(prd.UserStories),
currentIteration: 0,
maxIterations: maxIterations,
outputLines: []string{},
outputViewport: viewport.New(80, 20),
focusedPanel: PanelOutput,
prdPath: prdPath,
promptPath: promptPath,
projectRoot: projectRoot,
msgChan: make(chan interface{}, 100),
initError: err,
storyStartTimes: make(map[string]time.Time),
storyDurations: make(map[string]time.Duration),
}
if err != nil {
m.outputLines = append(m.outputLines, "ERROR: Failed to load PRD file: "+err.Error())
m.outputLines = append(m.outputLines, "Path: "+prdPath)
m.outputViewport.SetContent(string(m.outputLines[0]) + "\n" + m.outputLines[1])
}
return m
}
func (m Model) Init() tea.Cmd {
return tea.Batch(
watchPRDCmd(m.prdPath),
tickCmd(),
)
}