[RDY] Refactor input buffer-related code

Some cleanup of input buffer code(moved from ui.c to os/input.c). Still needs some tests(for `'termencoding'`, though it will be irrelevant once all terminal code is externalized to a UI)
Why not search backwards for the "first" `CTRL-C`, so that we only need at most one memmove?