mirror of
https://github.com/peco/peco.git
synced 2026-09-10 07:16:29 -04:00
Apply 256color configuration
This commit is contained in:
parent
a14f3abf35
commit
a7cd43ff22
11
config.go
11
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
4
peco.go
4
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)
|
||||
}()
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue