Add examples

This commit is contained in:
Anas Elgarhy 2022-06-16 05:42:47 +02:00
parent fb8ba71e67
commit 3cce7ba71e
6 changed files with 54 additions and 27 deletions

View file

@ -6,8 +6,10 @@
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="JColorfulConsole" />
</profile>
</annotationProcessing>
<bytecodeTargetLevel>
<module name="examples" target="1.8" />
</bytecodeTargetLevel>
</component>
</project>

8
.idea/modules.xml Normal file
View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/examples.iml" filepath="$PROJECT_DIR$/examples.iml" />
</modules>
</component>
</project>

View file

@ -43,6 +43,49 @@ allprojects {
## Usage:
```java
public class Example1 {
public static void main(String[] args) {
ColoredString hello = new ColoredString("Hello, ");
hello.setForegroundColor(TextColor.ANSI.BLUE); // Set text color to red
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](./Screenshots/1.0.1-example1.png)
```java
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](./Screenshots/1.0.1-example2.gif)
## Requirements for development:
- Maven
- jdk 17

Binary file not shown.

After

Width:  |  Height:  |  Size: 2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 67 KiB

View file

@ -1,26 +0,0 @@
package test;
import com.anas.jcolorfulconsole.ColoredString;
import com.anas.jcolorfulconsole.TextStyle;
import com.anas.jcolorfulconsole.lanterna.TextColor;
public class Main {
public static void main(String[] args) {
ColoredString coloredString = new ColoredString("Hello World", null, "blue", TextStyle.BOLD, TextStyle.ITALIC);
System.out.println(coloredString);
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();
}
}