on main help sign in
fix(ui): adjust dialog sizing to account for dynamic title and help heights
675d851Ayman Bagabas
internal/ui/dialog/commands.go+7−2
@@ -111,11 +111,16 @@ func NewCommands(com *common.Common, sessionID string) (*Commands, error) {
111
111
112// SetSize sets the size of the dialog.
112// SetSize sets the size of the dialog.
113func (c *Commands) SetSize(width, height int) {
113func (c *Commands) SetSize(width, height int) {
114+ t := c.com.Styles
114 c.width = width
115 c.width = width
115 c.height = height
116 c.height = height
116 innerWidth := width - c.com.Styles.Dialog.View.GetHorizontalFrameSize()
117 innerWidth := width - c.com.Styles.Dialog.View.GetHorizontalFrameSize()
118+ heightOffset := t.Dialog.Title.GetVerticalFrameSize() + 1 + // (1) title content
119+ t.Dialog.InputPrompt.GetVerticalFrameSize() + 1 + // (1) input content
120+ t.Dialog.HelpView.GetVerticalFrameSize() +
121+ t.Dialog.View.GetVerticalFrameSize()
117− c.input.SetWidth(innerWidth - c.com.Styles.Dialog.InputPrompt.GetHorizontalFrameSize() - 1)
122+ c.input.SetWidth(innerWidth - t.Dialog.InputPrompt.GetHorizontalFrameSize() - 1) // (1) cursor padding
118− c.list.SetSize(innerWidth, height-6) // (1) title + (3) input + (1) padding + (1) help
123+ c.list.SetSize(innerWidth, height-heightOffset)
119 c.help.SetWidth(width)
124 c.help.SetWidth(width)
120}
125}
121
126
internal/ui/dialog/sessions.go+8−3
@@ -67,11 +67,16 @@ func NewSessions(com *common.Common, sessions ...session.Session) *Session {
67
67
68// SetSize sets the size of the dialog.
68// SetSize sets the size of the dialog.
69func (s *Session) SetSize(width, height int) {
69func (s *Session) SetSize(width, height int) {
70+ t := s.com.Styles
70 s.width = width
71 s.width = width
71 s.height = height
72 s.height = height
72− innerWidth := width - s.com.Styles.Dialog.View.GetHorizontalFrameSize()
73+ innerWidth := width - t.Dialog.View.GetHorizontalFrameSize()
74+ heightOffset := t.Dialog.Title.GetVerticalFrameSize() + 1 + // (1) title content
75+ t.Dialog.InputPrompt.GetVerticalFrameSize() + 1 + // (1) input content
76+ t.Dialog.HelpView.GetVerticalFrameSize() +
77+ t.Dialog.View.GetVerticalFrameSize()
73− s.input.SetWidth(innerWidth - s.com.Styles.Dialog.InputPrompt.GetHorizontalFrameSize() - 1)
78+ s.input.SetWidth(innerWidth - t.Dialog.InputPrompt.GetHorizontalFrameSize() - 1) // (1) cursor padding
74− s.list.SetSize(innerWidth, height-6) // (1) title + (3) input + (1) padding + (1) help
79+ s.list.SetSize(innerWidth, height-heightOffset)
75 s.help.SetWidth(width)
80 s.help.SetWidth(width)
76}
81}
77
82
internal/ui/dialog/sessions_item.go+7−3
@@ -84,11 +84,15 @@ func renderItem(t *styles.Styles, title string, updatedAt int64, focused bool, w
84
84
85 age = " " + age
85 age = " " + age
86 }
86 }
87+
88+ var ageLen int
89+ if updatedAt > 0 {
87− ageLen := lipgloss.Width(age)
90+ ageLen = lipgloss.Width(age)
88− titleLen := lipgloss.Width(title)
91+ }
92+
89 title = ansi.Truncate(title, max(0, width-ageLen), "…")
93 title = ansi.Truncate(title, max(0, width-ageLen), "…")
94+ titleLen := lipgloss.Width(title)
90 right := lipgloss.NewStyle().AlignHorizontal(lipgloss.Right).Width(width - titleLen).Render(age)
95 right := lipgloss.NewStyle().AlignHorizontal(lipgloss.Right).Width(width - titleLen).Render(age)
91−
92 content := title
96 content := title
93 if matches := len(m.MatchedIndexes); matches > 0 {
97 if matches := len(m.MatchedIndexes); matches > 0 {
94 var lastPos int
98 var lastPos int