From 8069f8eb2f21158d76a6e63644fbb6018773814c Mon Sep 17 00:00:00 2001 From: Daisuke Maki Date: Thu, 16 Mar 2017 23:16:12 +0900 Subject: [PATCH 1/3] Make Resume a blocking operation This is required because we need to make sure we know termbox has been initialized before attempting to make another drawing operation. Notably, without proper termbox initialization, screen.Size() returns a bogus value, and we miss the line location where we left off to execute the external command specified by --exec --- action.go | 2 +- interface.go | 4 ++-- screen.go | 13 ++++++++++--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/action.go b/action.go index f2d791d..7239698 100644 --- a/action.go +++ b/action.go @@ -356,7 +356,7 @@ func doFinish(ctx context.Context, state *Peco, _ termbox.Event) { err = cmd.Run() state.screen.Resume() - state.ExecQuery() + state.Hub().SendDraw(&DrawOptions{DisableCache: true}) if err != nil { // bail out, or otherwise the user cannot know what happened state.Exit(errors.Wrap(err, `failed to execute command`)) diff --git a/interface.go b/interface.go index 3d4472f..fff446c 100644 --- a/interface.go +++ b/interface.go @@ -162,8 +162,8 @@ type Screen interface { // Termbox just hands out the processing to the termbox library type Termbox struct { mutex sync.Mutex - resumeCh chan (struct{}) - suspendCh chan (struct{}) + resumeCh chan chan struct{} + suspendCh chan struct{} } // View handles the drawing/updating the screen diff --git a/screen.go b/screen.go index edbce87..f6dd71e 100644 --- a/screen.go +++ b/screen.go @@ -21,7 +21,7 @@ func (t *Termbox) Init() error { func NewTermbox() *Termbox { return &Termbox{ suspendCh: make(chan struct{}), - resumeCh: make(chan struct{}), + resumeCh: make(chan chan struct{}), } } @@ -92,8 +92,9 @@ func (t *Termbox) PollEvent(ctx context.Context) chan termbox.Event { select { case <-ctx.Done(): return - case <-t.resumeCh: + case replyCh := <-t.resumeCh: t.Init() + close(replyCh) } } }() @@ -109,10 +110,16 @@ func (t *Termbox) Suspend() { } func (t *Termbox) Resume() { + // Resume must be a block operation, because we can't safely proceed + // without actually knowing that termbox has been re-initialized. + // So we send a channel where we expect a reply back, and wait for that + ch := make(chan struct{}) select { - case t.resumeCh <- struct{}{}: + case t.resumeCh <- ch: default: } + + <-ch } // SetCell writes to the terminal From 94a027170644f710f9628038527723ed5f034a69 Mon Sep 17 00:00:00 2001 From: Daisuke Maki Date: Thu, 16 Mar 2017 23:44:00 +0900 Subject: [PATCH 2/3] Update changes --- Changes | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Changes b/Changes index a66ef3a..65f8c01 100644 --- a/Changes +++ b/Changes @@ -2,8 +2,17 @@ Changes ======= v0.5.1 - unreleased + Bugs/Fixes + * When --exec is used, and you come back from the external command, + you lost your selected location in the peco view. #410 Backwards Incompatible Change: * --tty has been removed. it was not being used anyways. + Miscellaneous + * External commands specified in --exec now receive + PECO_FILENAME, PECO_LINE_COUNT, PECO_QUERY, and + PECO_MACHED_LINE_COUNT as environment variables + * Removed unused structs + * Fixed glide related Mkaefile actions v0.5.0 - 06 Mar 2017 Backwards Incompatible Change: From 330810872969c012bec123975b22e8377393c105 Mon Sep 17 00:00:00 2001 From: Daisuke Maki Date: Thu, 16 Mar 2017 23:58:54 +0900 Subject: [PATCH 3/3] Baaah, fix glide check while we're at it --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 554132e..a883bd7 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ VERSION=$(patsubst "%",%,$(lastword $(shell grep 'const version' peco.go))) RELEASE_DIR=releases ARTIFACTS_DIR=$(RELEASE_DIR)/artifacts/$(VERSION) SRC_FILES = $(wildcard *.go cmd/peco/*.go internal/*/*.go) -HAVE_GLIDE:=$(shell which glide >/dev/null 2>&1 && echo "yes") +HAVE_GLIDE:=$(shell (test -e $(INTERNAL_BIN_DIR)/$(THIS_GOOS)/$(THIS_GOARCH)/glide || which glide >/dev/null 2>&1 ) && echo "yes") GITHUB_USERNAME=peco BUILD_TARGETS= \ build-linux-arm64 \