This repository was archived by the owner on Apr 19, 2024. It is now read-only.
File tree 3 files changed +49
-2
lines changed
3 files changed +49
-2
lines changed Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import (
4
+ "fmt"
5
+
6
+ "github.com/AlecAivazis/survey/v2"
7
+ )
8
+
9
+ // the questions to ask
10
+ var simpleQs = []* survey.Question {
11
+ {
12
+ Name : "name" ,
13
+ Prompt : & survey.Input {
14
+ Message : "What is your name?" ,
15
+ },
16
+ Validate : survey .Required ,
17
+ },
18
+ }
19
+
20
+ func main () {
21
+ ansmap := make (map [string ]interface {})
22
+
23
+ // ask the question
24
+ err := survey .Ask (simpleQs , & ansmap , survey .WithShowCursor (true ))
25
+
26
+ if err != nil {
27
+ fmt .Println (err .Error ())
28
+ return
29
+ }
30
+ // print the answers
31
+ fmt .Printf ("Your name is %s.\n " , ansmap ["name" ])
32
+ }
Original file line number Diff line number Diff line change @@ -150,8 +150,10 @@ func (i *Input) Prompt(config *PromptConfig) (interface{}, error) {
150
150
defer rr .RestoreTermMode ()
151
151
152
152
cursor := i .NewCursor ()
153
- cursor .Hide () // hide the cursor
154
- defer cursor .Show () // show the cursor when we're done
153
+ if ! config .ShowCursor {
154
+ cursor .Hide () // hide the cursor
155
+ defer cursor .Show () // show the cursor when we're done
156
+ }
155
157
156
158
// start waiting for input
157
159
for {
Original file line number Diff line number Diff line change @@ -55,6 +55,7 @@ func defaultAskOptions() *AskOptions {
55
55
return strings .Contains (strings .ToLower (value ), filter )
56
56
},
57
57
KeepFilter : false ,
58
+ ShowCursor : false ,
58
59
},
59
60
}
60
61
}
@@ -114,6 +115,7 @@ type PromptConfig struct {
114
115
SuggestInput string
115
116
Filter func (filter string , option string , index int ) bool
116
117
KeepFilter bool
118
+ ShowCursor bool
117
119
}
118
120
119
121
// Prompt is the primary interface for the objects that can take user input
@@ -219,6 +221,17 @@ func WithIcons(setIcons func(*IconSet)) AskOpt {
219
221
}
220
222
}
221
223
224
+ // WithShowCursor sets the show cursor behavior when prompting the user
225
+ func WithShowCursor (ShowCursor bool ) AskOpt {
226
+ return func (options * AskOptions ) error {
227
+ // set the page size
228
+ options .PromptConfig .ShowCursor = ShowCursor
229
+
230
+ // nothing went wrong
231
+ return nil
232
+ }
233
+ }
234
+
222
235
/*
223
236
AskOne performs the prompt for a single prompt and asks for validation if required.
224
237
Response types should be something that can be casted from the response type designated
You can’t perform that action at this time.
0 commit comments