... by punting the problem when the input is an infinite stream.
This commit fixes the blocking, but the subsequent queries don't seem
to be properly running
refs #494
* Move internal stuff to internal
* Properly use conditional compilation to detect Windows
* Move type declarations to one location (except for a few places still)
We should check both 'ev.Key' and 'ev.Ch'. Because ev.Key is always '0'
if input does not have prefix('Ctrl-', 'Alt-') or input is not some
special key. If user binds some command to 'C-Space' or 'C-2', 'C-~'
(then that command is set to 'input.config.Keymap[0]'), the command
is executed by inputting non-prefix key like 'a', 'b', 'c'.
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