utils: refactor PrintMenu with tasker array

pull/7/head
oscar 2022-09-21 17:43:56 +12:00
parent a115970e7e
commit 9c56ec0d85
1 changed files with 18 additions and 1 deletions

View File

@ -1,6 +1,9 @@
package utils package utils
import "fmt" import (
"fmt"
"ocl/portainer-devtool/tasks"
)
const ( const (
colorReset string = "\033[0m" colorReset string = "\033[0m"
@ -41,6 +44,20 @@ func InputPrint(message string) {
fmt.Println(colorYellow, message, colorReset) fmt.Println(colorYellow, message, colorReset)
} }
func PrintMenu(question string, tasks []tasks.Tasker) {
if question != "" {
InputPrint(fmt.Sprintf("[%s]", question))
}
menuContent := ""
for i, task := range tasks {
menuContent += fmt.Sprintf("%d. %s\n", i+1, task.String())
}
fmt.Println(colorCyan, menuContent, colorReset)
}
func MenuPrint(question, menu string) { func MenuPrint(question, menu string) {
if question != "" { if question != "" {
InputPrint(fmt.Sprintf("[%s]", question)) InputPrint(fmt.Sprintf("[%s]", question))