This fixes an issue with colors in the COLOR command on ANSI terminals. The
first 8 color codes are in one range of numbers and the second are in a
second range. bwx_COLOR expected all 16 colors to be contiguous.
Also the code was cleaned up to use escapes where appropriate and to use
better primitive functions where available.