on main help sign in
Make permission dialog height dynamic based on content

- Adjust dialog height for bash commands based on content length - Reduce default dialog size for bash commands to be more compact - Add strings import for string splitting ๐Ÿค– Generated with termai Co-Authored-By: termai <noreply@termai.io>

commitef15976f5dcdbbf7465b2294580c6750d42f497a authorKujtim Hoxha <kujtimii.h@gmail.com> dateFri 4 Apr 2025, 14:40 (2 years ago) parentc185dc8
1 file changed+28โˆ’4
internal/tui/components/dialog/permission.go+28โˆ’4
internal/tui/components/dialog/permission.go+28โˆ’4
@@ -2,6 +2,7 @@ package dialog
22
33import (
44 "fmt"
5+ "strings"
56
67 "github.com/charmbracelet/bubbles/key"
78 "github.com/charmbracelet/bubbles/viewport"
@@ -160,7 +161,29 @@ func (p *permissionDialogCmp) render() string {
160161 renderedContent, _ := r.Render(content)
161162 headerContent := lipgloss.NewStyle().Padding(0, 1).Render(lipgloss.JoinVertical(lipgloss.Left, headerParts...))
162163 p.contentViewPort.Width = p.width - 2 - 2
163โˆ’ p.contentViewPort.Height = p.height - lipgloss.Height(headerContent) - lipgloss.Height(form) - 2 - 2 - 1
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
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+
164187 p.contentViewPort.SetContent(renderedContent)
165188
166189 // Make focus change more apparent with different border styles and colors
@@ -270,13 +293,14 @@ func NewPermissionDialogCmd(permission permission.PermissionRequest) tea.Cmd {
270293 minWidth := 100
271294 minHeight := 30
272295
273โˆ’ // Make the dialog size more appropriate for bash commands
296+ // Make the dialog size more appropriate for different tools
274297 switch permission.ToolName {
275298 case tools.BashToolName:
299+ // For bash commands, use a more compact dialog
276300 widthRatio = 0.7
277โˆ’ heightRatio = 0.5
301+ heightRatio = 0.4 // Reduced from 0.5
278302 minWidth = 100
279โˆ’ minHeight = 30
303+ minHeight = 20 // Reduced from 30
280304 }
281305 // Return the dialog command
282306 return util.CmdHandler(core.DialogMsg{