A Java library that lets your print formatted text using ANSI color codes. It's simple and lightweight, and very easy to use!
To actually use the library, you will need to add it to the Java Build Path. Here are instructions on how to do that in Eclipse:
- Right-click the project and select "Properties"
- Select "Java Build Path"
- Select "Add External Jars..."
- Navigate to the directory to where you downloaded the TextColor.jar file, and select "Open"
Using the API is very simple. Start by importing the com.libs.textcolor.main.TextColor class. For example:
import com.libs.textcolor.main.TextColor;
public class TextColorTest {
public static final void main(String[] args) {
System.out.println(TextColor.ANSI_FG_RED + "This text will be in red." + TextColor.ANSI_ALL_RESET);
}
}You can also combine multiple styles:
import com.libs.textcolor.main.TextColor;
public class TextColorTest {
public static final void main(String[] args) {
System.out.println(TextColor.ANSI_BOLD_ON + TextColor.ANSI_FG_RED + "This text will be in red and bold." + TextColor.ANSI_ALL_RESET);
}
}It is also possible to generate a TrueColor ANSI escape code with this library, just do the following:
import com.libs.textcolor.main.TextColor;
public class TextColorTest {
public static final void main(String[] args) {
System.out.println(TextColor.ANSI_FG_VALUE(132, 65, 42) + "Try combining different amounts of red, green, and blue!" + TextColor.ANSI_ALL_RESET);
}
}IMPORTANT: Not all ANSI color codes are supported by every terminal! Most codes here are not supported by the Windows Command Prompt. If you're looking for an ANSI library that supports Windows, I recommend checking out the Jansi library.
If you're using an IDE, chances are that the codes will not display into the built-in console. You will need to export it first, then you can run it from the command prompt.