GoStyle is a Go-To library for styling text output in terminals. It provides functions for coloring text, applying styles, adding text effects, and printing formatted log messages
To install GoStyle, use go get
:
go get "github.com/yourpwnguy/gostyle"
Following styles are supported
Following colors are supported
Following labels are supported
Firstly, Import the library and Instantiate it as follows
package main
import (
"github.com/yourpwnguy/gostyle"
)
func main() {
g := gostyle.New()
}
Printing colored text as follows
fmt.Println(g.Red("This is Red Text!"))
You can also apply styles:
fmt.Println(g.Italic("This string is in italic"))
Combining styles and colors:
fmt.Println(g.Bold(g.Red("This string is bold and red")))
Labels are useful for printing minimal output schemas for different types of messages:
fmt.Println(g.LogGood("Good"))
fmt.Println(g.LogBad("Bad"))
fmt.Println(g.LogInfo("Informational"))
fmt.Println(g.LogRun("Processing"))
fmt.Println(g.LogQue("Question"))
Normal Colors:
Black, Red, Green, Yellow, Blue, Magenta, Cyan, Gray, White
Bright Colors:
BrBlack, BrRed, BrGreen, BrYellow, BrBlue, BrMagenta, BrCyan, BrGray
Bold, BGround, Underline, Strike, Italic
LogInfo, LogQue, LogRun, LogBad, LogGood
Blink, Reverse, Hidden
Note: Some terminals don't support special effects and Windows versions below windows 10 do not support ANSI escape sequences so the colors will not be printed in command prompt.
When comparing GoStyle with the fatih/color library, GoStyle offers a more straightforward and intuitive API for text styling. While fatih/color provides a robust set of functionalities for colorizing text, it requires a more complex approach for applying styles like bold.
package main
import (
"github.com/fatih/color"
)
func main() {
red := color.New(color.FgRed).Add(color.Bold)
red.Println("This string is bold and red")
}
package main
import (
"github.com/yourpwnguy/gostyle"
)
func main() {
g := gostyle.New()
fmt.Println(g.Bold(g.Red("This string is red")))
}
- Provides a cleaner and more user-friendly interface for applying various text styles.
- Users can easily chain multiple styles together, making it simpler to create richly formatted text output.
- Offers a wider range of supported styles, including italic, underline, strike-through, and more, providing greater flexibility for customizing text appearance.
I mean Why Not? It is simple, fast and awesome at the same time !!!
-
Simplicity First: GoStyle keeps thing simple. With a clean and intuitive API, it's easy to style text without wrestling with complex configurations.
-
Flexibility Matters: Whether you want bold, italic, or striking text, GoStyle has you covered. Mix and match styles effortlessly to create the perfect look.
-
Easy to Learn: New to Go? No problem. GoStyle's straightforward interface makes it a breeze for beginners to start styling text right away.
-
Rich Styling Options: From colors to styles to effects, GoStyle offers a wide range of customization options to make your text stand out.
We believe that GoStyle has immense potential, and your contributions can help make it even better. Whether you're fixing bug, adding new features, or improving documentation, your efforts are highly valued.
If you think GoStyle could benefit from additional colors, styles, or effects, don't hesitate to start a pull request. Together, we can continue to enhance GoStyle and make it the go-to choice for text styling in Go applications.
For more information about the library, please refer to Documentation.