import java.awt.Color;
import hsa.Console;

public class Colour
{
    static Console c;

    public static void main (String[] args)
    {
	Colour p = new Colour ();
	p.process ();
    }
    
    void process ()
    {
	c = new Console ();
	Color background = new Color (0x3B, 0x50, 0x65);
	Color dodgerblue = new Color (0x1E, 0x90, 0xFF);
	int i, clr;
	String input;

	c.print ("Enter \"^\" to abort");
	while (true)
	{
	    c.print ("\n\nInput: ");
	    input = c.readLine ();
	    if (input.equals ("^"))
	    {
		c.setTextColor (Color.red);
		c.print ("Aborted");
		break;
	    }
	    c.print ("Output:");
	    c.setTextBackgroundColor (background);
	    c.setTextColor (Color.white);
	    c.print (" ");
	    for (i = 0 ; i < input.length () ; i++)
	    {
		if (input.charAt (i) == '^')
		{
		    if (i > input.length () - 3)
			break;
		    else
		    {
			i++;
			clr = (int) input.charAt (i);
			if ((clr > 32 && clr < 41) || (clr > 48 && clr < 57) || (clr > 64 && clr < 73) || (clr > 80 && clr < 89) || (clr > 96 && clr < 105) || (clr > 112 && clr < 121))
			    clr = clr % 8;
			if (clr == 48)
			    clr = 7;
			switch (clr)
			{
			    case 0:
				c.setTextColor (Color.gray);
				break;
			    case 1:
				c.setTextColor (Color.red);
				break;
			    case 2:
				c.setTextColor (Color.green);
				break;
			    case 3:
				c.setTextColor (Color.yellow);
				break;
			    case 4:
				c.setTextColor (dodgerblue);
				break;
			    case 5:
				c.setTextColor (Color.cyan);
				break;
			    case 6:
				c.setTextColor (Color.magenta);
				break;
			    case 7:
				c.setTextColor (Color.white);
				break;
			    default:
				c.setTextColor (Color.black);
			}
			continue;
		    }
		}
		c.print (input.charAt (i));
	    }
	    c.print (" ");
	    c.setTextBackgroundColor (Color.white);
	    c.setTextColor (Color.black);
	}
    }
}


