Java Terminal Color Output colorize(String original)

Here you can find the source of colorize(String original)

Description

Converts color codes into the simoleon code.

License

Open Source License

Parameter

Parameter Description
original Original string to be parsed against group of color names.

Return

String - The parsed string after conversion.

Declaration

public static String colorize(String original) 

Method Source Code

//package com.java2s;
/**/*from www  . j  a va2  s  . co m*/
 * Permissions 2.x
 * Copyright (C) 2011  Matt 'The Yeti' Burnett <admin@theyeticave.net>
 * Original Credit & Copyright (C) 2010 Nijikokun <nijikokun@gmail.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Permissions Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Permissions Public License for more details.
 *
 * You should have received a copy of the GNU Permissions Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    /**
     * Converts color codes into the simoleon code. Sort of a HTML format color
     * code tag.
     * <p>
     * Color codes allowed: black, navy, green, teal, red, purple, gold, silver,
     * gray, blue, lime, aqua, rose, pink, yellow, white.
     * </p>
     * Example: <blockquote
     * 
     * <pre>
     * Messaging.colorize(&quot;Hello &lt;green&gt;world!&quot;); // returns: Hello \u00A72world!
     * </pre>
     * 
     * </blockquote>
     * 
     * @param original
     *            Original string to be parsed against group of color names.
     * 
     * @return <code>String</code> - The parsed string after conversion.
     */
    public static String colorize(String original) {
        // Removed the weird character
        return original.replace("<black>", "\u00A70").replace("<navy>", "\u00A71").replace("<green>", "\u00A72")
                .replace("<teal>", "\u00A73").replace("<red>", "\u00A74").replace("<purple>", "\u00A75")
                .replace("<gold>", "\u00A76").replace("<silver>", "\u00A77").replace("<gray>", "\u00A78")
                .replace("<blue>", "\u00A79").replace("<lime>", "\u00A7a").replace("<aqua>", "\u00A7b")
                .replace("<rose>", "\u00A7c").replace("<pink>", "\u00A7d").replace("<yellow>", "\u00A7e")
                .replace("<white>", "\u00A7f");
    }
}

Related

  1. colorise(final char alt, final String message)
  2. colorize(String color, String str)
  3. colorize(String string)
  4. colorizeBackground(String str, String color)
  5. colorizeBackground(String str, String color)
  6. colorizeBackground(String str, String color, boolean autoff)