diff --git a/complete_tag.go b/complete_tag.go new file mode 100644 index 0000000..2039458 --- /dev/null +++ b/complete_tag.go @@ -0,0 +1,7 @@ +package readline + +type TabCompleter struct{} + +func (t *TabCompleter) Do([]rune, int) ([][]rune, int) { + return [][]rune{[]rune("\t")}, 0 +} diff --git a/readline.go b/readline.go index 4b866fb..20a2108 100644 --- a/readline.go +++ b/readline.go @@ -93,6 +93,9 @@ func (c *Config) Init() error { c.EOFPrompt = "" } + if c.AutoComplete == nil { + c.AutoComplete = &TabCompleter{} + } if c.FuncGetWidth == nil { c.FuncGetWidth = GetScreenWidth } diff --git a/runebuf.go b/runebuf.go index e402aed..538832e 100644 --- a/runebuf.go +++ b/runebuf.go @@ -430,7 +430,13 @@ func (r *RuneBuffer) output() []byte { } } else { - buf.Write([]byte(string(r.buf))) + for idx := range r.buf { + if r.buf[idx] == '\t' { + buf.WriteString(strings.Repeat(" ", TabWidth)) + } else { + buf.WriteRune(r.buf[idx]) + } + } if r.isInLineEdge() { buf.Write([]byte(" \b")) } diff --git a/runes.go b/runes.go index b85af7a..8ed54ce 100644 --- a/runes.go +++ b/runes.go @@ -6,6 +6,7 @@ import ( ) var runes = Runes{} +var TabWidth = 4 type Runes struct{} @@ -98,6 +99,9 @@ var doubleWidth = []*unicode.RangeTable{ } func (Runes) Width(r rune) int { + if r == '\t' { + return TabWidth + } if unicode.IsOneOf(zeroWidth, r) { return 0 }