support insert tag char (#74)

This commit is contained in:
chzyer 2016-09-02 20:10:31 +08:00 committed by GitHub
parent 4ffff9f41c
commit 31eb6be473
4 changed files with 21 additions and 1 deletions

7
complete_tag.go Normal file
View File

@ -0,0 +1,7 @@
package readline
type TabCompleter struct{}
func (t *TabCompleter) Do([]rune, int) ([][]rune, int) {
return [][]rune{[]rune("\t")}, 0
}

View File

@ -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
}

View File

@ -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"))
}

View File

@ -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
}