MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / showCustomResultModal

Method showCustomResultModal

internal/plugins/command-runner/ui.go:453–524  ·  view source on GitHub ↗

showCustomResultModal is like ShowResultModal but adds a "Save to Whitelist" button so the user can promote a successful custom command into the session whitelist.

(result ExecutionResult, targetType TargetType, onClose func(), onAddToWhitelist func(string))

Source from the content-addressed store, hash-verified

451// showCustomResultModal is like ShowResultModal but adds a "Save to Whitelist" button
452// so the user can promote a successful custom command into the session whitelist.
453func (u *UIManager) showCustomResultModal(result ExecutionResult, targetType TargetType, onClose func(), onAddToWhitelist func(string)) {
454 pages := u.app.Pages()
455 pages.RemovePage("executingCommand")
456
457 closeResult := func() {
458 pages.RemovePage("commandResult")
459 if onClose != nil {
460 onClose()
461 }
462 }
463
464 var text strings.Builder
465 fmt.Fprintf(&text, "Command: %s\n", result.Command)
466 fmt.Fprintf(&text, "Duration: %v\n\n", result.Duration)
467
468 if result.Error != nil {
469 fmt.Fprintf(&text, "Error: %v\n\n", result.Error)
470 if result.Output != "" {
471 text.WriteString("Output:\n")
472 text.WriteString(result.Output)
473 }
474 } else {
475 text.WriteString("Output:\n")
476 text.WriteString(result.Output)
477 if result.Truncated {
478 text.WriteString("\n\n[Output truncated]")
479 }
480 }
481
482 textView := tview.NewTextView().
483 SetText(text.String()).
484 SetDynamicColors(true).
485 SetScrollable(true)
486 textView.SetBorder(true)
487 textView.SetTitle(" Custom Command Result ")
488
489 // Build hint line; include whitelist shortcut only when the command succeeded.
490 hintText := " [primary]ESC/Backspace[-] Close | [primary]↑/↓[-] Scroll"
491 if result.Error == nil {
492 hintText += fmt.Sprintf(" | [primary]w[-] Save to %s Whitelist (session)", targetType)
493 }
494 hintText += " "
495
496 buttons := tview.NewTextView().
497 SetText(hintText).
498 SetTextAlign(tview.AlignCenter).
499 SetDynamicColors(true)
500
501 flex := tview.NewFlex().
502 SetDirection(tview.FlexRow).
503 AddItem(textView, 0, 1, true).
504 AddItem(buttons, 1, 0, false)
505
506 textView.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
507 if isBackKey(event) {
508 closeResult()
509 return nil
510 }

Callers 1

Calls 6

AddToWhitelistMethod · 0.80
isBackKeyFunction · 0.70
PagesMethod · 0.65
SetTitleMethod · 0.65
SetTextMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected