File tree Expand file tree Collapse file tree 1 file changed +62
-0
lines changed Expand file tree Collapse file tree 1 file changed +62
-0
lines changed Original file line number Diff line number Diff line change
1
+ package prompt
2
+
3
+ import (
4
+ "errors"
5
+ "strings"
6
+
7
+ "github.com/mritd/promptx"
8
+ )
9
+
10
+ // SelectItem a default item struct
11
+ type SelectItem struct {
12
+ Title string
13
+ Description string
14
+ Value string
15
+ }
16
+
17
+ // SelectConfiguration a complete configuration select options
18
+ type SelectConfiguration struct {
19
+ ActiveTpl string
20
+ InactiveTpl string
21
+ SelectPrompt string
22
+ SelectedTpl string
23
+ DetailsTpl string
24
+ }
25
+
26
+ // Select Returns a selected item
27
+ func Select (items []SelectItem , config SelectConfiguration ) SelectItem {
28
+ configuration := & promptx.SelectConfig {
29
+ ActiveTpl : config .ActiveTpl ,
30
+ InactiveTpl : config .InactiveTpl ,
31
+ SelectPrompt : config .SelectPrompt ,
32
+ SelectedTpl : config .SelectedTpl ,
33
+ DisPlaySize : 9 ,
34
+ DetailsTpl : config .DetailsTpl ,
35
+ }
36
+
37
+ selector := & promptx.Select {
38
+ Items : items ,
39
+ Config : configuration ,
40
+ }
41
+
42
+ return items [selector .Run ()]
43
+ }
44
+
45
+ // Input return a simple user input
46
+ func Input (title string , errorMessage string , defaultValue string ) string {
47
+ input := promptx .NewDefaultPrompt (func (line []rune ) error {
48
+ if strings .TrimSpace (string (line )) == "" && defaultValue == "" {
49
+ return errors .New (errorMessage )
50
+ }
51
+
52
+ return nil
53
+ }, title )
54
+
55
+ value := input .Run ()
56
+
57
+ if value == "" && defaultValue != "" {
58
+ return defaultValue
59
+ }
60
+
61
+ return value
62
+ }
You can’t perform that action at this time.
0 commit comments