From 518703b826db5d00d80179082cfa1ff936d8a903 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Tue, 9 Apr 2019 15:55:45 -0700 Subject: [PATCH] Added colorize method. --- .../java/net/thauvin/erik/mobibot/Utils.java | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/thauvin/erik/mobibot/Utils.java b/src/main/java/net/thauvin/erik/mobibot/Utils.java index d37e9bc..4c7d8d5 100644 --- a/src/main/java/net/thauvin/erik/mobibot/Utils.java +++ b/src/main/java/net/thauvin/erik/mobibot/Utils.java @@ -73,7 +73,7 @@ public final class Utils { * @return The bold string. */ public static String bold(final String s) { - return Colors.BOLD + s + Colors.BOLD; + return colorize(s, Colors.BOLD); } /** @@ -152,6 +152,20 @@ public final class Utils { return s.substring(0, 1).toUpperCase() + s.substring(1); } + /** + * Colorize a string. + * + * @param s The string. + * @param color The color. + * @return The colorized string. + */ + public static String colorize(final String s, final String color) { + if (color.equals(Colors.BOLD) || color.equals(Colors.REVERSE)) { + return color + s + color; + } + return color + s + Colors.NORMAL; + } + /** * Meks the given string cyan * @@ -159,7 +173,7 @@ public final class Utils { * @return The cyan string. */ public static String cyan(final String s) { - return Colors.CYAN + s + Colors.NORMAL; + return colorize(s, Colors.CYAN); } /** @@ -211,7 +225,7 @@ public final class Utils { * @return The green string. */ public static String green(final String s) { - return Colors.DARK_GREEN + s + Colors.NORMAL; + return colorize(s, Colors.DARK_GREEN); } /** @@ -276,7 +290,7 @@ public final class Utils { * @return The reverse color string. */ public static String reverseColor(final String s) { - return Colors.REVERSE + s + Colors.REVERSE; + return colorize(s, Colors.REVERSE); } /**