Bitburner

Bitburner

35 ratings
Using Colors to print
By Balatro Balatrez Skibidi
Did you know you can use colors to print output?
2
   
Award
Favorite
Favorited
Unfavorite
Code:
You only need to use the available keywords at the start of the print command for it to change color.
Known:
Keyword
Color
INFO
blue
WARN
yellow
WARNING
yellow
ERROR
red

Here is a simple code to output the available colors and see them in the terminal:

/** @param {NS} ns **/ export async function main(ns) { ns.tprintf('INFO---available log colors:') ns.tprintf('INFOthey only need to be at the start') ns.tprintf(`otherwise INFO or others won't work`) ns.tprintf('WARN this is a warning') ns.tprintf('WARNING this is also warning') ns.tprintf('ERROR this is an error') }
This will output in terminal:

Feel free to comment with anything else you know.
3 Comments
HiEv 9 Jun, 2023 @ 10:23pm 
You can actually get whatever RGB color you want by using "\u001b[38;2;RED;GRN;BLUm" where, "RED", "GRN", and "BLU" are replaced with numbers 0 to 255 for the red, green, and blue colors, respectively. You can also set the RGB color for the background behind the text using "\u001b[48;2;RED;GRN;BLUm" using the same numbering scheme.

Look up "ANSI escape codes" for more, but be aware that not all of them are supported in BitBurner.
TheWookieWaves 25 Jul, 2022 @ 5:57pm 
yes. The first programs I wrote on my Atari 1200XL were basically screensavers. Back in the stone age...
WhiskeyFur 25 Dec, 2021 @ 3:17pm 
INFO, WARNING, ERROR are actually functions of the standard TPRINT function. TPRINTF only formats a string and then passes it into TPRINT.

I really wish this color formatting was a second arg of tprint instead if you wanted something aside from green.