Skip to content

An object to smoothly use color codes on the Terminal

Notifications You must be signed in to change notification settings

nimbus321/TerminalColorCodes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 

Repository files navigation

Terminal Color Codes (NodeJS)

An object to smoothly use color codes on the Terminal, just use the color codes like this:

console.log( C["&a"] + C["&l"] + "Lorem ipsum dolor sit amet" + C["&r"] )
// Will appear green and bold on the Terminal

Output: Example

  • C["&a"] means Green
  • C["&l"] means Bold
  • C["&r"] is to reset all previous style

More complicated example:

console.log( C["&c"] + C["&l"] + "Danger! " + C["&r"] + C["&e"] + C["&n"] + "Don't do that!" + C["&r"] + " " +C["&bg"] + C["&b"] + " Be careful "+ C["&r"] )

Example

How To Use

The C object in the JavaScript code provides an easy way to print text with different colors in the terminal without having to remember the corresponding ANSI codes. The object contains several properties, each of which is associated with a specific color or style code that can be used to format text in the terminal.

There are 2 types of codes; color and format. You can combine color with formats, for example, Green with Bold (example above). To use them, just put the code like this C["CODE"]

The "Codes" are just properties of the object C, on with there is the respective ANSI code that the terminal will interpret.

Here are the Color Codes: (For each color, there is a brighter and darker color)

colors

Allways remember to reset any style at the end of the line by using the reset code, C["&r"]

CheatSheet

Colors

Tag, o Key JavaScript Result
&0 C["&0"] &0
&1 C["&1"] &1
&2 C["&2"] &2
&3 C["&3"] &3
&4 C["&4"] &4
&5 C["&5"] &5
&6 C["&6"] &6
&7 C["&7"] &7
&8 C["&8"] &8
&9 C["&9"] &9
&a C["&a"] &a
&b C["&b"] &b
&c C["&c"] &c
&d C["&d"] &d
&e C["&e"] &e
&f C["&f"] &f

Formats

Tag, o Key JavaScript Result Notes
&r or reset C["&r"] reset Resets all previews formats and color
&n, &u, &sub or underscore C["&n"] underscore
&o, &i or italic C["&o"] italic
&m, &s, &str or strikethrough C["&m"] strikethrough
&l or bold C["&l"] bold
&h or hidden C["&h"] &h The text can still be copied, and is rendered but invisible.
&bg or background C["&bg"] background The color of the background can change if you specify it after the &bg code, examples below
Examples of background with color:
&bg with &a C["&bg"] + C["&a"] background2
&bg with &e C["&bg"] + C["&e"] background3
&bg with &c C["&bg"] + C["&c"] background4

FAQ

Okey, but WHY?

Because its great to use color on the terminal, if it's not for you just don't use it. :)

Where does it work?

The main place is the terminal, and that's why I made this. But it also works on the javascript dev's console! I don't recommend it tho, there are better ways to manipulate the style and color there, here are some links: Link 1, Link 2.

Why that strange naming of the color codes?

Because I pretty much took the colors from Minecraft's color codes and made them into ANSI codes. Also, on there, the way of using them is to put a & before the code, so that's why I made it this way. I already knew the color and their code so it was really easy for me to make it this way.

About

An object to smoothly use color codes on the Terminal

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages