[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)
:+1: