1
0
Fork 0
mirror of https://github.com/postmannen/ctrl.git synced 2025-04-09 10:24:17 +00:00

updating dropdowns when flex is in focus

This commit is contained in:
postmannen 2022-01-12 06:16:14 +01:00
parent f6f96ef76a
commit 28cb3a6509

16
tui.go
View file

@ -502,13 +502,22 @@ func console(app *tview.Application) tview.Primitive {
msgDropdown := tview.NewDropDown()
msgDropdown.SetLabelColor(tcell.ColorIndianRed)
msgDropdown.SetLabel("message").SetOptions(msgsValues, nil)
msgDropdown.SetFocusFunc(func() {
p.selectForm.AddFormItem(msgDropdown)
// Add button for manually updating dropdown menus.
p.selectForm.AddButton("update dropdown menus", func() {
nodesList, err := getNodeNames("nodeslist.cfg")
if err != nil {
fmt.Fprintf(p.outputForm, "error: failed to open nodeslist.cfg file\n")
}
nodesDropdown.SetLabel("nodes").SetOptions(nodesList, nil)
msgsValues := getMessageNames(p.outputForm)
msgDropdown.SetLabel("message").SetOptions(msgsValues, nil)
})
p.selectForm.AddFormItem(msgDropdown)
p.selectForm.AddButton("update dropdown menus", func() {
// Update the dropdown menus when the flex view gets focus.
p.flex.SetFocusFunc(func() {
nodesList, err := getNodeNames("nodeslist.cfg")
if err != nil {
fmt.Fprintf(p.outputForm, "error: failed to open nodeslist.cfg file\n")
@ -638,7 +647,6 @@ func getNodeNames(fileName string) ([]string, error) {
}
filePath := filepath.Join(dirPath, fileName)
log.Printf(" * filepath : %v\n", filePath)
fh, err := os.Open(filePath)
if err != nil {