File tree Expand file tree Collapse file tree 3 files changed +28
-4
lines changed Expand file tree Collapse file tree 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) {
8888}
8989
9090func (s * shellActionsImpl ) ReadLineWithDefault (defaultValue string ) string {
91- s .reader .defaultValue = defaultValue
91+ s .reader .defaultInput = defaultValue
9292 line , _ := s .readLine ()
93- s .reader .defaultValue = ""
93+ s .reader .defaultInput = ""
9494 return line
9595}
9696
Original file line number Diff line number Diff line change @@ -57,6 +57,30 @@ func main() {
5757 },
5858 })
5959
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+ })
6084 // read multiple lines with "multi" command
6185 shell .AddCmd (& ishell.Cmd {
6286 Name : "multi" ,
Original file line number Diff line number Diff line change 2424 multiPrompt string
2525 showPrompt bool
2626 completer readline.AutoCompleter
27+ defaultInput string
2728 sync.Mutex
28- defaultValue string
2929 }
3030)
3131
@@ -88,7 +88,7 @@ func (s *shellReader) readLine(consumer chan lineString) {
8888 // use printed statement as prompt
8989 s .scanner .SetPrompt (prompt )
9090
91- line , err := s .scanner .ReadlineWithDefault (s .defaultValue )
91+ line , err := s .scanner .ReadlineWithDefault (s .defaultInput )
9292
9393 // reset prompt
9494 s .scanner .SetPrompt (shellPrompt )
You can’t perform that action at this time.
0 commit comments