Skip to content

Using ANSI color in java programming language and changing the terminal forecolor and background color.

License

Notifications You must be signed in to change notification settings

iMohsen02/AnsiColorInJavaProjectTemplate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ANSI Color

ANSI escape code

base on wikipedia:

ANSI escape sequences are a standard for in-band signaling to control cursor location, color, font styling, and other options on video text terminals and terminal emulators. Certain sequences of bytes, most starting with an ASCII escape character and a bracket character, are embedded into text. The terminal interprets these sequences as commands, rather than text to display verbatim.

ANSI sequences were introduced in the 1970s to replace vendor-specific sequences and became widespread in the computer equipment market by the early 1980s. They are used in development, scientific, commercial text-based applications as well as bulletin board systems to offer standardized functionality.

Although hardware text terminals have become increasingly rare in the 21st century, the relevance of the ANSI standard persists because a great majority of terminal emulators and command consoles interpret at least a portion of the ANSI standard.

how to change the terminal color using java project?

Ansi colors help programmers in this problem to easily change the color of the terminal.

Ansi color table

easily use this format in any programming language to change the color of the terminal(point that colors should be printed to affect):

\033[(color number from the above table)m

for example in java:

System.out.println("\033[91mThis text will be RED\033[0m");
// change the color to red and then after print the text reset the color format

also you can use 8-bit color: Ansi color table
easily use 8-bit color format in any programming language to change the color of the terminal(point that colors should be printed to affect):

\u001b[38;5;(number from the above table)m // select the foreground color
\u001b[48;5;(number from the above table)m // select the background color

for example in java:

System.out.println("\u001b[38;5;32m This text will be BLUE\u001b[0m");
// change the color to blue and then after print the text reset the color format

and you can use RGB coloring model:

colorcube
you can easily generate too many color by using RGB coloring model:

\033[38;2;R;G;Bm // select the foreground color
\033[38;2;R;G;Bm // select the background color

for example in java:

System.out.println("\033[38;2;255;215;0m This text will be GOLD\033[0m");

Creative Process & Process Line

Some creative functions that show the process are built based on Ansi colors in the AnsiColor.java to bring beauty to your command line programs.

For example, process line functions have been tested in Main.java, which can be used in three different modes (process using percentage, process using percentage and text, process line using text).

In every type of showing process you are able to set the sleep time per percentage

pat attention that After the process, the printed line will be deleted

doc_2023-01-28_21-00-14.mp4

Enjoy it :)

About

Using ANSI color in java programming language and changing the terminal forecolor and background color.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages