Skip to content

shuoros/JTerminal

Repository files navigation

JTerminal

JTerminal

Is an easy to use library for printing custom outouts on terminal!

code factor Contributors License

If you like this project, help me by giving me a star =))<3

What is in V1.0.2

  • Print and println with foreground and background color.
  • Support 8-bit 0-255 XTerm colors.
  • Get colors by name and theire XTerm code.
  • TextEntity class for assign different styles to a single string.
  • Pass your TextEntity list with no order and full coverage (v1.0.2)
  • clear the terminal.
  • delete lines.

Hello Terminal

To use JTerminal you just need to make a static call to your desired API.

For example:

ezgif com-gif-maker

The above gif was the result of running this piece of code:

import java.util.List;

import io.github.shuoros.jterminal.JTerminal;
import io.github.shuoros.jterminal.ansi.Color;
import io.github.shuoros.jterminal.util.TextEntity;

public class Main {

	public static void main(String[] args) {
		// Clear screen with timer
		JTerminal.println("Screen must clear after one second");
		JTerminal.clear(1000);

		// Delete line
		JTerminal.println("The line below must be deleted after one second");
		JTerminal.println("I should be deleted in a second");
		try {
			Thread.sleep(1000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		JTerminal.delete();
		JTerminal.clear(1000);
		
		// Print with default foreground and background colors
		JTerminal.println("Hello I'm in your terminal's default foreground and background color");
		JTerminal.println("\n");

		// Print with foreground or background color
		JTerminal.println("I'm an orange text with default background", Color.ORANGE);
		JTerminal.println("I'm an orange text with white background", Color.ORANGE, Color.WHITE);
		JTerminal.println("\n");

		// Use custom XTerm code
		JTerminal.println("I'm printed with 201 XTerm code", Color.xTerm(201));
		JTerminal.println("\n");

		// Print with TextEntity
		JTerminal.println("My colors were set with TextEntity", List.of(//
				new TextEntity(0, 24, Color.BLUE), //
				new TextEntity(24, 33, Color.YELLOW, Color.RED)));
		JTerminal.println("\n");

		// All suppoerted XTerm colors (8-bit 0-255)
		JTerminal.println("All suppoerted XTerm colors (8-bit 0-255) ->", List.of(//
				new TextEntity(0, 27, Color.WHITE), //
				new TextEntity(27, 42, Color.RED), //
				new TextEntity(42, 44, Color.WHITE, Color.ORANGE)));
		JTerminal.println("");
		for (Color color : Color.values()) {
			JTerminal.print(color.toString(), color);
			JTerminal.print(" ");
		}
		JTerminal.println("\n");

		// Credits
		JTerminal.println(">JTerminal:~ 1.0.0", List.of(//
				new TextEntity(0, 1, Color.DARK_SEA_GREEN_7), //
				new TextEntity(1, 10, Color.ORANGE), //
				new TextEntity(10, 12, Color.DARK_SEA_GREEN_7), //
				new TextEntity(12, 18, Color.WHITE)));
		JTerminal.println("By Soroush Shemshadi", Color.ORANGE);
	}

}

To see color cheat sheet please check docs.

Installation

You can use JTerminal with any project management tool:

Maven

<!-- https://mvnrepository.com/artifact/io.github.shuoros/JTerminal -->
<dependency>
    <groupId>io.github.shuoros</groupId>
    <artifactId>JTerminal</artifactId>
    <version>1.0.2</version>
</dependency>

Gradle

// https://mvnrepository.com/artifact/io.github.shuoros/JTerminal
implementation group: 'io.github.shuoros', name: 'JTerminal', version: '1.0.2'

Or

// https://mvnrepository.com/artifact/io.github.shuoros/JTerminal
implementation 'io.github.shuoros:JTerminal:1.0.2'

And in Kotlin

// https://mvnrepository.com/artifact/io.github.shuoros/JTerminal
implementation("io.github.shuoros:JTerminal:1.0.2")

SBT

// https://mvnrepository.com/artifact/io.github.shuoros/JTerminal
libraryDependencies += "io.github.shuoros" % "JTerminal" % "1.0.2"

Ivy

<!-- https://mvnrepository.com/artifact/io.github.shuoros/JTerminal -->
<dependency org="io.github.shuoros" name="JTerminal" rev="1.0.2"/>

Grape

// https://mvnrepository.com/artifact/io.github.shuoros/JTerminal
@Grapes(
    @Grab(group='io.github.shuoros', module='JTerminal', version='1.0.2')
)

Leiningen

;; https://mvnrepository.com/artifact/io.github.shuoros/JTerminal
[io.github.shuoros/JTerminal "1.0.2"]

Authors

JTerminal is developed by Soroush Shemshadi and contributors.

Contribution

If you want to contribute on this project, Please read the contribution guide.

Releases

To see the changes in different versions of JTerminal, you can read the release notes.

Issues

If you encounter a bug or vulnerability, please read the issue policy.

Documentation

To learn how to work with JTerminal, please take a look at the /doc folder.

Acknowledgement

A greate thanks to @sarahrajabi for designing the logo.