[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)
NVM, I pushed the rbuffer change back and now it worked. I was too tired yesterday and made some integer overflow mistake.