jroimartin / gocui

Minimalist Go package aimed at creating Console User Interfaces.
BSD 3-Clause "New" or "Revised" License
9.92k stars 608 forks source link

Buffer not being flushed before polling events #165

Open jesseduffield opened 6 years ago

jesseduffield commented 6 years ago

Hey, thanks for making this awesome library!

I'm not very well-versed in the terminology of terminals, but I think there is a bug caused by not calling g.flush() at the beginning of MainLoop(). In my application I switch to a third party process, closing the gui beforehand, then I reinitialize the gui, however I can sneak in keypresses as processes switch, meaning when the mainloop begins again, I get a slice out of bounds error from termbox's PollEvent() where it does this:

    if event.N != 0 {
        copy(inbuf, inbuf[event.N:])
        inbuf = inbuf[:len(inbuf)-event.N]
    }

Producing repro steps is tricky, but I'm wondering if I'm right in assuming the solution is to chuck a g.flush() as the first line in g.MainLoop()? Testing this locally on my gocui fork works for me