From 1567eff74093d2b83acc0f63f7a40e4dcd2c19f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Prist=C3=A1=C5=A1=20Michal?= Date: Thu, 7 Apr 2016 10:53:58 +0200 Subject: [PATCH 1/2] auto-complete gets displayed even with space characters prefixing the line --- complete_helper.go | 2 +- example/readline-demo/readline-demo.go | 2 +- runes.go | 11 +++++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/complete_helper.go b/complete_helper.go index 430fbf3..f609d44 100644 --- a/complete_helper.go +++ b/complete_helper.go @@ -73,7 +73,7 @@ func (p *PrefixCompleter) Do(line []rune, pos int) (newLine [][]rune, offset int } func Do(p PrefixCompleterInterface, line []rune, pos int) (newLine [][]rune, offset int) { - line = line[:pos] + line = runes.TrimSpaceLeft(line[:pos]) goNext := false var lineCompleter PrefixCompleterInterface for _, child := range p.GetChildren() { diff --git a/example/readline-demo/readline-demo.go b/example/readline-demo/readline-demo.go index eeb3605..68e929d 100644 --- a/example/readline-demo/readline-demo.go +++ b/example/readline-demo/readline-demo.go @@ -8,7 +8,7 @@ import ( "strings" "time" - "github.com/chzyer/readline" + "github.com/michalpristas/readline" ) func usage(w io.Writer) { diff --git a/runes.go b/runes.go index b0a878b..b85af7a 100644 --- a/runes.go +++ b/runes.go @@ -154,3 +154,14 @@ aggregate: } return } + +func (Runes) TrimSpaceLeft(in []rune) []rune { + firstIndex := len(in) + for i, r := range in { + if unicode.IsSpace(r) == false { + firstIndex = i + break + } + } + return in[firstIndex:] +} From c2366033fa4dd1dcee2a2fb459d2ae1c8dce50b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Prist=C3=A1=C5=A1=20Michal?= Date: Thu, 7 Apr 2016 10:54:57 +0200 Subject: [PATCH 2/2] demo test back to chzyer; --- example/readline-demo/readline-demo.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/readline-demo/readline-demo.go b/example/readline-demo/readline-demo.go index 68e929d..eeb3605 100644 --- a/example/readline-demo/readline-demo.go +++ b/example/readline-demo/readline-demo.go @@ -8,7 +8,7 @@ import ( "strings" "time" - "github.com/michalpristas/readline" + "github.com/chzyer/readline" ) func usage(w io.Writer) {