Skip to content

Instantly share code, notes, and snippets.

@sleungcy
Forked from crevier/colorInConsole.groovy
Created February 16, 2019 01:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sleungcy/6fa47da1e0dc5a71e424aa5b93988550 to your computer and use it in GitHub Desktop.
Save sleungcy/6fa47da1e0dc5a71e424aa5b93988550 to your computer and use it in GitHub Desktop.
How to print color in console in groovy
def fg = 30
def bg = 46
def style = "${(char)27}[$fg;$bg"+"m"
println(style+"HELLO")
/*
+~~~~~~+~~~~~~+~~~~~~~~~~~+
| fg | bg | color |
+~~~~~~+~~~~~~+~~~~~~~~~~~+
| 30 | 40 | black |
| 31 | 41 | red |
| 32 | 42 | green |
| 33 | 43 | yellow |
| 34 | 44 | blue |
| 35 | 45 | magenta |
| 36 | 46 | cyan |
| 37 | 47 | white |
| 39 | 49 | default |
+~~~~~~+~~~~~~+~~~~~~~~~~~+
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment