This change fixes#144 by delaying all the terminal initialization
until there's something coming in from the standard input.
Without this, for example, a succesive chain of commands that expect to
use stdin will fail, because peco might accidentally grab the stdin
under the hood. With this change, peco is forced to wait to do any
terminal related stuff until some output has been spewed by the
previous command (which is most likely when the command is ready to
give up the control of the terminal), so things work again.
This adds -b / --buffer-size to the peco binary. It basically limits the
maximum number of lines that peco will hold at any given time, allowing
you to keep peco running for a long time, even when you are receiving an
infinite stream of lines.
By default the buffer size is unlimited. If --buffer-size is specified,
lines will be thrown away in FIFO order
This makes peco accept lines with NUL(\0) characters.
Anything before the NUL is used as the string to be displayed
in the peco view AND used for matching.
Anything after the NUL is used as the output when peco is done
Should fix#76
termbox's PollEvent() blocks, and on particular instances it blocks
even after termbox.Close() is called. In order to workaround this,
we isolate termbox.PollEvent() in a goroutine so we can just wait
for something to come in via a channel.
In this scenario, once our main functions exit, termbox's polling
is cleaned up by go itself, and we don't get stuck in that loop.
Because previously everything has been written using non-buffered
channels, the request to refresh the screen would always block.
This resulted in the main thread always waiting to write to
ctx.drawCh until viewer.Loop() registered itself to the waitgroup
via wg.Add(), therefore making the successive wg.Wait() actually wait.
When (this change does not do this) we do use buffered channels,
this guarantee breaks, and the main thread goes immediately to
wg.Wait() before viewer.Loop() has the chance to register
itself to the wait group
This change explicitly forces the main thread to call wg.Add()
to prevent this from happening