Skip to content

Commit

Permalink
fix nil dereference from SetConfig()
Browse files Browse the repository at this point in the history
See chzyer/readline#221 ;
we are consolidating (*Config).Init() calls into NewFromConfig and SetConfig,
and consolidating all preparatory mungeing of the config into (*Config).Init.
  • Loading branch information
slingamn committed Mar 9, 2023
1 parent 6f58797 commit 746d908
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions readline.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ func (c *Config) Init() error {
if c.FuncOnWidthChanged == nil {
c.FuncOnWidthChanged = DefaultOnSizeChanged
}
if c.Painter == nil {
c.Painter = &defaultPainter{}
}

return nil
}
Expand All @@ -166,10 +169,6 @@ 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
}

// NewFromConfig creates a readline instance from the specified configuration.
func NewFromConfig(cfg *Config) (*Instance, error) {
if err := cfg.Init(); err != nil {
Expand All @@ -180,9 +179,6 @@ func NewFromConfig(cfg *Config) (*Instance, error) {
return nil, err
}
o := NewOperation(t, cfg)
if cfg.Painter == nil {
cfg.Painter = &defaultPainter{}
}
return &Instance{
Terminal: t,
Operation: o,
Expand Down

0 comments on commit 746d908

Please sign in to comment.