Make sure we return complete lines from readline() and fix regressions

This should fix everything that was broken by the premature merge of my branch, as well as implementing the readline() change.