Refactor termbox frontend

Decompose large functions into smaller descriptive functions. Also, add
a test around a particularly involved options parsing. I hope to continue refactoring this file in order to break out smaller testable functions and reduce the use of globals.