on main help sign in
fix(ui): dialog: show shortcut/info in list items
179e17fAyman Bagabas
internal/ui/dialog/commands_item.go+1−1
@@ -51,5 +51,5 @@ func (c *CommandItem) SetMatch(m fuzzy.Match) {
51
51
52// Render implements ListItem.
52// Render implements ListItem.
53func (c *CommandItem) Render(width int) string {
53func (c *CommandItem) Render(width int) string {
54− return renderItem(c.t, c.Cmd.Title, 0, c.focused, width, c.cache, &c.m)
54+ return renderItem(c.t, c.Cmd.Title, c.Cmd.Shortcut, c.focused, width, c.cache, &c.m)
55}
55}
internal/ui/dialog/models_item.go+1−1
@@ -81,7 +81,7 @@ func (m *ModelItem) ID() string {
81
81
82// Render implements ListItem.
82// Render implements ListItem.
83func (m *ModelItem) Render(width int) string {
83func (m *ModelItem) Render(width int) string {
84− return renderItem(m.t, m.model.Name, 0, m.focused, width, m.cache, &m.m)
84+ return renderItem(m.t, m.model.Name, "", m.focused, width, m.cache, &m.m)
85}
85}
86
86
87// SetFocused implements ListItem.
87// SetFocused implements ListItem.
internal/ui/dialog/sessions_item.go+12−11
@@ -54,10 +54,11 @@ func (s *SessionItem) SetMatch(m fuzzy.Match) {
54
54
55// Render returns the string representation of the session item.
55// Render returns the string representation of the session item.
56func (s *SessionItem) Render(width int) string {
56func (s *SessionItem) Render(width int) string {
57+ info := humanize.Time(time.Unix(s.UpdatedAt, 0))
57− return renderItem(s.t, s.Title, s.UpdatedAt, s.focused, width, s.cache, &s.m)
58+ return renderItem(s.t, s.Title, info, s.focused, width, s.cache, &s.m)
58}
59}
59
60
60−func renderItem(t *styles.Styles, title string, updatedAt int64, focused bool, width int, cache map[int]string, m *fuzzy.Match) string {
61+func renderItem(t *styles.Styles, title string, info string, focused bool, width int, cache map[int]string, m *fuzzy.Match) string {
61 if cache == nil {
62 if cache == nil {
62 cache = make(map[int]string)
63 cache = make(map[int]string)
63 }
64 }
@@ -72,23 +73,23 @@ func renderItem(t *styles.Styles, title string, updatedAt int64, focused bool, w
72 style = t.Dialog.SelectedItem
73 style = t.Dialog.SelectedItem
73 }
74 }
74
75
75− var age string
76+ var infoText string
76− var ageLen int
77+ var infoLen int
77 lineWidth := width
78 lineWidth := width
78− if updatedAt > 0 {
79+ if len(info) > 0 {
79− age = fmt.Sprintf(" %s ", humanize.Time(time.Unix(updatedAt, 0)))
80+ infoText = fmt.Sprintf(" %s ", info)
80 if focused {
81 if focused {
81− age = t.Base.Render(age)
82+ infoText = t.Base.Render(infoText)
82 } else {
83 } else {
83− age = t.Subtle.Render(age)
84+ infoText = t.Subtle.Render(infoText)
84 }
85 }
85
86
86− ageLen = lipgloss.Width(age)
87+ infoLen = lipgloss.Width(infoText)
87 }
88 }
88
89
89 title = ansi.Truncate(title, max(0, lineWidth), "")
90 title = ansi.Truncate(title, max(0, lineWidth), "")
90 titleLen := lipgloss.Width(title)
91 titleLen := lipgloss.Width(title)
91− gap := strings.Repeat(" ", max(0, lineWidth-titleLen-ageLen))
92+ gap := strings.Repeat(" ", max(0, lineWidth-titleLen-infoLen))
92 content := title
93 content := title
93 if matches := len(m.MatchedIndexes); matches > 0 {
94 if matches := len(m.MatchedIndexes); matches > 0 {
94 var lastPos int
95 var lastPos int
@@ -118,7 +119,7 @@ func renderItem(t *styles.Styles, title string, updatedAt int64, focused bool, w
118 content = strings.Join(parts, "")
119 content = strings.Join(parts, "")
119 }
120 }
120
121
121− content = style.Render(content + gap + age)
122+ content = style.Render(content + gap + infoText)
122 cache[width] = content
123 cache[width] = content
123 return content
124 return content
124}
125}