Use readline library instead of custom code.