Skip to content

Commit 8b8aa74

Browse files
pierreNabiosoft
authored andcommitted
Add NewWithReadline to have a shell with custom readline Instance (#105)
* add new helper NewWithReadLine to create ishell instance with a custom readline instance * use readline config for Shell.Writer in NewWithReadline * refactor NewWithConfig to use NewWithReadline
1 parent d2bd206 commit 8b8aa74

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

ishell.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ func NewWithConfig(conf *readline.Config) *Shell {
7474
log.Println("Shell or operating system not supported.")
7575
log.Fatal(err)
7676
}
77+
78+
return NewWithReadline(rl)
79+
}
80+
81+
// NewWithReadline creates a new shell with a custom readline instance.
82+
func NewWithReadline(rl *readline.Instance) *Shell {
7783
shell := &Shell{
7884
rootCmd: &Cmd{},
7985
reader: &shellReader{
@@ -84,7 +90,7 @@ func NewWithConfig(conf *readline.Config) *Shell {
8490
buf: &bytes.Buffer{},
8591
completer: readline.NewPrefixCompleter(),
8692
},
87-
writer: conf.Stdout,
93+
writer: rl.Config.Stdout,
8894
autoHelp: true,
8995
}
9096
shell.Actions = &shellActionsImpl{Shell: shell}

0 commit comments

Comments
 (0)