| 1 |
package ui |
| 2 |
|
| 3 |
import ( |
| 4 |
"fmt" |
| 5 |
"runtime" |
| 6 |
|
| 7 |
"github.com/chzyer/readline" |
| 8 |
"github.com/manifoldco/promptui" |
| 9 |
) |
| 10 |
|
| 11 |
var ( |
| 12 |
|
| 13 |
|
| 14 |
IconInitial = promptui.Styler(promptui.FGBlue)("?") |
| 15 |
|
| 16 |
|
| 17 |
IconGood = promptui.Styler(promptui.FGGreen)("✔") |
| 18 |
|
| 19 |
|
| 20 |
IconWarn = promptui.Styler(promptui.FGYellow)("⚠") |
| 21 |
|
| 22 |
|
| 23 |
IconBad = promptui.Styler(promptui.FGRed)("✗") |
| 24 |
|
| 25 |
|
| 26 |
IconSelect = promptui.Styler(promptui.FGBold)("▸") |
| 27 |
) |
| 28 |
|
| 29 |
func init() { |
| 30 |
|
| 31 |
if runtime.GOOS == "windows" { |
| 32 |
promptui.KeyEnter = readline.CharEnter |
| 33 |
promptui.KeyBackspace = readline.CharBackspace |
| 34 |
promptui.KeyPrev = readline.CharPrev |
| 35 |
promptui.KeyPrevDisplay = "↑" |
| 36 |
promptui.KeyNext = readline.CharNext |
| 37 |
promptui.KeyNextDisplay = "↓" |
| 38 |
promptui.KeyBackward = readline.CharBackward |
| 39 |
promptui.KeyBackwardDisplay = "←" |
| 40 |
promptui.KeyForward = readline.CharForward |
| 41 |
promptui.KeyForwardDisplay = "→" |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
func PrintSelectedTemplate() string { |
| 47 |
return fmt.Sprintf(`{{ "%s" | green }} {{ .Name | bold }}{{ ":" | bold }} {{ .Value }}`, IconGood) + "\n" |
| 48 |
} |
| 49 |
|
| 50 |
|
| 51 |
func PromptTemplates() *promptui.PromptTemplates { |
| 52 |
bold := promptui.Styler(promptui.FGBold) |
| 53 |
return &promptui.PromptTemplates{ |
| 54 |
Prompt: fmt.Sprintf("%s {{ . | bold }}%s ", IconInitial, bold(":")), |
| 55 |
Success: fmt.Sprintf("%s {{ . | bold }}%s ", bold(IconGood), bold(":")), |
| 56 |
|
| 57 |
Valid: fmt.Sprintf("%s {{ . | bold }}%s ", bold(IconGood), bold(":")), |
| 58 |
Invalid: fmt.Sprintf("%s {{ . | bold }}%s ", bold(IconBad), bold(":")), |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
func SimplePromptTemplates() *promptui.PromptTemplates { |
| 64 |
return &promptui.PromptTemplates{ |
| 65 |
Prompt: "{{ . }}: ", |
| 66 |
Success: "{{ . }}: ", |
| 67 |
Valid: "{{ . }}: ", |
| 68 |
Invalid: "{{ . }}: ", |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
func SelectTemplates(name string) *promptui.SelectTemplates { |
| 75 |
return &promptui.SelectTemplates{ |
| 76 |
Label: fmt.Sprintf("%s {{ . }}: ", IconInitial), |
| 77 |
Active: fmt.Sprintf("%s {{ . | underline }}", IconSelect), |
| 78 |
Inactive: " {{ . }}", |
| 79 |
Selected: fmt.Sprintf(`{{ "%s" | green }} {{ "%s:" | bold }} {{ .Name }}`, IconGood, name), |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
func NamedSelectTemplates(name string) *promptui.SelectTemplates { |
| 87 |
return &promptui.SelectTemplates{ |
| 88 |
Label: fmt.Sprintf("%s {{.Name}}: ", IconInitial), |
| 89 |
Active: fmt.Sprintf("%s {{ .Name | underline }}", IconSelect), |
| 90 |
Inactive: " {{.Name}}", |
| 91 |
Selected: fmt.Sprintf(`{{ "%s" | green }} {{ "%s:" | bold }} {{ .Name }}`, IconGood, name), |
| 92 |
} |
| 93 |
} |