From e7a9f991f9333f494ecc31583bdef1cf3b7b257f Mon Sep 17 00:00:00 2001 From: John Brooks Date: Wed, 26 Oct 2016 14:57:48 -0600 Subject: [PATCH] cli: Fix conversation prompt update logic --- cli/ui.go | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/cli/ui.go b/cli/ui.go index 5a6a38e..62ccc05 100644 --- a/cli/ui.go +++ b/cli/ui.go @@ -184,24 +184,24 @@ type conversationInputConfig struct { BaseConfig *readline.Config PromptFmt string + usingConfig bool stopPromptTimer chan struct{} } func (cc *conversationInputConfig) OnChange(line []rune, pos int, key rune) ([]rune, int, bool) { - if len(line) == 0 && key != 0 { - cc.Input.SetConfig(cc.Config) - cc.stopPromptTimer = make(chan struct{}) - go cc.updatePromptTimer() + if len(line) == 0 && key != 0 && !cc.usingConfig { + cc.Install() } if len(line) > 0 && line[0] == '/' { - if cc.Input.Config == cc.Config { + if cc.usingConfig { cc.stopPromptTimer <- struct{}{} + cc.usingConfig = false close(cc.stopPromptTimer) cc.BaseConfig.Listener = cc.Config.Listener cc.Input.SetConfig(cc.BaseConfig) } - } else if cc.Input.Config == cc.BaseConfig { + } else if !cc.usingConfig { line = append([]rune{'/'}, line...) } @@ -209,19 +209,23 @@ func (cc *conversationInputConfig) OnChange(line []rune, pos int, key rune) ([]r } func (cc *conversationInputConfig) Install() { - cc.Input.SetConfig(cc.Config) - cc.stopPromptTimer = make(chan struct{}) - go cc.updatePromptTimer() + if !cc.usingConfig { + cc.usingConfig = true + cc.Input.SetConfig(cc.Config) + cc.stopPromptTimer = make(chan struct{}) + go cc.updatePromptTimer() + } } func (cc *conversationInputConfig) Remove() { - if cc.Input.Config == cc.Config { + cc.BaseConfig.Listener = nil + + if cc.usingConfig { cc.stopPromptTimer <- struct{}{} + cc.usingConfig = false close(cc.stopPromptTimer) cc.Input.SetConfig(cc.BaseConfig) } - - cc.BaseConfig.Listener = nil } func (cc *conversationInputConfig) updatePromptTimer() {