mirror of https://github.com/chzyer/readline.git
intercept line rendering using a 'Painter' (#116)
This commit is contained in:
parent
9f56defe66
commit
707fd8ecaa
10
operation.go
10
operation.go
|
@ -504,3 +504,13 @@ func (d *DumpListener) OnChange(line []rune, pos int, key rune) (newLine []rune,
|
|||
type Listener interface {
|
||||
OnChange(line []rune, pos int, key rune) (newLine []rune, newPos int, ok bool)
|
||||
}
|
||||
|
||||
type Painter interface {
|
||||
Paint(line []rune, pos int) []rune
|
||||
}
|
||||
|
||||
type defaultPainter struct{}
|
||||
|
||||
func (p *defaultPainter) Paint(line []rune, _ int) []rune {
|
||||
return line
|
||||
}
|
||||
|
|
|
@ -44,6 +44,8 @@ type Config struct {
|
|||
// NOTE: Listener will be triggered by (nil, 0, 0) immediately
|
||||
Listener Listener
|
||||
|
||||
Painter Painter
|
||||
|
||||
// If VimMode is true, readline will in vim.insert mode by default
|
||||
VimMode bool
|
||||
|
||||
|
@ -149,6 +151,10 @@ func (c *Config) SetListener(f func(line []rune, pos int, key rune) (newLine []r
|
|||
c.Listener = FuncListener(f)
|
||||
}
|
||||
|
||||
func (c *Config) SetPainter(p Painter) {
|
||||
c.Painter = p
|
||||
}
|
||||
|
||||
func NewEx(cfg *Config) (*Instance, error) {
|
||||
t, err := NewTerminal(cfg)
|
||||
if err != nil {
|
||||
|
|
|
@ -490,11 +490,11 @@ func (r *RuneBuffer) output() []byte {
|
|||
}
|
||||
|
||||
} else {
|
||||
for idx := range r.buf {
|
||||
if r.buf[idx] == '\t' {
|
||||
for _, e := range r.cfg.Painter.Paint(r.buf, r.idx) {
|
||||
if e == '\t' {
|
||||
buf.WriteString(strings.Repeat(" ", TabWidth))
|
||||
} else {
|
||||
buf.WriteRune(r.buf[idx])
|
||||
buf.WriteRune(e)
|
||||
}
|
||||
}
|
||||
if r.isInLineEdge() {
|
||||
|
|
Loading…
Reference in New Issue