Reduce duplication in use of inputHistory.

Replaces repeated patterns for clearing and appending to the input history with single function calls. This would be worth doing for its own sake to make the code clearer & simpler, but it has the side benefit that it gives a way to "hook" pushInput for monitoring/tracing if anybody ever wants to do something like that.