getch2: Don't get stuck forever if actual garbage is inputted

Have some checks to throw invalid bytes out and move the input queue
forward.

If we get an ESC sequence that doesn't have a '[' or 'O' immediately
following it, it's not an ESC sequence we care about; throw the ESC out.

Check that, if we have an UTF-8 start code, that the whole character is
valid UTF-8. If it's not, throw out the bad UTF-8 sequence.

Since the longest valid ESC sequence we check is 5 bytes long, and the
longest valid UTF-8 sequence is 4 bytes long, if we have more than 5 bytes
in the buffer and we can't consume anything from it, we throw the entire
buffer out and start over.