issue #507: fix/simplify parsing of colors

I verified that xterm, gnome-terminal, and one other thing worked similarly to this code, and I tested this against the original issue.