java - Print colored text in consoles (Windows, Mac, Linux) -
i know question asked before, have other questions, too. so, if use system.err in eclipse, text red. if outside in eclise windows command prompt, has same color. question, there way print colored text in each of these consoles?
i tried following line:
system.out.println((char)27 + "[34;43mblue text yellow background");
i've tried windows 10, didn't work.
i've tried linux ubuntu, did work, don't no if works linux variations.
i have no mac, unfortunately can't try it, if can try it, nice. (i don't if mac has command prompt, thank can tell me more)
if it's possible, make without library, if easier or without library really hard, it's ok. (and if it's library happy if tell me must if want publish program contains library).
thanks, abilnf
there java library jansi achieve in windows rendering ansi escape sequences.
here how can use it
import org.fusesource.jansi.ansiconsole; import static org.fusesource.jansi.ansi.*; import static org.fusesource.jansi.ansi.color.*; public class sample { public static void main(string[] args) { ansiconsole.systeminstall(); system.out.println(ansi().fg(red).a("hello world").reset()); // colored system.out.println("this uncolored"); ansiconsole.systemuninstall(); } }
Comments
Post a Comment