From 8b8aa74a85127192b469453a72fd7971b47481fb Mon Sep 17 00:00:00 2001 From: pierreN Date: Sat, 29 Dec 2018 04:06:44 +0900 Subject: [PATCH] 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 --- ishell.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ishell.go b/ishell.go index 9d03ab3..d3f4b42 100644 --- a/ishell.go +++ b/ishell.go @@ -74,6 +74,12 @@ func NewWithConfig(conf *readline.Config) *Shell { log.Println("Shell or operating system not supported.") log.Fatal(err) } + + return NewWithReadline(rl) +} + +// NewWithReadline creates a new shell with a custom readline instance. +func NewWithReadline(rl *readline.Instance) *Shell { shell := &Shell{ rootCmd: &Cmd{}, reader: &shellReader{ @@ -84,7 +90,7 @@ func NewWithConfig(conf *readline.Config) *Shell { buf: &bytes.Buffer{}, completer: readline.NewPrefixCompleter(), }, - writer: conf.Stdout, + writer: rl.Config.Stdout, autoHelp: true, } shell.Actions = &shellActionsImpl{Shell: shell}