on main help sign in
fix(ui): properly align session item age text
b449545Ayman Bagabas
internal/ui/dialog/sessions_item.go+7−18
@@ -1,6 +1,7 @@
1package dialog
1package dialog
2
2
3import (
3import (
4+ "fmt"
4 "strings"
5 "strings"
5 "time"
6 "time"
6
7
@@ -71,35 +72,23 @@ func renderItem(t *styles.Styles, title string, updatedAt int64, focused bool, w
71 style = t.Dialog.SelectedItem
72 style = t.Dialog.SelectedItem
72 }
73 }
73
74
74− width -= style.GetHorizontalFrameSize()
75−
76 var age string
75 var age string
76+ var ageLen int
77+ lineWidth := width
77 if updatedAt > 0 {
78 if updatedAt > 0 {
78− age = humanize.Time(time.Unix(updatedAt, 0))
79+ age = fmt.Sprintf(" %s ", humanize.Time(time.Unix(updatedAt, 0)))
79 if focused {
80 if focused {
80 age = t.Base.Render(age)
81 age = t.Base.Render(age)
81 } else {
82 } else {
82 age = t.Subtle.Render(age)
83 age = t.Subtle.Render(age)
83 }
84 }
84
85
85− age = " " + age
86− }
87−
88− var ageLen int
89− var right string
90− lineWidth := width
91− if updatedAt > 0 {
92 ageLen = lipgloss.Width(age)
86 ageLen = lipgloss.Width(age)
93− lineWidth -= ageLen
94 }
87 }
95
88
96− title = ansi.Truncate(title, max(0, lineWidth), "…")
89+ title = ansi.Truncate(title, max(0, lineWidth), "")
97 titleLen := lipgloss.Width(title)
90 titleLen := lipgloss.Width(title)
98−
91+ gap := strings.Repeat(" ", max(0, lineWidth-titleLen-ageLen))
99− if updatedAt > 0 {
100− right = lipgloss.NewStyle().AlignHorizontal(lipgloss.Right).Width(width - titleLen).Render(age)
101− }
102−
103 content := title
92 content := title
104 if matches := len(m.MatchedIndexes); matches > 0 {
93 if matches := len(m.MatchedIndexes); matches > 0 {
105 var lastPos int
94 var lastPos int
@@ -129,7 +118,7 @@ func renderItem(t *styles.Styles, title string, updatedAt int64, focused bool, w
129 content = strings.Join(parts, "")
118 content = strings.Join(parts, "")
130 }
119 }
131
120
132− content = style.Render(content + right)
121+ content = style.Render(content + gap + age)
133 cache[width] = content
122 cache[width] = content
134 return content
123 return content
135}
124}