Split into category packages; module github.com/ZacharyZhang-NY/MujicaUI
This commit is contained in:
1822 files changed
+24568
-21314
No files matched your search
@@ -0,0 +1,60 @@
|
||||
package git
|
||||
|
||||
import (
|
||||
"github.com/egoist/mygo/ui"
|
||||
|
||||
"github.com/ZacharyZhang-NY/MujicaUI/core"
|
||||
"github.com/ZacharyZhang-NY/MujicaUI/data"
|
||||
"github.com/ZacharyZhang-NY/MujicaUI/icons"
|
||||
"github.com/ZacharyZhang-NY/MujicaUI/theme"
|
||||
)
|
||||
|
||||
// Stash is one stash entry.
|
||||
type Stash struct {
|
||||
// Ref names the entry, as stash@{0}.
|
||||
Ref string
|
||||
Message string
|
||||
Branch string
|
||||
}
|
||||
|
||||
// StashListOptions configure a StashList.
|
||||
type StashListOptions struct {
|
||||
// Status and Error show the load state.
|
||||
Status data.DataStatus
|
||||
Error string
|
||||
}
|
||||
|
||||
// StashList shows stashes with apply, pop and drop actions.
|
||||
func StashList(c *ui.Context, s *data.ListState[string], stashes []Stash, opts StashListOptions) GitListResult {
|
||||
var r GitListResult
|
||||
k := core.Tokens(c)
|
||||
actions := []GitAction{
|
||||
{ID: "apply", Label: core.Msg(c, "stash_list.apply"), Icon: "check"},
|
||||
{ID: "pop", Label: core.Msg(c, "stash_list.pop"), Icon: "upload"},
|
||||
{ID: "drop", Label: core.Msg(c, "stash_list.drop"), Icon: "trash-2"},
|
||||
}
|
||||
v := data.List(c, s, len(stashes), data.ListOptions[string]{
|
||||
Key: func(i int) string { return stashListKey(stashes[i]) },
|
||||
Label: func(i int) string { return stashes[i].Message },
|
||||
Status: opts.Status, Error: opts.Error, Empty: core.Msg(c, "stash_list.empty"),
|
||||
}, func(i int) {
|
||||
st := stashes[i]
|
||||
small := core.FontSize(c, theme.CaptionSize)
|
||||
ui.Icon(c, icons.Must("archive")).Size(14, 14).Shrink(0).TextColor(k.TextMuted)
|
||||
ui.Text(c, st.Ref).Font(theme.MonoFont).FontSize(small).TextColor(k.AccentText).Shrink(0)
|
||||
ui.Text(c, st.Message).SingleLine().Grow(1).MinWidth(0)
|
||||
if st.Branch != "" {
|
||||
ui.Text(c, st.Branch).FontSize(small).TextColor(k.TextMuted).SingleLine().MaxWidth(140).Shrink(0)
|
||||
}
|
||||
gitRowActions(c, actions, st.Ref, &r)
|
||||
})
|
||||
r.Element, r.changed, r.submitted = v.Element, v.Changed(), v.Submitted()
|
||||
return r
|
||||
}
|
||||
|
||||
func stashListKey(s Stash) string {
|
||||
if s.Ref == "" {
|
||||
panic("mujica: Stash needs a Ref")
|
||||
}
|
||||
return s.Ref
|
||||
}
|
||||
Reference in new issue
Block a user