[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)
I did that in a previous commit where I changed `inbuf` to be a `RBuffer`, unfortunately it caused some failures in test49 and I couldn't immediately figure out what was wrong so I restored to it's previous ui.c form.

Would you be interested in reviewing my first attempt? You have a good eye for catching bugs, maybe you can figure out whats wrong by a quick look