diff --git a/config.go b/config.go index 7e748ae..423c881 100644 --- a/config.go +++ b/config.go @@ -6,6 +6,7 @@ import ( "os" "path/filepath" "strings" + "strconv" "github.com/nsf/termbox-go" "github.com/peco/peco/filter" @@ -133,11 +134,21 @@ func stringsToStyle(style *Style, raw []string) error { fg, ok := stringToFg[s] if ok { style.fg = fg + } else { + if fg, err := strconv.ParseUint(s, 10, 8); err == nil { + style.fg = termbox.Attribute(fg+1) + } } bg, ok := stringToBg[s] if ok { style.bg = bg + } else { + if strings.HasPrefix(s, "on_") { + if bg, err := strconv.ParseUint(s[3:], 10, 8); err == nil { + style.bg = termbox.Attribute(bg+1) + } + } } } diff --git a/interface.go b/interface.go index 8bb2a53..3ae9515 100644 --- a/interface.go +++ b/interface.go @@ -151,10 +151,10 @@ type Selection struct { // Screen hides termbox from the consuming code so that // it can be swapped out for testing type Screen interface { - Init() error + Init(*Config) error Close() error Flush() error - PollEvent(context.Context) chan termbox.Event + PollEvent(context.Context, *Config) chan termbox.Event Print(PrintArgs) int Resume() SetCell(int, int, rune, termbox.Attribute, termbox.Attribute) diff --git a/peco.go b/peco.go index e093549..b168424 100644 --- a/peco.go +++ b/peco.go @@ -364,8 +364,8 @@ func (p *Peco) Run(ctx context.Context) (err error) { // screen.Init must be called within Run() because we // want to make sure to call screen.Close() after getting // out of Run() - p.screen.Init() - go NewInput(p, p.Keymap(), p.screen.PollEvent(ctx)).Loop(ctx, cancel) + p.screen.Init(&p.config) + go NewInput(p, p.Keymap(), p.screen.PollEvent(ctx, &p.config)).Loop(ctx, cancel) go NewView(p).Loop(ctx, cancel) go NewFilter(p).Loop(ctx, cancel) }() diff --git a/screen.go b/screen.go index f8d0325..c5d7b79 100644 --- a/screen.go +++ b/screen.go @@ -10,12 +10,12 @@ import ( "github.com/pkg/errors" ) -func (t *Termbox) Init() error { +func (t *Termbox) Init(cfg *Config) error { if err := termbox.Init(); err != nil { return errors.Wrap(err, "failed to initialized termbox") } - return t.PostInit() + return t.PostInit(cfg) } func NewTermbox() *Termbox { @@ -55,7 +55,7 @@ func (t *Termbox) Flush() error { // PollEvent returns a channel that you can listen to for // termbox's events. The actual polling is done in a // separate gouroutine -func (t *Termbox) PollEvent(ctx context.Context) chan termbox.Event { +func (t *Termbox) PollEvent(ctx context.Context, cfg *Config) chan termbox.Event { // XXX termbox.PollEvent() can get stuck on unexpected signal // handling cases. We still would like to wait until the user // (termbox) has some event for us to process, but we don't @@ -97,7 +97,7 @@ func (t *Termbox) PollEvent(ctx context.Context) chan termbox.Event { case <-ctx.Done(): return case replyCh := <-t.resumeCh: - t.Init() + t.Init(cfg) close(replyCh) } } diff --git a/screen_posix.go b/screen_posix.go index 7e41028..d68f564 100644 --- a/screen_posix.go +++ b/screen_posix.go @@ -2,6 +2,14 @@ package peco -func (t *Termbox) PostInit() error { +import "github.com/nsf/termbox-go" + +func (t *Termbox) PostInit(cfg *Config) error { + // This has no effect on Windows, + // because termbox.SetOutputMode always sets termbox.OutputNormal on Windows. + if cfg.Use256Color { + termbox.SetOutputMode(termbox.Output256) + } + return nil } diff --git a/screen_windows.go b/screen_windows.go index 4cba33b..b223167 100644 --- a/screen_windows.go +++ b/screen_windows.go @@ -2,7 +2,7 @@ package peco import "github.com/nsf/termbox-go" -func (t *Termbox) PostInit() error { +func (t *Termbox) PostInit(cfg *Config) error { // Windows handle Esc/Alt self termbox.SetInputMode(termbox.InputEsc | termbox.InputAlt)