A library that helps you to print colored and styled text in the Java console 🖌🖌🖌️
Find a file
2023-06-30 15:38:38 +00:00
.github/workflows chore(deps): update gradle/gradle-build-action digest to bde650d 2023-06-30 15:38:38 +00:00
.idea Up version ⬆️⬆️⬆️ 2022-06-16 07:07:22 +02:00
.m2 fix 2022-03-25 20:45:03 +02:00
Screenshots Add examples 2022-06-16 05:42:47 +02:00
src/main/java/com/anas/jcolorfulconsole Add examples 2022-06-16 05:42:47 +02:00
.gitignore Add .m2/settings.xml 2022-03-25 20:40:56 +02:00
.mergify.yml ci(Mergify): configuration update 2023-01-29 00:28:42 +02:00
CODE_OF_CONDUCT.md Create CODE_OF_CONDUCT.md 2022-03-25 01:45:55 +02:00
CONTRIBUTING.md Add contributing gide 💙 2022-06-16 06:26:51 +02:00
LICENSE.txt Change license MIT -> GPTv3 2022-06-16 05:09:53 +02:00
pom.xml chore(deps): update dependency org.apache.maven.plugins:maven-compiler-plugin to v3.11.0 2023-02-27 09:48:10 +00:00
README.md Add projects section 💙 2022-06-16 08:13:42 +02:00
renovate.json Add renovate.json 2023-01-28 21:33:10 +00:00

JColorfulConsole is a console color library.

Vulnerabilities Duplicated Lines (%) Quality Gate Status Technical Debt Lines of Code Code Smells Maintainability Rating Security Rating Bugs

Features:

  • Support text color.
  • Support background color.
  • Support 256 colors (RGB).
  • Support ANSI colors.
  • Support indexed colors.
  • Support text style.
  • Lightweight and fast.
  • Easy to use.

How to add this library into your project

Maven

Step 1. Add the JitPack repository to your build file


<repositories>
	<repository>
		<id>jitpack.io</id>
		<url>https://jitpack.io</url>
	</repository>
</repositories>

Step 2. Add the dependency

<dependency>
	<groupId>com.github.Anas-Elgarhy</groupId>
	<artifactId>JColorfulConsole</artifactId>
	<version>1.0.3</version>
</dependency>

Gradle:

Step 1. Add the JitPack repository to your build file
Add it in your root build.gradle at the end of repositories:

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

Step 2. Add the dependency

	dependencies {
	        implementation 'com.github.Anas-Elgarhy:JColorfulConsole:1.0.3'
	}

Usage:

public class Example1 {
    public static void main(String[] args) {
        ColoredString hello = new ColoredString("Hello, ");
        hello.setForegroundColor(TextColor.ANSI.BLUE); // Set text color to blue
        hello.setBackgroundColor("magenta"); // Set background color to magenta
        hello.addStyle(TextStyle.BOLD); // Add bold style

        ColoredString world = new ColoredString();
        world.setStr("World!"); // Set string to "World!"
        world.setForegroundColor("#542413"); // Set text color
        world.setBackgroundColor(new TextColor.RGB(34, 139, 34)); // Set background color
        world.addStyle(TextStyle.ITALIC); // Add italic style

        System.out.print(hello); // Print colored string
        System.out.print(world); // Print colored string

    }
}

Result of example 1

public class Example2 {
    public static void main(String[] args) {
        new Thread(() -> {
            while (true) {
                System.out.println(new ColoredString("Hi",
                        new TextColor.RGB((int) (Math.random() * 255), (int) (Math.random() * 255), (int) (Math.random() * 255)),
                        new TextColor.RGB((int) (Math.random() * 255), (int) (Math.random() * 255), (int) (Math.random() * 255)),
                        TextStyle.values()[(int) (Math.random() * TextStyle.values().length)]));
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }
}

Result of example 2

Requirements for development:

  • Maven
  • jdk 17
  • IntelliJ IDEA (not required but recommended)

TODO

  • Add Tests
  • Add Formatter
  • Add Documentation
  • Add more examples

Projects using this library 💙

Available in

GitHub GitLab BitBucket Codeberg

Quality gate

SonarCloud

License: GPL-3.0