1
0
Fork 0
mirror of https://github.com/postmannen/ctrl.git synced 2024-12-15 17:51:15 +00:00

added update button for dropdowns

This commit is contained in:
postmannen 2022-01-12 05:44:41 +01:00
parent 340fe4d344
commit f6f96ef76a

51
tui.go
View file

@ -492,22 +492,32 @@ func console(app *tview.Application) tview.Primitive {
fmt.Fprintf(p.outputForm, "error: failed to open nodeslist.cfg file\n")
}
item := tview.NewDropDown()
item.SetLabelColor(tcell.ColorIndianRed)
item.SetLabel("nodes").SetOptions(nodesList, nil)
p.selectForm.AddFormItem(item)
nodesDropdown := tview.NewDropDown()
nodesDropdown.SetLabelColor(tcell.ColorIndianRed)
nodesDropdown.SetLabel("nodes").SetOptions(nodesList, nil)
p.selectForm.AddFormItem(nodesDropdown)
// Create messages dropdown field.
fInfo, err := ioutil.ReadDir("messages")
msgsValues := getMessageNames(p.outputForm)
msgDropdown := tview.NewDropDown()
msgDropdown.SetLabelColor(tcell.ColorIndianRed)
msgDropdown.SetLabel("message").SetOptions(msgsValues, nil)
msgDropdown.SetFocusFunc(func() {
msgsValues := getMessageNames(p.outputForm)
msgDropdown.SetLabel("message").SetOptions(msgsValues, nil)
})
p.selectForm.AddFormItem(msgDropdown)
p.selectForm.AddButton("update dropdown menus", func() {
nodesList, err := getNodeNames("nodeslist.cfg")
if err != nil {
fmt.Fprintf(p.outputForm, "error: failed to read files from messages dir\n")
fmt.Fprintf(p.outputForm, "error: failed to open nodeslist.cfg file\n")
}
nodesDropdown.SetLabel("nodes").SetOptions(nodesList, nil)
values := []string{}
for _, v := range fInfo {
values = append(values, v.Name())
}
p.selectForm.AddDropDown("method", values, 0, nil).SetItemPadding(1)
msgsValues := getMessageNames(p.outputForm)
msgDropdown.SetLabel("message").SetOptions(msgsValues, nil)
})
p.selectForm.AddButton("send message", func() {
// here ........
@ -520,6 +530,23 @@ func console(app *tview.Application) tview.Primitive {
// Helper functions
// ---------------------------------------------------------------------
func getMessageNames(outputForm *tview.TextView) []string {
// Create messages dropdown field.
fInfo, err := ioutil.ReadDir("messages")
if err != nil {
fmt.Fprintf(outputForm, "error: failed to read files from messages dir\n")
}
msgsValues := []string{}
msgsValues = append(msgsValues, "")
for _, v := range fInfo {
msgsValues = append(msgsValues, v.Name())
}
return msgsValues
}
// stringToSlice will Split the comma separated string
// into a and remove the start and end ampersand.
func stringToSlice(s string) (*[]string, error) {