-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Toby Padilla
committed
Aug 7, 2021
1 parent
e228d7d
commit 45ec4a8
Showing
5 changed files
with
186 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
package tui | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"smoothie/git" | ||
"smoothie/tui/bubbles/commits" | ||
"smoothie/tui/bubbles/selection" | ||
|
||
tea "github.com/charmbracelet/bubbletea" | ||
gg "github.com/go-git/go-git/v5" | ||
"github.com/go-git/go-git/v5/plumbing/object" | ||
) | ||
|
||
type windowMsg struct{} | ||
|
@@ -21,24 +26,76 @@ func (b *Bubble) windowChangesCmd() tea.Msg { | |
return windowMsg{} | ||
} | ||
|
||
func (b *Bubble) getRepoCmd(name string) tea.Cmd { | ||
return func() tea.Msg { | ||
r, err := b.repoSource.GetRepo(name) | ||
func (b *Bubble) loadGitCmd() tea.Msg { | ||
cn := "config" | ||
err := b.repoSource.LoadRepos() | ||
cr, err := b.repoSource.GetRepo(cn) | ||
if err == git.ErrMissingRepo { | ||
cr, err = b.repoSource.InitRepo(cn, false) | ||
if err != nil { | ||
return errMsg{err} | ||
} | ||
b.readmeViewport.Viewport.GotoTop() | ||
b.readmeViewport.Viewport.Height = b.height - verticalPadding - viewportHeightConstant | ||
b.readmeViewport.Viewport.Width = boxLeftWidth - 2 | ||
b.readmeViewport.Viewport.SetContent(r.Readme) | ||
b.boxes[1] = b.readmeViewport | ||
b.activeBox = 1 | ||
return nil | ||
} | ||
} | ||
|
||
func (b *Bubble) loadGitCmd() tea.Msg { | ||
// Add default README and config | ||
rp := filepath.Join(b.repoSource.Path, cn, "README.md") | ||
rf, err := os.Create(rp) | ||
if err != nil { | ||
return errMsg{err} | ||
} | ||
defer rf.Close() | ||
_, err = rf.WriteString(defaultReadme) | ||
if err != nil { | ||
return errMsg{err} | ||
} | ||
err = rf.Sync() | ||
if err != nil { | ||
return errMsg{err} | ||
} | ||
cp := filepath.Join(b.repoSource.Path, cn, "config.json") | ||
cf, err := os.Create(cp) | ||
if err != nil { | ||
return errMsg{err} | ||
} | ||
defer cf.Close() | ||
_, err = cf.WriteString(defaultConfig) | ||
if err != nil { | ||
return errMsg{err} | ||
} | ||
err = cf.Sync() | ||
if err != nil { | ||
return errMsg{err} | ||
} | ||
wt, err := cr.Repository.Worktree() | ||
if err != nil { | ||
return errMsg{err} | ||
} | ||
_, err = wt.Add("README.md") | ||
if err != nil { | ||
return errMsg{err} | ||
} | ||
_, err = wt.Add("config.json") | ||
if err != nil { | ||
return errMsg{err} | ||
} | ||
_, err = wt.Commit("Default init", &gg.CommitOptions{ | ||
All: true, | ||
Author: &object.Signature{ | ||
Name: "Smoothie Server", | ||
Email: "[email protected]", | ||
}, | ||
}) | ||
if err != nil { | ||
return errMsg{err} | ||
} | ||
err = b.repoSource.LoadRepos() | ||
if err != nil { | ||
return errMsg{err} | ||
} | ||
} else if err != nil { | ||
return errMsg{err} | ||
} | ||
b.repos = b.repoSource.AllRepos() | ||
|
||
rs := make([]string, 0) | ||
for _, r := range b.repos { | ||
rs = append(rs, r.Name) | ||
|
@@ -55,3 +112,19 @@ func (b *Bubble) loadGitCmd() tea.Msg { | |
b.state = loadedState | ||
return nil | ||
} | ||
|
||
func (b *Bubble) getRepoCmd(name string) tea.Cmd { | ||
return func() tea.Msg { | ||
r, err := b.repoSource.GetRepo(name) | ||
if err != nil { | ||
return errMsg{err} | ||
} | ||
b.readmeViewport.Viewport.GotoTop() | ||
b.readmeViewport.Viewport.Height = b.height - verticalPadding - viewportHeightConstant | ||
b.readmeViewport.Viewport.Width = boxLeftWidth - 2 | ||
b.readmeViewport.Viewport.SetContent(r.Readme) | ||
b.boxes[1] = b.readmeViewport | ||
b.activeBox = 1 | ||
return nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package tui | ||
|
||
const defaultReadme = "# Smoothie\nWelcome to Smoothie. To setup your own configuration, please clone this repo." | ||
|
||
const defaultConfig = `{ | ||
"name": "Smoothie", | ||
"show_all_repos": true, | ||
"menu": [ | ||
{ | ||
"name": "Home", | ||
"repo": "config", | ||
"note": "" | ||
} | ||
] | ||
}` |