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

Method showCommandMenu

internal/plugins/command-runner/ui.go:57–136  ·  view source on GitHub ↗
(targetType TargetType, target string, commands []string, onClose func())

Source from the content-addressed store, hash-verified

55}
56
57func (u *UIManager) showCommandMenu(targetType TargetType, target string, commands []string, onClose func()) {
58 if len(commands) == 0 {
59 u.ShowErrorModal("No commands available", "No commands configured for this target type", onClose)
60 return
61 }
62
63 pages := u.app.Pages()
64
65 // Close function that removes the page and calls onClose callback
66 closeMenu := func() {
67 pages.RemovePage("commandMenu")
68 if onClose != nil {
69 onClose()
70 }
71 }
72
73 // Create list of commands
74 list := tview.NewList()
75 list.SetBorder(true)
76 list.SetTitle(fmt.Sprintf(" Run Command on %s (%s) ", target, targetType))
77
78 returnToMenu := func() {
79 u.app.SetFocus(list)
80 }
81
82 // addToList inserts a newly whitelisted command at index 1 (right after "Custom
83 // Command...") so it appears at the top of the whitelist section immediately.
84 addToList := func(cmd string) {
85 desc := GetCommandDescription(cmd)
86 cmdCopy := cmd
87 list.InsertItem(1, cmdCopy, desc, 0, func() {
88 u.handleCommandSelection(targetType, target, cmdCopy, returnToMenu)
89 })
90 }
91
92 // Custom command entry first so it is always visible at the top.
93 list.AddItem("Custom Command...", "Type and run any non-interactive command", '!', func() {
94 u.showCustomCommandForm(targetType, target, returnToMenu, addToList)
95 })
96
97 for _, cmd := range commands {
98 cmdCopy := cmd // Capture for closure
99 description := GetCommandDescription(cmdCopy)
100 list.AddItem(cmdCopy, description, 0, func() {
101 u.handleCommandSelection(targetType, target, cmdCopy, returnToMenu)
102 })
103 }
104
105 // Add cancel option
106 list.AddItem("Cancel", "Press to close", 'q', closeMenu)
107
108 // Set input handler for Esc key and vi-style navigation
109 list.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
110 if isBackKey(event) {
111 closeMenu()
112 return nil
113 }
114 // Vi-style navigation

Callers 2

ShowCommandMenuMethod · 0.95
ShowVMCommandMenuMethod · 0.95

Calls 10

ShowErrorModalMethod · 0.95
showCustomCommandFormMethod · 0.95
GetCommandDescriptionFunction · 0.85
isBackKeyFunction · 0.70
PagesMethod · 0.65
SetTitleMethod · 0.65
SetFocusMethod · 0.65
GetCurrentItemMethod · 0.65
SetCurrentItemMethod · 0.65

Tested by

no test coverage detected