telnet: add telnet history support

adapted from Yoshinori Sato's patch:
https://github.com/ysat0/openocd/commit/2f07f4600a0da8206612d78c159bbe1171aa41c2

Change-Id: I084b86d316b0aa6e9593f007c024961dbda805e9
Signed-off-by: Spencer Oliver <spen@spen-soft.co.uk>
Reviewed-on: http://openocd.zylin.com/1310
Tested-by: jenkins
Reviewed-by: Freddie Chopin <freddie.chopin@gmail.com>