Merge pull request #2191 from charmbracelet/charm-1152-sessions-dialog-is-too-big

Ayman Bagabas created

fix(ui): adjust sessions dialog size

Change summary

internal/ui/dialog/commands.go      | 18 +++++++-----------
internal/ui/dialog/dialog.go        |  4 ++--
internal/ui/dialog/models.go        | 10 ++++------
internal/ui/dialog/sessions.go      | 16 +++++++---------
internal/ui/dialog/sessions_item.go |  4 ++--
5 files changed, 22 insertions(+), 30 deletions(-)

Detailed changes

internal/ui/dialog/commands.go 🔗

@@ -27,9 +27,7 @@ type CommandType uint
 func (c CommandType) String() string { return []string{"System", "User", "MCP"}[c] }
 
 const (
-	sidebarCompactModeBreakpoint   = 120
-	defaultCommandsDialogMaxHeight = 20
-	defaultCommandsDialogMaxWidth  = 70
+	sidebarCompactModeBreakpoint = 120
 )
 
 const (
@@ -155,19 +153,17 @@ func (c *Commands) HandleMsg(msg tea.Msg) Action {
 			c.list.Focus()
 			if c.list.IsSelectedFirst() {
 				c.list.SelectLast()
-				c.list.ScrollToBottom()
-				break
+			} else {
+				c.list.SelectPrev()
 			}
-			c.list.SelectPrev()
 			c.list.ScrollToSelected()
 		case key.Matches(msg, c.keyMap.Next):
 			c.list.Focus()
 			if c.list.IsSelectedLast() {
 				c.list.SelectFirst()
-				c.list.ScrollToTop()
-				break
+			} else {
+				c.list.SelectNext()
 			}
-			c.list.SelectNext()
 			c.list.ScrollToSelected()
 		case key.Matches(msg, c.keyMap.Select):
 			if selectedItem := c.list.SelectedItem(); selectedItem != nil {
@@ -240,8 +236,8 @@ func commandsRadioView(sty *styles.Styles, selected CommandType, hasUserCmds boo
 // Draw implements [Dialog].
 func (c *Commands) Draw(scr uv.Screen, area uv.Rectangle) *tea.Cursor {
 	t := c.com.Styles
-	width := max(0, min(defaultCommandsDialogMaxWidth, area.Dx()-t.Dialog.View.GetHorizontalBorderSize()))
-	height := max(0, min(defaultCommandsDialogMaxHeight, area.Dy()-t.Dialog.View.GetVerticalBorderSize()))
+	width := max(0, min(defaultDialogMaxWidth, area.Dx()-t.Dialog.View.GetHorizontalBorderSize()))
+	height := max(0, min(defaultDialogHeight, area.Dy()-t.Dialog.View.GetVerticalBorderSize()))
 	if area.Dx() != c.windowWidth && c.selected == SystemCommands {
 		c.windowWidth = area.Dx()
 		// since some items in the list depend on width (e.g. toggle sidebar command),

internal/ui/dialog/dialog.go 🔗

@@ -11,9 +11,9 @@ import (
 // Dialog sizing constants.
 const (
 	// defaultDialogMaxWidth is the maximum width for standard dialogs.
-	defaultDialogMaxWidth = 120
+	defaultDialogMaxWidth = 70
 	// defaultDialogHeight is the default height for standard dialogs.
-	defaultDialogHeight = 30
+	defaultDialogHeight = 20
 	// titleContentHeight is the height of the title content line.
 	titleContentHeight = 1
 	// inputContentHeight is the height of the input content line.

internal/ui/dialog/models.go 🔗

@@ -174,19 +174,17 @@ func (m *Models) HandleMsg(msg tea.Msg) Action {
 			m.list.Focus()
 			if m.list.IsSelectedFirst() {
 				m.list.SelectLast()
-				m.list.ScrollToBottom()
-				break
+			} else {
+				m.list.SelectPrev()
 			}
-			m.list.SelectPrev()
 			m.list.ScrollToSelected()
 		case key.Matches(msg, m.keyMap.Next):
 			m.list.Focus()
 			if m.list.IsSelectedLast() {
 				m.list.SelectFirst()
-				m.list.ScrollToTop()
-				break
+			} else {
+				m.list.SelectNext()
 			}
-			m.list.SelectNext()
 			m.list.ScrollToSelected()
 		case key.Matches(msg, m.keyMap.Select, m.keyMap.Edit):
 			selectedItem := m.list.SelectedItem()

internal/ui/dialog/sessions.go 🔗

@@ -190,19 +190,17 @@ func (s *Session) HandleMsg(msg tea.Msg) Action {
 				s.list.Focus()
 				if s.list.IsSelectedFirst() {
 					s.list.SelectLast()
-					s.list.ScrollToBottom()
-					break
+				} else {
+					s.list.SelectPrev()
 				}
-				s.list.SelectPrev()
 				s.list.ScrollToSelected()
 			case key.Matches(msg, s.keyMap.Next):
 				s.list.Focus()
 				if s.list.IsSelectedLast() {
 					s.list.SelectFirst()
-					s.list.ScrollToTop()
-					break
+				} else {
+					s.list.SelectNext()
 				}
-				s.list.SelectNext()
 				s.list.ScrollToSelected()
 			case key.Matches(msg, s.keyMap.Select):
 				if item := s.list.SelectedItem(); item != nil {
@@ -231,9 +229,9 @@ func (s *Session) Cursor() *tea.Cursor {
 // Draw implements [Dialog].
 func (s *Session) Draw(scr uv.Screen, area uv.Rectangle) *tea.Cursor {
 	t := s.com.Styles
-	width := max(0, min(defaultDialogMaxWidth, area.Dx()))
-	height := max(0, min(defaultDialogHeight, area.Dy()))
-	innerWidth := width - t.Dialog.View.GetHorizontalFrameSize() - 2
+	width := max(0, min(defaultDialogMaxWidth, area.Dx()-t.Dialog.View.GetHorizontalBorderSize()))
+	height := max(0, min(defaultDialogHeight, area.Dy()-t.Dialog.View.GetVerticalBorderSize()))
+	innerWidth := width - t.Dialog.View.GetHorizontalFrameSize()
 	heightOffset := t.Dialog.Title.GetVerticalFrameSize() + titleContentHeight +
 		t.Dialog.InputPrompt.GetVerticalFrameSize() + inputContentHeight +
 		t.Dialog.HelpView.GetVerticalFrameSize() +

internal/ui/dialog/sessions_item.go 🔗

@@ -137,7 +137,7 @@ func renderItem(t ListItemStyles, title string, info string, focused bool, width
 		infoWidth = lipgloss.Width(infoText)
 	}
 
-	title = ansi.Truncate(title, max(0, lineWidth-infoWidth), "")
+	title = ansi.Truncate(title, max(0, lineWidth-infoWidth), "…")
 	titleWidth := lipgloss.Width(title)
 	gap := strings.Repeat(" ", max(0, lineWidth-titleWidth-infoWidth))
 	content := title
@@ -154,7 +154,7 @@ func renderItem(t ListItemStyles, title string, info string, focused bool, width
 			// because we can control the underline start and stop more
 			// precisely via [ansi.AttrUnderline] and [ansi.AttrNoUnderline]
 			// which only affect the underline attribute without interfering
-			// with other style
+			// with other style attributes.
 			parts = append(parts,
 				ansi.NewStyle().Underline(true).String(),
 				ansi.Cut(title, start, stop+1),