Package wlog creates simple to use UI structure. The UI is used to simply print to the screen. There a wrappers that will wrap each other to create a good looking UI. You can add color and prefixes as well as make it thread safe.
It is recommended to use
govendor or any vendoring tool allowing you to specify which version of this package you would like to use.
Idea Behind WLog
I used Mitchellh's CLI structure and
wrapping for the different structures. It was a clean look and feel. Plus it
was pretty simple to use. But I didn't want all the other cli stuff that came
with the package so I created this.
For color I use DavidDenGCN's
Go-ColorText. His color package
allows for color that is available cross-platforms. I made a wrapper with all
possible color combinations with his package. So you only have to import this
package (one less line).
var ui UI reader := strings.NewReader("User Input\r\n") //Simulate user typing "User Input" then pressing [enter] when reading from os.Stdin ui = New(reader, os.Stdout, os.Stdout) ui = AddPrefix("?", Cross, " ", "", "", "~", Check, "!", ui) ui = AddConcurrent(ui) ui.Ask("Ask question", "") ui.Error("Error message") ui.Info("Info message") ui.Output("Output message") ui.Running("Running message") ui.Success("Success message") ui.Warn("Warning message")
? Ask question ✗ Error message Info message Output message ~ Running message ✓ Success message ! Warning message
On Windows it outputs to this (this includes color):
On Mac it outputs to this (this includes color):
Subscribe to Golang Example
Get the latest posts delivered right to your inbox