getch2: Correctly deal with getch2_pos when switching to STATE_ESC

In STATE_INITIAL, STATE_ESC would see the ESC (instead of the key following
it) because of the previous rewind; we have to skip the ESC.

In STATE_TERMCAP, in case the first character in the buffer isn't an ESC,
we would accidentally skip it when switching to STATE_NONESC. Reset the
getch2_pos to 0 and then skip the ESC when switching to STATE_ESC.