on main help sign in
Make permission dialog height dynamic based on content
ef15976Kujtim Hoxha
internal/tui/components/dialog/permission.go+28−4
@@ -2,6 +2,7 @@ package dialog
2
2
3import (
3import (
4 "fmt"
4 "fmt"
5+ "strings"
5
6
6 "github.com/charmbracelet/bubbles/key"
7 "github.com/charmbracelet/bubbles/key"
7 "github.com/charmbracelet/bubbles/viewport"
8 "github.com/charmbracelet/bubbles/viewport"
@@ -160,7 +161,29 @@ func (p *permissionDialogCmp) render() string {
160 renderedContent, _ := r.Render(content)
161 renderedContent, _ := r.Render(content)
161 headerContent := lipgloss.NewStyle().Padding(0, 1).Render(lipgloss.JoinVertical(lipgloss.Left, headerParts...))
162 headerContent := lipgloss.NewStyle().Padding(0, 1).Render(lipgloss.JoinVertical(lipgloss.Left, headerParts...))
162 p.contentViewPort.Width = p.width - 2 - 2
163 p.contentViewPort.Width = p.width - 2 - 2
164+
165+ // Calculate content height dynamically based on content
166+ contentLines := len(strings.Split(renderedContent, "\n"))
167+ // Set a reasonable min/max for the viewport height
168+ minContentHeight := 3
163− p.contentViewPort.Height = p.height - lipgloss.Height(headerContent) - lipgloss.Height(form) - 2 - 2 - 1
169+ maxContentHeight := p.height - lipgloss.Height(headerContent) - lipgloss.Height(form) - 2 - 2 - 1
170+
171+ // For bash commands, adjust height based on content length
172+ if p.permission.ToolName == tools.BashToolName {
173+ // Add some padding to the content lines
174+ contentHeight := contentLines + 2
175+ if contentHeight < minContentHeight {
176+ contentHeight = minContentHeight
177+ }
178+ if contentHeight > maxContentHeight {
179+ contentHeight = maxContentHeight
180+ }
181+ p.contentViewPort.Height = contentHeight
182+ } else {
183+ // For other content types, use the full available height
184+ p.contentViewPort.Height = maxContentHeight
185+ }
186+
164 p.contentViewPort.SetContent(renderedContent)
187 p.contentViewPort.SetContent(renderedContent)
165
188
166 // Make focus change more apparent with different border styles and colors
189 // Make focus change more apparent with different border styles and colors
@@ -270,13 +293,14 @@ func NewPermissionDialogCmd(permission permission.PermissionRequest) tea.Cmd {
270 minWidth := 100
293 minWidth := 100
271 minHeight := 30
294 minHeight := 30
272
295
273− // Make the dialog size more appropriate for bash commands
296+ // Make the dialog size more appropriate for different tools
274 switch permission.ToolName {
297 switch permission.ToolName {
275 case tools.BashToolName:
298 case tools.BashToolName:
299+ // For bash commands, use a more compact dialog
276 widthRatio = 0.7
300 widthRatio = 0.7
277− heightRatio = 0.5
301+ heightRatio = 0.4 // Reduced from 0.5
278 minWidth = 100
302 minWidth = 100
279− minHeight = 30
303+ minHeight = 20 // Reduced from 30
280 }
304 }
281 // Return the dialog command
305 // Return the dialog command
282 return util.CmdHandler(core.DialogMsg{
306 return util.CmdHandler(core.DialogMsg{