mirror of
https://github.com/taigrr/gico.git
synced 2026-04-02 03:09:07 -07:00
remove debug line, add basic tea structure
This commit is contained in:
111
cmd/cli/cli.go
111
cmd/cli/cli.go
@@ -37,11 +37,25 @@ func xmain() {
|
|||||||
type errMsg error
|
type errMsg error
|
||||||
|
|
||||||
type model struct {
|
type model struct {
|
||||||
SettingsModel any
|
SettingsModel Settings
|
||||||
GraphModel any
|
GraphModel Graph
|
||||||
CommitModel any
|
CommitLogModel CommitLog
|
||||||
quitting bool
|
HelpModel Help
|
||||||
err error
|
quitting bool
|
||||||
|
err error
|
||||||
|
}
|
||||||
|
|
||||||
|
type Help struct{}
|
||||||
|
|
||||||
|
type CommitLog struct{}
|
||||||
|
|
||||||
|
type Settings struct{}
|
||||||
|
|
||||||
|
type Graph struct {
|
||||||
|
Selected int
|
||||||
|
Year int
|
||||||
|
Repos []string
|
||||||
|
Authors []string
|
||||||
}
|
}
|
||||||
|
|
||||||
var quitKeys = key.NewBinding(
|
var quitKeys = key.NewBinding(
|
||||||
@@ -49,14 +63,89 @@ var quitKeys = key.NewBinding(
|
|||||||
key.WithHelp("", "press q to quit"),
|
key.WithHelp("", "press q to quit"),
|
||||||
)
|
)
|
||||||
|
|
||||||
func initialModel() model {
|
func initialModel() (model, error) {
|
||||||
return model{}
|
var m model
|
||||||
|
var err error
|
||||||
|
m.GraphModel, err = NewGraph()
|
||||||
|
if err != nil {
|
||||||
|
return m, err
|
||||||
|
}
|
||||||
|
return m, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m model) Init() tea.Cmd {
|
func (m model) Init() tea.Cmd {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m Settings) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m Settings) Init() tea.Cmd {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m Settings) View() string {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m CommitLog) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m CommitLog) Init() tea.Cmd {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m CommitLog) View() string {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m Graph) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
|
switch msg := msg.(type) {
|
||||||
|
case tea.Key:
|
||||||
|
switch msg.String() {
|
||||||
|
case "up":
|
||||||
|
case "left":
|
||||||
|
if m.Selected > 6 {
|
||||||
|
m.Selected -= 7
|
||||||
|
} else {
|
||||||
|
// TODO calculate the square for this day last year
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewGraph() (Graph, error) {
|
||||||
|
var m Graph
|
||||||
|
now := time.Now()
|
||||||
|
today := now.YearDay()
|
||||||
|
year := now.Year()
|
||||||
|
aName, _ := commits.GetAuthorName()
|
||||||
|
aEmail, _ := commits.GetAuthorEmail()
|
||||||
|
authors := []string{aName, aEmail}
|
||||||
|
mr, err := commits.GetMRRepos()
|
||||||
|
if err != nil {
|
||||||
|
return m, err
|
||||||
|
}
|
||||||
|
m.Repos = mr
|
||||||
|
m.Authors = authors
|
||||||
|
m.Year = year
|
||||||
|
m.Selected = today
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m Graph) Init() tea.Cmd {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m Graph) View() string {
|
||||||
|
mr := commits.RepoSet(m.Repos)
|
||||||
|
gfreq, _ := mr.FrequencyChan(m.Year, m.Authors)
|
||||||
|
return gfreq.String()
|
||||||
|
}
|
||||||
|
|
||||||
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
switch msg := msg.(type) {
|
switch msg := msg.(type) {
|
||||||
|
|
||||||
@@ -84,11 +173,15 @@ func (m model) View() string {
|
|||||||
if m.quitting {
|
if m.quitting {
|
||||||
return "\n"
|
return "\n"
|
||||||
}
|
}
|
||||||
return ""
|
return m.GraphModel.View()
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
p := tea.NewProgram(initialModel())
|
m, err := initialModel()
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
p := tea.NewProgram(m)
|
||||||
if _, err := p.Run(); err != nil {
|
if _, err := p.Run(); err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package commits
|
package commits
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
@@ -61,7 +60,6 @@ func YearFreqFromChan(cc chan types.Commit, year int) types.Freq {
|
|||||||
freq := make([]int, yearLength)
|
freq := make([]int, yearLength)
|
||||||
for commit := range cc {
|
for commit := range cc {
|
||||||
freq[commit.TimeStamp.YearDay()-1]++
|
freq[commit.TimeStamp.YearDay()-1]++
|
||||||
fmt.Println(commit)
|
|
||||||
}
|
}
|
||||||
return freq
|
return freq
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user