mirror of
https://github.com/peco/peco.git
synced 2026-09-10 07:16:29 -04:00
newMutex, sync.Locker
This commit is contained in:
parent
38992a4cc0
commit
4594f2d26d
16
ctx.go
16
ctx.go
|
|
@ -60,7 +60,7 @@ func (p *Ctx) MoveCaretPos(offset int) {
|
|||
|
||||
type FilterQuery struct {
|
||||
query []rune
|
||||
mutex *sync.Mutex
|
||||
mutex sync.Locker
|
||||
}
|
||||
|
||||
func (q FilterQuery) Query() []rune {
|
||||
|
|
@ -113,9 +113,9 @@ type Ctx struct {
|
|||
maxPage int
|
||||
selection *Selection
|
||||
lines []Match
|
||||
linesMutex *sync.Mutex
|
||||
linesMutex sync.Locker
|
||||
current []Match
|
||||
currentMutex *sync.Mutex
|
||||
currentMutex sync.Locker
|
||||
bufferSize int
|
||||
config *Config
|
||||
currentMatcher int
|
||||
|
|
@ -154,7 +154,7 @@ func (m *loggingMutex) Unlock() {
|
|||
func NewCtx(o CtxOptions) *Ctx {
|
||||
c := &Ctx{
|
||||
Hub: NewHub(),
|
||||
FilterQuery: &FilterQuery{[]rune{}, &sync.Mutex{}},
|
||||
FilterQuery: &FilterQuery{[]rune{}, newMutex()},
|
||||
MatcherSet: nil,
|
||||
caretPosition: 0,
|
||||
result: []Match{},
|
||||
|
|
@ -163,9 +163,9 @@ func NewCtx(o CtxOptions) *Ctx {
|
|||
maxPage: 0,
|
||||
selection: NewSelection(),
|
||||
lines: []Match{},
|
||||
linesMutex: &sync.Mutex{},
|
||||
linesMutex: newMutex(),
|
||||
current: nil,
|
||||
currentMutex: &sync.Mutex{},
|
||||
currentMutex: newMutex(),
|
||||
config: NewConfig(),
|
||||
currentMatcher: 0,
|
||||
exitStatus: 0,
|
||||
|
|
@ -376,7 +376,7 @@ func (c *Ctx) NewView() *View {
|
|||
default:
|
||||
layout = NewDefaultLayout(c)
|
||||
}
|
||||
return &View{c, &sync.Mutex{}, layout}
|
||||
return &View{c, newMutex(), layout}
|
||||
}
|
||||
|
||||
func (c *Ctx) NewFilter() *Filter {
|
||||
|
|
@ -387,7 +387,7 @@ func (c *Ctx) NewInput() *Input {
|
|||
// Create a new keymap object
|
||||
k := NewKeymap(c.config.Keymap, c.config.Action)
|
||||
k.ApplyKeybinding()
|
||||
return &Input{c, &sync.Mutex{}, nil, k, []string{}}
|
||||
return &Input{c, newMutex(), nil, k, []string{}}
|
||||
}
|
||||
|
||||
func (c *Ctx) SetQuery(q []rune) {
|
||||
|
|
|
|||
16
hub.go
16
hub.go
|
|
@ -9,13 +9,13 @@ import (
|
|||
// it controls how the communication that goes through channels
|
||||
// are handled.
|
||||
type Hub struct {
|
||||
isSync bool
|
||||
mutex *sync.Mutex
|
||||
loopCh chan struct{}
|
||||
queryCh chan HubReq
|
||||
drawCh chan HubReq
|
||||
statusMsgCh chan HubReq
|
||||
pagingCh chan HubReq
|
||||
isSync bool
|
||||
mutex sync.Locker
|
||||
loopCh chan struct{}
|
||||
queryCh chan HubReq
|
||||
drawCh chan HubReq
|
||||
statusMsgCh chan HubReq
|
||||
pagingCh chan HubReq
|
||||
}
|
||||
|
||||
// HubReq is a wrapper around the actual requst value that needs
|
||||
|
|
@ -56,7 +56,7 @@ func (hr HubReq) Done() {
|
|||
func NewHub() *Hub {
|
||||
return &Hub{
|
||||
false,
|
||||
&sync.Mutex{},
|
||||
newMutex(),
|
||||
make(chan struct{}), // loopCh. You never send messages to this. no point in buffering
|
||||
make(chan HubReq, 5), // queryCh.
|
||||
make(chan HubReq, 5), // drawCh.
|
||||
|
|
|
|||
2
input.go
2
input.go
|
|
@ -10,7 +10,7 @@ import (
|
|||
// Input handles input events from termbox.
|
||||
type Input struct {
|
||||
*Ctx
|
||||
mutex *sync.Mutex // Currently only used for protecting Alt/Esc workaround
|
||||
mutex sync.Locker // Currently only used for protecting Alt/Esc workaround
|
||||
mod *time.Timer
|
||||
keymap Keymap
|
||||
currentKeySeq []string
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ func wrapClearSequence(a Action) Action {
|
|||
}
|
||||
|
||||
if len(i.currentKeySeq) > 0 {
|
||||
i.SendStatusMsgAndClear(strings.Join(i.currentKeySeq, " "), 500 * time.Millisecond)
|
||||
i.SendStatusMsgAndClear(strings.Join(i.currentKeySeq, " "), 500*time.Millisecond)
|
||||
i.currentKeySeq = []string{}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -189,7 +189,7 @@ type StatusBar struct {
|
|||
*Ctx
|
||||
*AnchorSettings
|
||||
clearTimer *time.Timer
|
||||
timerMutex *sync.Mutex
|
||||
timerMutex sync.Locker
|
||||
}
|
||||
|
||||
// NewStatusBar creates a new StatusBar struct
|
||||
|
|
@ -198,7 +198,7 @@ func NewStatusBar(ctx *Ctx, anchor VerticalAnchor, anchorOffset int) *StatusBar
|
|||
ctx,
|
||||
NewAnchorSettings(anchor, anchorOffset),
|
||||
nil,
|
||||
&sync.Mutex{},
|
||||
newMutex(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,11 +13,11 @@ import (
|
|||
type MatcherSet struct {
|
||||
current int
|
||||
matchers []Matcher
|
||||
mutex *sync.Mutex
|
||||
mutex sync.Locker
|
||||
}
|
||||
|
||||
func NewMatcherSet() *MatcherSet {
|
||||
return &MatcherSet{0, []Matcher{}, &sync.Mutex{}}
|
||||
return &MatcherSet{0, []Matcher{}, newMutex()}
|
||||
}
|
||||
|
||||
func (s *MatcherSet) GetCurrent() Matcher {
|
||||
|
|
|
|||
|
|
@ -4,13 +4,13 @@ import "sync"
|
|||
|
||||
type interceptorArgs []interface{}
|
||||
type interceptor struct {
|
||||
m *sync.Mutex
|
||||
m sync.Locker
|
||||
events map[string][]interceptorArgs
|
||||
}
|
||||
|
||||
func newInterceptor() *interceptor {
|
||||
return &interceptor{
|
||||
&sync.Mutex{},
|
||||
newMutex(),
|
||||
make(map[string][]interceptorArgs),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ func (b *BufferReader) Loop() {
|
|||
}
|
||||
}()
|
||||
|
||||
m := &sync.Mutex{}
|
||||
m := newMutex()
|
||||
once := &sync.Once{}
|
||||
var refresh *time.Timer
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,6 @@
|
|||
package peco
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/nsf/termbox-go"
|
||||
)
|
||||
import "github.com/nsf/termbox-go"
|
||||
|
||||
// Screen hides termbox from tne consuming code so that
|
||||
// it can be swapped out for testing
|
||||
|
|
@ -21,7 +17,7 @@ type Termbox struct{}
|
|||
|
||||
// termbox always gives us some sort of warning when we run
|
||||
// go run -race cmd/peco/peco.go
|
||||
var termboxMutex = &sync.Mutex{}
|
||||
var termboxMutex = newMutex()
|
||||
|
||||
func (t Termbox) Clear(fg, bg termbox.Attribute) error {
|
||||
termboxMutex.Lock()
|
||||
|
|
|
|||
|
|
@ -10,11 +10,11 @@ import (
|
|||
// largest line number
|
||||
type Selection struct {
|
||||
selection []int
|
||||
mutex *sync.Mutex
|
||||
mutex sync.Locker
|
||||
}
|
||||
|
||||
func NewSelection() *Selection {
|
||||
return &Selection{nil,&sync.Mutex{}}
|
||||
return &Selection{nil, newMutex()}
|
||||
}
|
||||
|
||||
func (s *Selection) GetSelection() []int {
|
||||
|
|
|
|||
Loading…
Reference in a new issue