1package repo23import (4 "fmt"5 "io"67 "charm.land/bubbles/v2/key"8 "charm.land/bubbles/v2/list"9 tea "charm.land/bubbletea/v2"10 gitm "github.com/aymanbagabas/git-module"11 "github.com/charmbracelet/soft-serve/pkg/ui/common"12)1314// StashItem represents a stash item.15type StashItem struct{ *gitm.Stash }1617// ID returns the ID of the stash item.18func (i StashItem) ID() string {19 return fmt.Sprintf("stash@{%d}", i.Index)20}2122// Title returns the title of the stash item.23func (i StashItem) Title() string {24 return i.Message25}2627// Description returns the description of the stash item.28func (i StashItem) Description() string {29 return ""30}3132// FilterValue implements list.Item.33func (i StashItem) FilterValue() string { return i.Title() }3435// StashItems is a list of stash items.36type StashItems []StashItem3738// Len implements sort.Interface.39func (cl StashItems) Len() int { return len(cl) }4041// Swap implements sort.Interface.42func (cl StashItems) Swap(i, j int) { cl[i], cl[j] = cl[j], cl[i] }4344// Less implements sort.Interface.45func (cl StashItems) Less(i, j int) bool {46 return cl[i].Index < cl[j].Index47}4849// StashItemDelegate is a delegate for stash items.50type StashItemDelegate struct {51 common *common.Common52}5354// Height returns the height of the stash item list. Implements list.ItemDelegate.55func (d StashItemDelegate) Height() int { return 1 }5657// Spacing implements list.ItemDelegate.58func (d StashItemDelegate) Spacing() int { return 0 }5960// Update implements list.ItemDelegate.61func (d StashItemDelegate) Update(msg tea.Msg, m *list.Model) tea.Cmd {62 item, ok := m.SelectedItem().(StashItem)63 if !ok {64 return nil65 }6667 switch msg := msg.(type) {68 case tea.KeyPressMsg:69 switch {70 case key.Matches(msg, d.common.KeyMap.Copy):71 return copyCmd(item.Title(), fmt.Sprintf("Stash message %q copied to clipboard", item.Title()))72 }73 }7475 return nil76}7778// Render implements list.ItemDelegate.79func (d StashItemDelegate) Render(w io.Writer, m list.Model, index int, listItem list.Item) {80 item, ok := listItem.(StashItem)81 if !ok {82 return83 }8485 s := d.common.Styles.Stash8687 st := s.Normal.Message88 selector := " "89 if index == m.Index() {90 selector = "> "91 st = s.Active.Message92 }9394 selector = s.Selector.Render(selector)95 title := st.Render(item.Title())96 fmt.Fprint(w, d.common.Zone.Mark( //nolint:errcheck97 item.ID(),98 common.TruncateString(fmt.Sprintf("%s%s",99 selector,100 title,101 ), m.Width()-102 s.Selector.GetWidth()-103 st.GetHorizontalFrameSize(),104 ),105 ))106}