Skip to main content

GO lang to print colored output

package main

import (
	"fmt"
)

func Red(format string, args ...interface{}) {
	fmt.Printf("\033[31m"+format+"\033[0m", args...)
}

func Green(format string, args ...interface{}) {
	fmt.Printf("\033[32m"+format+"\033[0m", args...)
}

func Yellow(format string, args ...interface{}) {
	fmt.Printf("\033[33m"+format+"\033[0m", args...)
}

func Blue(format string, args ...interface{}) {
	fmt.Printf("\033[34m"+format+"\033[0m", args...)
}

func Magenta(format string, args ...interface{}) {
	fmt.Printf("\033[35m"+format+"\033[0m", args...)
}

func Cyan(format string, args ...interface{}) {
	fmt.Printf("\033[36m"+format+"\033[0m", args...)
}

func main() {
	// Set the foreground color to red
	Red("Hello, world!\n")
	Yellow("Hello, world!\n")
	Green("Hello, world!\n")
	Magenta("Hello, world!\n")
	Cyan("Hello, world!\n")
	Blue("Hello, world!\n")

}


<
Previous Post
Installing golang compiler in linux machine
>
Blog Archive
Archive of all previous blog posts

Comments

Popular posts from this blog

Profiling CPU Usage in Go: Boosting Performance

Creating Custom Error Types in Go

Enhancing Database Security and Performance with Parameterized Queries