Fix line numbering in the command-line shell

The code that handled the terminal prompt was treating $Line as the
next line number. This meant that $Line and In/Out were off by one:

  In[1]:= $Line
  Out[1]= 2

Fix this by treating $Line as the last line number when handling the
prompt.
Fix line wrapping with readline and coloured prompts

Readline needs to know the width of the prompt in order to wrap lines
correctly. To get this right, it has to know which character sequences
don't take up any screen space. The \001 and \002 characters (ASCII
SOH and STX) indicate the beginning and end of a nonprinting character
sequence to readline.

Fix the line wrapping by surrounding any colour escapes with these
characters.

For this to work properly, we need to do this to the prompt passed to
raw_input(), but not to any other prompts we print, otherwise the \001
and \002 characters end up going to the terminal. Refactor the call to
raw_input into a new read_line() method to achieve this.
Use colours by default only if stdout is a tty

Prevents colours in "mathics | cat" or "mathics >somefile", but e.g.
"mathics --colors=linux <input.m | less -R" works as expected.
Fix input decoding when stdin isn't a tty

Use locale.getpreferredencoding() to get the user's encoding and
decode input from stdin or the -e option that way. Files on the
command line are still treated as UTF-8.

Fixes "cat | mathics" and "mathics <input.m"
Merge pull request #155 from bnjones/cmdline-fixes

Fix a few minor bugs in the command-line shell