Reset terminal before letting editline grab a line.
Fix simple parsing bug.
Create a query FSM.

The query processing was quite complex and error prone. We now switchted to a
state-machine-based implementation which significantly improves clarity by
having an explicit execution model to drive the process.