|
|
@@ -69,13 +69,13 @@ type permissionDialogCmp struct {
|
|
|
func formatDiff(diffText string) string {
|
|
|
lines := strings.Split(diffText, "\n")
|
|
|
var formattedLines []string
|
|
|
-
|
|
|
+
|
|
|
// Define styles for different line types
|
|
|
addStyle := lipgloss.NewStyle().Foreground(styles.Green)
|
|
|
removeStyle := lipgloss.NewStyle().Foreground(styles.Red)
|
|
|
headerStyle := lipgloss.NewStyle().Bold(true).Foreground(styles.Blue)
|
|
|
contextStyle := lipgloss.NewStyle().Foreground(styles.SubText0)
|
|
|
-
|
|
|
+
|
|
|
// Process each line
|
|
|
for _, line := range lines {
|
|
|
if strings.HasPrefix(line, "+") {
|
|
|
@@ -90,7 +90,7 @@ func formatDiff(diffText string) string {
|
|
|
formattedLines = append(formattedLines, line)
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// Join all formatted lines
|
|
|
return strings.Join(formattedLines, "\n")
|
|
|
}
|
|
|
@@ -112,13 +112,13 @@ func (p *permissionDialogCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|
|
p.selectOption.Blur()
|
|
|
// Add a visual indicator for focus change
|
|
|
cmds = append(cmds, tea.Batch(
|
|
|
- util.CmdHandler(util.InfoMsg("Viewing content - use arrow keys to scroll")),
|
|
|
+ util.ReportInfo("Viewing content - use arrow keys to scroll"),
|
|
|
))
|
|
|
} else {
|
|
|
p.selectOption.Focus()
|
|
|
// Add a visual indicator for focus change
|
|
|
cmds = append(cmds, tea.Batch(
|
|
|
- util.CmdHandler(util.InfoMsg("Select an action")),
|
|
|
+ util.CmdHandler(util.ReportInfo("Select an action")),
|
|
|
))
|
|
|
}
|
|
|
return p, tea.Batch(cmds...)
|
|
|
@@ -162,44 +162,44 @@ func (p *permissionDialogCmp) render() string {
|
|
|
lipgloss.JoinHorizontal(lipgloss.Left, keyStyle.Render("Path:"), " ", valueStyle.Render(p.permission.Path)),
|
|
|
" ",
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// Create the header content first so it can be used in all cases
|
|
|
headerContent := lipgloss.NewStyle().Padding(0, 1).Render(lipgloss.JoinVertical(lipgloss.Left, headerParts...))
|
|
|
-
|
|
|
+
|
|
|
r, _ := glamour.NewTermRenderer(
|
|
|
glamour.WithStyles(styles.CatppuccinMarkdownStyle()),
|
|
|
glamour.WithWordWrap(p.width-10),
|
|
|
glamour.WithEmoji(),
|
|
|
)
|
|
|
-
|
|
|
+
|
|
|
// Handle different tool types
|
|
|
switch p.permission.ToolName {
|
|
|
case tools.BashToolName:
|
|
|
pr := p.permission.Params.(tools.BashPermissionsParams)
|
|
|
headerParts = append(headerParts, keyStyle.Render("Command:"))
|
|
|
content := fmt.Sprintf("```bash\n%s\n```", pr.Command)
|
|
|
-
|
|
|
+
|
|
|
renderedContent, _ := r.Render(content)
|
|
|
p.contentViewPort.Width = p.width - 2 - 2
|
|
|
-
|
|
|
+
|
|
|
// Calculate content height dynamically based on content
|
|
|
contentLines := len(strings.Split(renderedContent, "\n"))
|
|
|
// Set a reasonable min/max for the viewport height
|
|
|
minContentHeight := 3
|
|
|
maxContentHeight := p.height - lipgloss.Height(headerContent) - lipgloss.Height(form) - 2 - 2 - 1
|
|
|
-
|
|
|
+
|
|
|
// Add some padding to the content lines
|
|
|
contentHeight := contentLines + 2
|
|
|
contentHeight = max(contentHeight, minContentHeight)
|
|
|
contentHeight = min(contentHeight, maxContentHeight)
|
|
|
p.contentViewPort.Height = contentHeight
|
|
|
-
|
|
|
+
|
|
|
p.contentViewPort.SetContent(renderedContent)
|
|
|
-
|
|
|
+
|
|
|
// Style the viewport
|
|
|
var contentBorder lipgloss.Border
|
|
|
var borderColor lipgloss.TerminalColor
|
|
|
-
|
|
|
+
|
|
|
if p.isViewportFocus {
|
|
|
contentBorder = lipgloss.DoubleBorder()
|
|
|
borderColor = styles.Blue
|
|
|
@@ -207,47 +207,47 @@ func (p *permissionDialogCmp) render() string {
|
|
|
contentBorder = lipgloss.RoundedBorder()
|
|
|
borderColor = styles.Flamingo
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
contentStyle := lipgloss.NewStyle().
|
|
|
MarginTop(1).
|
|
|
Padding(0, 1).
|
|
|
Border(contentBorder).
|
|
|
BorderForeground(borderColor)
|
|
|
-
|
|
|
+
|
|
|
if p.isViewportFocus {
|
|
|
contentStyle = contentStyle.BorderBackground(styles.Surface0)
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
contentFinal := contentStyle.Render(p.contentViewPort.View())
|
|
|
-
|
|
|
+
|
|
|
return lipgloss.JoinVertical(
|
|
|
lipgloss.Top,
|
|
|
headerContent,
|
|
|
contentFinal,
|
|
|
form,
|
|
|
)
|
|
|
-
|
|
|
+
|
|
|
case tools.EditToolName:
|
|
|
pr := p.permission.Params.(tools.EditPermissionsParams)
|
|
|
headerParts = append(headerParts, keyStyle.Render("Update"))
|
|
|
// Recreate header content with the updated headerParts
|
|
|
headerContent = lipgloss.NewStyle().Padding(0, 1).Render(lipgloss.JoinVertical(lipgloss.Left, headerParts...))
|
|
|
-
|
|
|
+
|
|
|
// Format the diff with colors
|
|
|
formattedDiff := formatDiff(pr.Diff)
|
|
|
-
|
|
|
+
|
|
|
// Set up viewport for the diff content
|
|
|
p.contentViewPort.Width = p.width - 2 - 2
|
|
|
-
|
|
|
+
|
|
|
// Calculate content height dynamically based on window size
|
|
|
maxContentHeight := p.height - lipgloss.Height(headerContent) - lipgloss.Height(form) - 2 - 2 - 1
|
|
|
p.contentViewPort.Height = maxContentHeight
|
|
|
p.contentViewPort.SetContent(formattedDiff)
|
|
|
-
|
|
|
+
|
|
|
// Style the viewport
|
|
|
var contentBorder lipgloss.Border
|
|
|
var borderColor lipgloss.TerminalColor
|
|
|
-
|
|
|
+
|
|
|
if p.isViewportFocus {
|
|
|
contentBorder = lipgloss.DoubleBorder()
|
|
|
borderColor = styles.Blue
|
|
|
@@ -255,47 +255,47 @@ func (p *permissionDialogCmp) render() string {
|
|
|
contentBorder = lipgloss.RoundedBorder()
|
|
|
borderColor = styles.Flamingo
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
contentStyle := lipgloss.NewStyle().
|
|
|
MarginTop(1).
|
|
|
Padding(0, 1).
|
|
|
Border(contentBorder).
|
|
|
BorderForeground(borderColor)
|
|
|
-
|
|
|
+
|
|
|
if p.isViewportFocus {
|
|
|
contentStyle = contentStyle.BorderBackground(styles.Surface0)
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
contentFinal := contentStyle.Render(p.contentViewPort.View())
|
|
|
-
|
|
|
+
|
|
|
return lipgloss.JoinVertical(
|
|
|
lipgloss.Top,
|
|
|
headerContent,
|
|
|
contentFinal,
|
|
|
form,
|
|
|
)
|
|
|
-
|
|
|
+
|
|
|
case tools.WriteToolName:
|
|
|
pr := p.permission.Params.(tools.WritePermissionsParams)
|
|
|
headerParts = append(headerParts, keyStyle.Render("Content"))
|
|
|
// Recreate header content with the updated headerParts
|
|
|
headerContent = lipgloss.NewStyle().Padding(0, 1).Render(lipgloss.JoinVertical(lipgloss.Left, headerParts...))
|
|
|
-
|
|
|
+
|
|
|
// Format the diff with colors
|
|
|
formattedDiff := formatDiff(pr.Content)
|
|
|
-
|
|
|
+
|
|
|
// Set up viewport for the content
|
|
|
p.contentViewPort.Width = p.width - 2 - 2
|
|
|
-
|
|
|
+
|
|
|
// Calculate content height dynamically based on window size
|
|
|
maxContentHeight := p.height - lipgloss.Height(headerContent) - lipgloss.Height(form) - 2 - 2 - 1
|
|
|
p.contentViewPort.Height = maxContentHeight
|
|
|
p.contentViewPort.SetContent(formattedDiff)
|
|
|
-
|
|
|
+
|
|
|
// Style the viewport
|
|
|
var contentBorder lipgloss.Border
|
|
|
var borderColor lipgloss.TerminalColor
|
|
|
-
|
|
|
+
|
|
|
if p.isViewportFocus {
|
|
|
contentBorder = lipgloss.DoubleBorder()
|
|
|
borderColor = styles.Blue
|
|
|
@@ -303,75 +303,75 @@ func (p *permissionDialogCmp) render() string {
|
|
|
contentBorder = lipgloss.RoundedBorder()
|
|
|
borderColor = styles.Flamingo
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
contentStyle := lipgloss.NewStyle().
|
|
|
MarginTop(1).
|
|
|
Padding(0, 1).
|
|
|
Border(contentBorder).
|
|
|
BorderForeground(borderColor)
|
|
|
-
|
|
|
+
|
|
|
if p.isViewportFocus {
|
|
|
contentStyle = contentStyle.BorderBackground(styles.Surface0)
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
contentFinal := contentStyle.Render(p.contentViewPort.View())
|
|
|
-
|
|
|
+
|
|
|
return lipgloss.JoinVertical(
|
|
|
lipgloss.Top,
|
|
|
headerContent,
|
|
|
contentFinal,
|
|
|
form,
|
|
|
)
|
|
|
-
|
|
|
+
|
|
|
case tools.FetchToolName:
|
|
|
pr := p.permission.Params.(tools.FetchPermissionsParams)
|
|
|
headerParts = append(headerParts, keyStyle.Render("URL: "+pr.URL))
|
|
|
content := p.permission.Description
|
|
|
-
|
|
|
+
|
|
|
renderedContent, _ := r.Render(content)
|
|
|
p.contentViewPort.Width = p.width - 2 - 2
|
|
|
p.contentViewPort.Height = p.height - lipgloss.Height(headerContent) - lipgloss.Height(form) - 2 - 2 - 1
|
|
|
p.contentViewPort.SetContent(renderedContent)
|
|
|
-
|
|
|
+
|
|
|
// Style the viewport
|
|
|
contentStyle := lipgloss.NewStyle().
|
|
|
MarginTop(1).
|
|
|
Padding(0, 1).
|
|
|
Border(lipgloss.RoundedBorder()).
|
|
|
BorderForeground(styles.Flamingo)
|
|
|
-
|
|
|
+
|
|
|
contentFinal := contentStyle.Render(p.contentViewPort.View())
|
|
|
if renderedContent == "" {
|
|
|
contentFinal = ""
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
return lipgloss.JoinVertical(
|
|
|
lipgloss.Top,
|
|
|
headerContent,
|
|
|
contentFinal,
|
|
|
form,
|
|
|
)
|
|
|
-
|
|
|
+
|
|
|
default:
|
|
|
content := p.permission.Description
|
|
|
-
|
|
|
+
|
|
|
renderedContent, _ := r.Render(content)
|
|
|
p.contentViewPort.Width = p.width - 2 - 2
|
|
|
p.contentViewPort.Height = p.height - lipgloss.Height(headerContent) - lipgloss.Height(form) - 2 - 2 - 1
|
|
|
p.contentViewPort.SetContent(renderedContent)
|
|
|
-
|
|
|
+
|
|
|
// Style the viewport
|
|
|
contentStyle := lipgloss.NewStyle().
|
|
|
MarginTop(1).
|
|
|
Padding(0, 1).
|
|
|
Border(lipgloss.RoundedBorder()).
|
|
|
BorderForeground(styles.Flamingo)
|
|
|
-
|
|
|
+
|
|
|
contentFinal := contentStyle.Render(p.contentViewPort.View())
|
|
|
if renderedContent == "" {
|
|
|
contentFinal = ""
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
return lipgloss.JoinVertical(
|
|
|
lipgloss.Top,
|
|
|
headerContent,
|