mirror of https://github.com/chzyer/readline.git
fix terminal data race (#99)
This commit is contained in:
parent
c914be64f0
commit
eef24db1d5
19
terminal.go
19
terminal.go
|
@ -10,6 +10,7 @@ import (
|
|||
)
|
||||
|
||||
type Terminal struct {
|
||||
m sync.Mutex
|
||||
cfg *Config
|
||||
outchan chan rune
|
||||
closed int32
|
||||
|
@ -121,7 +122,7 @@ func (t *Terminal) ioloop() {
|
|||
expectNextChar bool
|
||||
)
|
||||
|
||||
buf := bufio.NewReader(t.cfg.Stdin)
|
||||
buf := bufio.NewReader(t.getStdin())
|
||||
for {
|
||||
if !expectNextChar {
|
||||
atomic.StoreInt32(&t.isReading, 0)
|
||||
|
@ -206,10 +207,26 @@ func (t *Terminal) Close() error {
|
|||
return t.ExitRawMode()
|
||||
}
|
||||
|
||||
func (t *Terminal) GetConfig() *Config {
|
||||
t.m.Lock()
|
||||
cfg := *t.cfg
|
||||
t.m.Unlock()
|
||||
return &cfg
|
||||
}
|
||||
|
||||
func (t *Terminal) getStdin() io.Reader {
|
||||
t.m.Lock()
|
||||
r := t.cfg.Stdin
|
||||
t.m.Unlock()
|
||||
return r
|
||||
}
|
||||
|
||||
func (t *Terminal) SetConfig(c *Config) error {
|
||||
if err := c.Init(); err != nil {
|
||||
return err
|
||||
}
|
||||
t.m.Lock()
|
||||
t.cfg = c
|
||||
t.m.Unlock()
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue