Empty stdin when closing window

Multibyte key sequences (e.g. F1) start with escape, which closes the window,
and then go on. Any further input is now cleared before closing windows so it
isn't interpreted as user input.

Closes #139