File tree 3 files changed +28
-4
lines changed
3 files changed +28
-4
lines changed Original file line number Diff line number Diff line change @@ -88,9 +88,9 @@ func (s *shellActionsImpl) ReadLineErr() (string, error) {
88
88
}
89
89
90
90
func (s * shellActionsImpl ) ReadLineWithDefault (defaultValue string ) string {
91
- s .reader .defaultValue = defaultValue
91
+ s .reader .defaultInput = defaultValue
92
92
line , _ := s .readLine ()
93
- s .reader .defaultValue = ""
93
+ s .reader .defaultInput = ""
94
94
return line
95
95
}
96
96
Original file line number Diff line number Diff line change @@ -57,6 +57,30 @@ func main() {
57
57
},
58
58
})
59
59
60
+ // handle "default".
61
+ shell .AddCmd (& ishell.Cmd {
62
+ Name : "default" ,
63
+ Help : "readline with default input" ,
64
+ Func : func (c * ishell.Context ) {
65
+ c .ShowPrompt (false )
66
+ defer c .ShowPrompt (true )
67
+
68
+ defaultInput := "default input, you can edit this"
69
+ if len (c .Args ) > 0 {
70
+ defaultInput = strings .Join (c .Args , " " )
71
+ }
72
+
73
+ c .Print ("input: " )
74
+ read := c .ReadLineWithDefault (defaultInput )
75
+
76
+ if read == defaultInput {
77
+ c .Println ("you left the default input intact" )
78
+ } else {
79
+ c .Printf ("you modified input to '%s'" , read )
80
+ c .Println ()
81
+ }
82
+ },
83
+ })
60
84
// read multiple lines with "multi" command
61
85
shell .AddCmd (& ishell.Cmd {
62
86
Name : "multi" ,
Original file line number Diff line number Diff line change 24
24
multiPrompt string
25
25
showPrompt bool
26
26
completer readline.AutoCompleter
27
+ defaultInput string
27
28
sync.Mutex
28
- defaultValue string
29
29
}
30
30
)
31
31
@@ -88,7 +88,7 @@ func (s *shellReader) readLine(consumer chan lineString) {
88
88
// use printed statement as prompt
89
89
s .scanner .SetPrompt (prompt )
90
90
91
- line , err := s .scanner .ReadlineWithDefault (s .defaultValue )
91
+ line , err := s .scanner .ReadlineWithDefault (s .defaultInput )
92
92
93
93
// reset prompt
94
94
s .scanner .SetPrompt (shellPrompt )
You can’t perform that action at this time.
0 commit comments