Large cleanup and refactoring of unescape() function.
Remove old unescape() function
more detailed debugging when terminal type cannot be found

Ref: #1060
fall back to ANSI terminal type if setupterm fails

Closes: https://github.com/fish-shell/fish-shell/issues/1060

'ansi' should always be present (tested on Solaris, Linux, FreeBSD,
Darwin).

Also overrides TERM so that other programs behave consistently e.g.
fish_pager.

The error message makes no specific mention of terminfo or termcap as
these vary across operating systems.