Clean up termbox frontend code

This fixes https://github.com/limetext/lime/issues/376 By default on a new line, no line number is printed and the editor is out of place. This is due to a missing piece of code that prints the line number after a newline is detected. I've also cleaned up some code throughout the file because it was bothering me.
Why so much repetition? What's the advantage of this over what we have?