/*
 * * Copyright (C) 2013-2014 Matt Baxter http://kitteh.org
 *
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use, copy,
 * modify, merge, publish, distribute, sublicense, and/or sell copies
 * of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
package org.kitteh.irc.client.library;

/**
 * Represents various formatting available in IRC.
 * <p>
 * The {@link #toString} method provides the String you need.
 */
public enum IRCFormat {
    BLACK(1),
    BLUE(12),
    BOLD('\u0002'),
    BROWN(5),
    CYAN(11),
    DARK_BLUE(2),
    DARK_GRAY(14),
    DARK_GREEN(3),
    GREEN(9),
    LIGHT_GRAY(15),
    MAGENTA(13),
    RESET('\u000f'),
    OLIVE(7),
    PURPLE(6),
    RED(4),
    REVERSE('\u0016'),
    TEAL(10),
    UNDERLINE('\u001f'),
    WHITE(0),
    YELLOW(8);

    private String toString;

    private IRCFormat(char ch) {
        this.toString = String.valueOf(ch);
    }

    private IRCFormat(int color) {
        if ((color & 15) != color) {
            throw new AssertionError("Impossible color id: " + color);
        }
        final StringBuilder builder = new StringBuilder();
        builder.append(COLOR_CHAR);
        if (color < 10) {
            builder.append('0');
        }
        builder.append(color);
        this.toString = builder.toString();
    }

    public static final char COLOR_CHAR = '\u0003';

    @Override
    public String toString() {
        return this.toString;
    }
}
@@ -1180,16 +1180,67 @@
 brary;%0A%0A
+import org.kitteh.irc.client.library.util.Sanity;%0A%0A
 /**%0A * R
@@ -1720,16 +1720,76 @@
 OW(8);%0A%0A
+    private int color;%0A    private boolean isColor = false;%0A
     priv
@@ -2234,32 +2234,89 @@
 .append(color);%0A
+        this.color = color;%0A        this.isColor = true;%0A
         this.toS
@@ -2411,77 +2411,765 @@
     
-@Override%0A    public String toString() %7B%0A        return this.toString
+/**%0A     * Gets if the format is a color.%0A     *%0A     * @return true if a color%0A     */%0A    public boolean isColor() %7B%0A        return this.isColor;%0A    %7D%0A%0A    @Override%0A    public String toString() %7B%0A        return this.toString;%0A    %7D%0A%0A    /**%0A     * Gets a String for displaying this color with a given background color.%0A     *%0A     * @param background background color%0A     * @return the color string%0A     * @throws IllegalArgumentException if using or providing a non-color%0A     */%0A    public String withBackground(IRCFormat background) %7B%0A        Sanity.truthiness(this.isColor, %22Cannot use non-color foreground.%22);%0A        Sanity.truthiness(background.isColor, %22Cannot use non-color background%22);%0A        return this.toString() + %22,%22 + background.color
 ;%0A  

Support background colors