- Demo
- Formatter
- Simple Formatter
- Colorizing the CLI Text
- 256 Color Support
- RGB Colors
- Formatter Examples
- Colorizing Examples
- Contributing
- License
To run the Demo, make sure you have Java and Maven installed.
Then, open a terminal and type these commands:
git clone https://github.com/0l1v3rr/jfmt.git
cd jfmt
bash demo.sh
The Formatter.stringf()
method is a function, which provides you the ability to format strings more easily.
It supports Entities, Symbols, and Format Characters.
Click here to expand
&n
: Line break
&N
: Double line break
&t
: Current time in a default format
&d
: Current date in a default format
$c
: Copyright (ยฉ)
$r
: Registered trademark (ยฎ)
$e
: Element of (โ)
$p
: N-ary product (โ)
$s
: N-ary summation (โ)
$x
: Plus-or-minus sign (ยฑ)
$2
: Superscript two (ยฒ)
$3
: Superscript three (ยณ)
$tm
: Trademark (โข)
$Ua
: Upwards Arrow (โ)
$Da
: Downwards Arrow (โ)
$La
: Leftwards Arrow (โ)
$Ra
: Rightwards Arrow (โ)
Click here to expand
%v
: Value in the default (.toString()
) format
%s
: String in a default format
%S
: String in uppercase
%q
: String in a double quote format. ("text")
%b
: Boolean (true/false)
%B
: Boolean in uppercase
%d
: A round number (if you provide a float or a double, it'll split off everything after the '.')
%o
: Number in binary - You must provide it in decimal
%i
: Number in decimal - You must provide it in binary
%f
: A float or a double number
%f<n>:
A float or a double number rounded to n decimal places. (E.g.: %f3
)
%r
: String in a reversed format
%R
: String in a reversed & uppercase format
%t
: java.util.Date format - default is "yyyy-MM-dd"
Note: Assign the appropriate type of variable to the characters, otherwise, it will not be formatted.
For example:
String result = Formatter.stringf("This is a boolean: %b", "true");
//Result:
//This is a boolean: %b
//Because the passed value is not a boolean but a string.
//To make it work, you want to use it like this:
String result = Formatter.stringf("This is a boolean: %b", true);
Formatter.setDateFormat("dd-MM-yyyy");
Formatter.setTimeFormat("hh:mm:ss");
Formatter.stringf("Hi %s! Date: &d, Time: &t", "John");
// Result: "Hi John! Date: 03-12-2021, Time: 10:04:43" (ofc with the current date and time)
The SimpleFormatter
's stringf()
method is easier to use, and it's faster than the Formatter.stringf()
, but it knows less.
It does not support entities and characters.
If you want to use this method, you pass the arguments like this: "{0}, {1}"
The 0th argument is the first argument, you pass.
You can use it multiple times.
Example:
String result = SimpleFormatter.stringf("{0} is {1} years old.", "John", 17);
// Result:
// John is 17 years old.
See more examples here
// Method 1: Custom Colored Output
CustomColorFormat ccf = new CustomColorFormat(TColor.BLACK, BgColor.BRIGHT_RED, TDecoration.UNDERLINE);
ccf.println("This is a black underline text with bright red background.");
// Method 2: Simple Formatting
System.out.println(BackgroundColor.red("This is a text with red background."));
System.out.println(BackgroundColor.red(TextColor.yellow("This is a yellow text with red background.")));
// Method 3: Colorize.colorf() function
System.out.println(Colorize.colorf("{t:yellow}This is a yellow text."));
System.out.println(Colorize.colorf("{t:bgreen}This is a green text. {reset}This is a text in default format."));
System.out.println(Colorize.colorf("{bg:bred}This is a text with bright red background."));
// Method 4: Colorize.string() function
System.out.println(Colorize.string("This is a red text.", TColor.RED));
System.out.println(Colorize.string("This is a red text with black background.", TColor.RED, BgColor.BLACK));
System.out.println(Colorize.string("This is a red, underline text with black background.", TColor.RED, BgColor.BLACK, TDecoration.UNDERLINE));
See more examples here
// In the constructor, you must provide a number between 0 and 255.
Color256 t = new Text256(200);
t.println("Text");
// Output: Text
// With the ANSI color code of 200
// You can modify the code like this:
t.setCode(201);
t.println("Text2");
// Output: Text2
// With the ANSI color code of 201
// You can use it as background as well:
Color256 t = new Background256(1);
t.println("Text");
// Output: Text
// With the background of code 1
// Random color:
t.random("This is a random colored text.");
// Example:
Color256 t = new Text256(0);
for(int i = 0; i < 256; i++) {
t.print(i+" ");
t.setCode(i);
}
// RGB text
RgbColor rgb = new RgbText(255, 0, 0);
rgb.println("Text");
// Rainbow text:
RgbText.rainbow("Text");
// Random RGB text:
RgbText.random("Text");
// RGB background
RgbColor rgb = new RgbBackground(255, 0, 0);
rgb.println("Text");
If you want to contribute to this project:
- Star this repository
- Open an Issue. There are some Issue Templates available.
- Open a Pull Request, where describe what you did and why.
Thanks for contributing! (:
This library is licensed under the terms of the MIT License