printf in color

10,057 views
Skip to first unread message

Constantine Vasil

unread,
Feb 1, 2013, 6:02:04 PM2/1/13
to golan...@googlegroups.com
I am printing a lot lines in command line during testing.
Visualizing using a color would be great.

Are there a way to send color related commands to the terminal using printf?

bryanturley

unread,
Feb 1, 2013, 6:06:17 PM2/1/13
to golan...@googlegroups.com

Constantine Vasil

unread,
Feb 1, 2013, 6:10:50 PM2/1/13
to golan...@googlegroups.com
I am using Ubuntu - how you will code it in fmt.Printf?

Constantine Vasil

unread,
Feb 1, 2013, 6:12:13 PM2/1/13
to golan...@googlegroups.com
GNOME Terminal - 3.4.1.1 - A terminal emulator for the GNOME desktop

speter

unread,
Feb 1, 2013, 6:17:40 PM2/1/13
to Constantine Vasil, golang-nuts
fmt.Println("\x1b[31;1mHello, World!\x1b[0m")



--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Constantine Vasil

unread,
Feb 1, 2013, 6:45:27 PM2/1/13
to golan...@googlegroups.com, Constantine Vasil

Here is the code I got:


        const CLR_0 = "\x1b[30;1m"

const CLR_R = "\x1b[31;1m"

const CLR_G = "\x1b[32;1m"

const CLR_Y = "\x1b[33;1m"

const CLR_B = "\x1b[34;1m"

const CLR_M = "\x1b[35;1m"

const CLR_C = "\x1b[36;1m"

const CLR_W = "\x1b[37;1m"

const CLR_N = "\x1b[0m"

fmt.Printf("%s%s%s\t%s%s%s\t%s%s%s\t%s%s%s\t%s%s%s\n",

CLR_G, sl1[0], CLR_N,

CLR_Y, sl1[1], CLR_N,

CLR_B, sl1[2], CLR_N,

CLR_W, sl1[3], CLR_N,

CLR_M, sl1[4], CLR_N,

David DENG

unread,
Feb 2, 2013, 3:01:42 AM2/2/13
to golan...@googlegroups.com

Константин Иванов

unread,
Nov 6, 2016, 10:07:37 PM11/6/16
to golang-nuts
Hello. I wrote the library that allows to use ANSI-colors (unix and win10+).
It allows to use colored printf such as

fmt.Priintf("neutral, red %d, cyan %d, bold %s", Red(35), Cyan(100), Bold("bold"))

Check it out https://github.com/logrusorgru/aurora

The library doesn't support Windows. But Windows 10 since some build
supports ANSI-colors and the library work on it.

суббота, 2 февраля 2013 г., 3:02:04 UTC+4 пользователь Constantine Vassilev написал:

gary.wi...@victoriaplumb.com

unread,
Nov 7, 2016, 3:54:50 AM11/7/16
to golang-nuts

Anmol Sethi

unread,
Nov 7, 2016, 4:15:22 AM11/7/16
to Константин Иванов, golang-nuts
I wrote a similar library once https://github.com/nhooyr/color
But I like your approach better because you can just use fmt.Printf

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages