Detailed changes
@@ -1,11 +1,10 @@
package footer
import (
- "strings"
-
"github.com/charmbracelet/bubbles/help"
"github.com/charmbracelet/bubbles/key"
tea "github.com/charmbracelet/bubbletea"
+ "github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/soft-serve/ui/common"
)
@@ -80,5 +79,5 @@ func (f *Footer) SetShowAll(show bool) {
// Height returns the height of the footer.
func (f *Footer) Height() int {
- return len(strings.Split(f.View(), "\n"))
+ return lipgloss.Height(f.View())
}
@@ -156,6 +156,7 @@ func (f *Files) Init() tea.Cmd {
f.currentItem = nil
f.activeView = filesViewFiles
f.lastSelected = make([]int, 0)
+ f.selector.Select(0)
return f.updateFilesCmd
}
@@ -164,7 +165,6 @@ func (f *Files) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
cmds := make([]tea.Cmd, 0)
switch msg := msg.(type) {
case RepoMsg:
- f.selector.Select(0)
f.repo = git.GitRepo(msg)
cmds = append(cmds, f.Init())
case RefMsg:
@@ -147,9 +147,12 @@ func (l *Log) FullHelp() [][]key.Binding {
// Init implements tea.Model.
func (l *Log) Init() tea.Cmd {
- cmds := make([]tea.Cmd, 0)
- cmds = append(cmds, l.updateCommitsCmd)
- return tea.Batch(cmds...)
+ l.activeView = logViewCommits
+ l.nextPage = 0
+ l.count = 0
+ l.activeCommit = nil
+ l.selector.Select(0)
+ return l.updateCommitsCmd
}
// Update implements tea.Model.
@@ -157,15 +160,11 @@ func (l *Log) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
cmds := make([]tea.Cmd, 0)
switch msg := msg.(type) {
case RepoMsg:
- l.count = 0
- l.selector.Select(0)
- l.nextPage = 0
- l.activeView = 0
l.repo = git.GitRepo(msg)
+ cmds = append(cmds, l.Init())
case RefMsg:
l.ref = msg
- l.count = 0
- cmds = append(cmds, l.countCommitsCmd)
+ cmds = append(cmds, l.Init())
case LogCountMsg:
l.count = int64(msg)
case LogItemsMsg:
@@ -11,43 +11,63 @@ import (
"github.com/charmbracelet/soft-serve/ui/styles"
)
+// RefItem is a git reference item.
type RefItem struct {
*git.Reference
}
+// ID implements selector.IdentifiableItem.
func (i RefItem) ID() string {
return i.Reference.Name().String()
}
+// Title implements list.DefaultItem.
func (i RefItem) Title() string {
return i.Reference.Name().Short()
}
+// Description implements list.DefaultItem.
func (i RefItem) Description() string {
return ""
}
+// Short returns the short name of the reference.
func (i RefItem) Short() string {
return i.Reference.Name().Short()
}
+// FilterValue implements list.Item.
func (i RefItem) FilterValue() string { return i.Short() }
+// RefItems is a list of git references.
type RefItems []RefItem
-func (cl RefItems) Len() int { return len(cl) }
+// Len implements sort.Interface.
+func (cl RefItems) Len() int { return len(cl) }
+
+// Swap implements sort.Interface.
func (cl RefItems) Swap(i, j int) { cl[i], cl[j] = cl[j], cl[i] }
+
+// Less implements sort.Interface.
func (cl RefItems) Less(i, j int) bool {
return cl[i].Short() < cl[j].Short()
}
+// RefItemDelegate is the delegate for the ref item.
type RefItemDelegate struct {
style *styles.Styles
}
-func (d RefItemDelegate) Height() int { return 1 }
-func (d RefItemDelegate) Spacing() int { return 0 }
+// Height implements list.ItemDelegate.
+func (d RefItemDelegate) Height() int { return 1 }
+
+// Spacing implements list.ItemDelegate.
+func (d RefItemDelegate) Spacing() int { return 0 }
+
+// Update implements list.ItemDelegate.
func (d RefItemDelegate) Update(msg tea.Msg, m *list.Model) tea.Cmd { return nil }
+
+// Render implements list.ItemDelegate.
func (d RefItemDelegate) Render(w io.Writer, m list.Model, index int, listItem list.Item) {
s := d.style
i, ok := listItem.(RefItem)
@@ -1,6 +1,7 @@
package selection
import (
+ "errors"
"fmt"
"strings"
@@ -229,6 +230,8 @@ func (s *Selection) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch {
case key.Matches(msg, s.common.KeyMap.Section):
s.activeBox = (s.activeBox + 1) % 2
+ case msg.String() == "a":
+ cmds = append(cmds, common.ErrorCmd(errors.New("not implemented")))
}
}
switch s.activeBox {
@@ -227,7 +227,7 @@ func DefaultStyles() *Styles {
SetString(" • ")
s.Error = lipgloss.NewStyle().
- Padding(1)
+ MarginTop(2)
s.ErrorTitle = lipgloss.NewStyle().
Foreground(lipgloss.Color("230")).
@@ -16,6 +16,13 @@ import (
"github.com/charmbracelet/soft-serve/ui/session"
)
+type page int
+
+const (
+ selectionPage page = iota
+ repoPage
+)
+
type sessionState int
const (
@@ -29,7 +36,7 @@ type UI struct {
s session.Session
common common.Common
pages []common.Page
- activePage int
+ activePage page
state sessionState
header *header.Header
footer *footer.Footer
@@ -43,7 +50,7 @@ func New(s session.Session, c common.Common, initialRepo string) *UI {
s: s,
common: c,
pages: make([]common.Page, 2), // selection & repo
- activePage: 0,
+ activePage: selectionPage,
state: startState,
header: h,
}
@@ -108,13 +115,13 @@ func (ui *UI) SetSize(width, height int) {
// Init implements tea.Model.
func (ui *UI) Init() tea.Cmd {
cfg := ui.s.Config()
- ui.pages[0] = selection.New(ui.s, ui.common)
- ui.pages[1] = repo.New(ui.common, &source{cfg.Source})
+ ui.pages[selectionPage] = selection.New(ui.s, ui.common)
+ ui.pages[repoPage] = repo.New(ui.common, &source{cfg.Source})
ui.SetSize(ui.common.Width, ui.common.Height)
ui.state = loadedState
return tea.Batch(
- ui.pages[0].Init(),
- ui.pages[1].Init(),
+ ui.pages[selectionPage].Init(),
+ ui.pages[repoPage].Init(),
)
}
@@ -143,8 +150,8 @@ func (ui *UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
ui.footer.SetShowAll(!ui.footer.ShowAll())
case key.Matches(msg, ui.common.KeyMap.Quit):
return ui, tea.Quit
- case ui.activePage == 1 && key.Matches(msg, ui.common.KeyMap.Back):
- ui.activePage = 0
+ case ui.activePage == repoPage && key.Matches(msg, ui.common.KeyMap.Back):
+ ui.activePage = selectionPage
}
}
case common.ErrorMsg:
@@ -154,8 +161,8 @@ func (ui *UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case selector.SelectMsg:
switch msg.IdentifiableItem.(type) {
case selection.Item:
- if ui.activePage == 0 {
- ui.activePage = 1
+ if ui.activePage == selectionPage {
+ ui.activePage = repoPage
cmds = append(cmds, ui.setRepoCmd(msg.ID()))
}
}
@@ -185,6 +192,7 @@ func (ui *UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
// View implements tea.Model.
func (ui *UI) View() string {
var view string
+ wm, hm := ui.getMargins()
footer := ui.footer.View()
style := ui.common.Styles.App.Copy()
switch ui.state {
@@ -193,15 +201,13 @@ func (ui *UI) View() string {
case errorState:
err := ui.common.Styles.ErrorTitle.Render("Bummer")
err += ui.common.Styles.ErrorBody.Render(ui.error.Error())
- view = ui.common.Styles.ErrorBody.Copy().
+ view = ui.common.Styles.Error.Copy().
Width(ui.common.Width -
- style.GetWidth() -
- style.GetHorizontalFrameSize() -
+ wm -
ui.common.Styles.ErrorBody.GetHorizontalFrameSize()).
Height(ui.common.Height -
- style.GetHeight() -
- style.GetVerticalFrameSize() -
- ui.common.Styles.Header.GetVerticalFrameSize() - 2).
+ hm -
+ ui.common.Styles.Error.GetVerticalFrameSize()).
Render(err)
case loadedState:
view = ui.pages[ui.activePage].View()
@@ -209,8 +215,7 @@ func (ui *UI) View() string {
view = "Unknown state :/ this is a bug!"
}
return style.Render(
- lipgloss.JoinVertical(
- lipgloss.Bottom,
+ lipgloss.JoinVertical(lipgloss.Bottom,
ui.header.View(),
view,
footer,