Added support for all mouse modes

In addition to normal mode (1000), added support for XTERM (1005), URXVT
(1015), and SGR (1006) modes. Also added safety to avoid sending garbage
characters when the other application uses a mouse mode incorrectly.