mirror of
https://github.com/peco/peco.git
synced 2026-09-10 07:16:29 -04:00
some linting
This commit is contained in:
parent
580fc48264
commit
64fc4d12fd
|
|
@ -5,6 +5,8 @@ import (
|
|||
"runtime"
|
||||
)
|
||||
|
||||
// ErrBufferOutOfRange is returned when the index within the buffer that
|
||||
// was queried was out of the containing buffer's range
|
||||
var ErrBufferOutOfRange = errors.New("error: Specified index is out of range")
|
||||
|
||||
type Pipeliner interface {
|
||||
|
|
@ -64,6 +66,8 @@ func acceptPipeline(cancel chan struct{}, in chan Line, out chan Line, pc *pipel
|
|||
//
|
||||
// Buffers should be immutable.
|
||||
type LineBuffer interface {
|
||||
Pipeliner
|
||||
|
||||
LineAt(int) (Line, error)
|
||||
Size() int
|
||||
|
||||
|
|
|
|||
2
cli.go
2
cli.go
|
|
@ -122,7 +122,7 @@ func (cli *CLI) Run() error {
|
|||
case !IsTty(os.Stdin.Fd()):
|
||||
in = os.Stdin
|
||||
default:
|
||||
return fmt.Errorf("You must supply something to work with via filename or stdin")
|
||||
return fmt.Errorf("error: You must supply something to work with via filename or stdin")
|
||||
}
|
||||
|
||||
ctx := NewCtx(opts)
|
||||
|
|
|
|||
|
|
@ -35,6 +35,8 @@ type Config struct {
|
|||
StickySelection bool
|
||||
}
|
||||
|
||||
// CustomFilterConfig is used to specify configuration parameters
|
||||
// to CustomFilters
|
||||
type CustomFilterConfig struct {
|
||||
// Cmd is the name of the command to invoke
|
||||
Cmd string
|
||||
|
|
@ -86,7 +88,7 @@ func (c *Config) ReadFilename(filename string) error {
|
|||
|
||||
for n, cfg := range c.CustomMatcher {
|
||||
if _, ok := c.CustomFilter[n]; ok {
|
||||
return fmt.Errorf("CustomFilter '%s' already exists. Refusing to overwrite with deprecated CustomMatcher config", n)
|
||||
return fmt.Errorf("error: CustomFilter '%s' already exists. Refusing to overwrite with deprecated CustomMatcher config", n)
|
||||
}
|
||||
|
||||
c.CustomFilter[n] = CustomFilterConfig{
|
||||
|
|
|
|||
26
ctx.go
26
ctx.go
|
|
@ -10,7 +10,7 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
var screen Screen = Termbox{}
|
||||
var screen = Screen(Termbox{})
|
||||
|
||||
// CtxOptions is the interface that defines that options can be
|
||||
// passed in from the command line
|
||||
|
|
@ -40,22 +40,22 @@ type PageInfo struct {
|
|||
maxPage int
|
||||
}
|
||||
|
||||
func (p *Ctx) CaretPos() int {
|
||||
p.mutex.Lock()
|
||||
defer p.mutex.Unlock()
|
||||
return p.caretPosition
|
||||
func (c *Ctx) CaretPos() int {
|
||||
c.mutex.Lock()
|
||||
defer c.mutex.Unlock()
|
||||
return c.caretPosition
|
||||
}
|
||||
|
||||
func (p *Ctx) SetCaretPos(where int) {
|
||||
p.mutex.Lock()
|
||||
defer p.mutex.Unlock()
|
||||
p.caretPosition = where
|
||||
func (c *Ctx) SetCaretPos(where int) {
|
||||
c.mutex.Lock()
|
||||
defer c.mutex.Unlock()
|
||||
c.caretPosition = where
|
||||
}
|
||||
|
||||
func (p *Ctx) MoveCaretPos(offset int) {
|
||||
p.mutex.Lock()
|
||||
defer p.mutex.Unlock()
|
||||
p.caretPosition = p.caretPosition + offset
|
||||
func (c *Ctx) MoveCaretPos(offset int) {
|
||||
c.mutex.Lock()
|
||||
defer c.mutex.Unlock()
|
||||
c.caretPosition = c.caretPosition + offset
|
||||
}
|
||||
|
||||
type FilterQuery struct {
|
||||
|
|
|
|||
|
|
@ -509,11 +509,9 @@ func (ecf *ExternalCmdFilter) launchExternalCmd(buf []Line, cancelCh chan struct
|
|||
|
||||
cmdCh := make(chan Line)
|
||||
go func(cmdCh chan Line, rdr *bufio.Reader) {
|
||||
defer trace("Done reader")
|
||||
defer func() { recover() }()
|
||||
defer close(cmdCh)
|
||||
for {
|
||||
trace("ReadLine")
|
||||
b, _, err := rdr.ReadLine()
|
||||
if len(b) > 0 {
|
||||
// TODO: need to redo the spec for custom matchers
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ func mergeAttribute(a, b termbox.Attribute) termbox.Attribute {
|
|||
|
||||
// Utility function
|
||||
func printScreen(x, y int, fg, bg termbox.Attribute, msg string, fill bool) int {
|
||||
var written int = 0
|
||||
var written int
|
||||
|
||||
for len(msg) > 0 {
|
||||
c, w := utf8.DecodeRuneInString(msg)
|
||||
|
|
@ -530,6 +530,7 @@ CALCULATE_PAGE:
|
|||
return nil
|
||||
}
|
||||
|
||||
//
|
||||
func (l *BasicLayout) DrawPrompt() {
|
||||
l.prompt.Draw()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,6 @@ func setDummyScreen() (*interceptor, func()) {
|
|||
func (d dummyScreen) SetCell(x, y int, ch rune, fg, bg termbox.Attribute) {
|
||||
d.record("SetCell", interceptorArgs{x, y, ch, fg, bg})
|
||||
}
|
||||
func (d dummyScreen) Clear(fg, bg termbox.Attribute) error { return nil }
|
||||
func (d dummyScreen) Flush() error {
|
||||
d.record("Flush", interceptorArgs{})
|
||||
return nil
|
||||
|
|
|
|||
16
screen.go
16
screen.go
|
|
@ -5,7 +5,6 @@ import "github.com/nsf/termbox-go"
|
|||
// Screen hides termbox from tne consuming code so that
|
||||
// it can be swapped out for testing
|
||||
type Screen interface {
|
||||
Clear(termbox.Attribute, termbox.Attribute) error
|
||||
Flush() error
|
||||
PollEvent() chan termbox.Event
|
||||
SetCell(int, int, rune, termbox.Attribute, termbox.Attribute)
|
||||
|
|
@ -20,22 +19,23 @@ type Termbox struct{}
|
|||
// go run -race cmd/peco/peco.go
|
||||
var termboxMutex = newMutex()
|
||||
|
||||
// SendEvent is used to allow programmers generate random
|
||||
// events, but it's only useful for testing purposes.
|
||||
// When interactiving with termbox-go, this method is a noop
|
||||
func (t Termbox) SendEvent(_ termbox.Event) {
|
||||
// no op
|
||||
}
|
||||
|
||||
func (t Termbox) Clear(fg, bg termbox.Attribute) error {
|
||||
termboxMutex.Lock()
|
||||
defer termboxMutex.Unlock()
|
||||
return termbox.Clear(fg, bg)
|
||||
}
|
||||
|
||||
// Flush calls termbox.Flush
|
||||
func (t Termbox) Flush() error {
|
||||
termboxMutex.Lock()
|
||||
defer termboxMutex.Unlock()
|
||||
return termbox.Flush()
|
||||
}
|
||||
|
||||
// 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() chan termbox.Event {
|
||||
// XXX termbox.PollEvent() can get stuck on unexpected signal
|
||||
// handling cases. We still would like to wait until the user
|
||||
|
|
@ -58,12 +58,14 @@ func (t Termbox) PollEvent() chan termbox.Event {
|
|||
|
||||
}
|
||||
|
||||
// SetCell writes to the terminal
|
||||
func (t Termbox) SetCell(x, y int, ch rune, fg, bg termbox.Attribute) {
|
||||
termboxMutex.Lock()
|
||||
defer termboxMutex.Unlock()
|
||||
termbox.SetCell(x, y, ch, fg, bg)
|
||||
}
|
||||
|
||||
// Size returns the dimensions of the current terminal
|
||||
func (t Termbox) Size() (int, int) {
|
||||
termboxMutex.Lock()
|
||||
defer termboxMutex.Unlock()
|
||||
|
|
|
|||
Loading…
Reference in a new issue