Skip to content
This repository was archived by the owner on Sep 18, 2025. It is now read-only.

Commit ef15976

Browse files
kujtimiihoxhatermai
andcommitted
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>
1 parent c185dc8 commit ef15976

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

internal/tui/components/dialog/permission.go

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package dialog
22

33
import (
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{

0 commit comments

Comments
 (0)