Skip to content

apriendeau/crayons

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

crayons

GoDoc Build Status Coverage MIT License

There are alot of ANSI color libraries but none of them were useful for larger implementations. It is heavily modeled after fatih/color but exposes things slightly differently and adds a concept of grouping different styles.

This is very conceptual right now and in alpha so note, there might be some changes and is not stable just yet and is totally just a POC repo for me at this point.

Installing

go get github.com/apriendeau/crayons

Basic Usage

package main

import(
	"fmt"
	"github.com/apriendeau/crayons"
)

func main() {
	c := crayons.New(crayons.FgBrightCyan, crayons.BgBlack)

	c.Println("blizzard blue")

	str := c.Sprintf("blizzard %s", "blue")
	fmt.Println(str)
}

Boxes for Branding

Who wants just one crayon? I want a whole freaking box!

So as I was building a CLI tool, I always had to write another package just to have to use for styles for certain things such as errors, headers and just regular text. I found this annoying. As developer, we tend to forget about branding and UX so I wanted a way to define a style that would be constantly used throughout my CLI.

The value is consistency.

package main

import(
	"fmt"
	"log"

	"github.com/apriendeau/crayons"
)

func main() {
	redCrayon := crayons.New(crayons.FgBrightRed)
	greenCrayon := crayons.New(crayons.FgBrightGreen)

	box := crayons.NewBox(nil) // nil will default to the defaultFg, defaultBg
	err := box.Store("error", redCrayon)
	if err != nil {
		redCrayon.Fatal(err)
	}
	err = box.Store("success", greenCrayon)
	if err != nil {
		redCrayon.Fatal(err)
	}

	c := box.Pick("success")
	c.Println("Yay, I worked this time")

	c = box.Pick("error")
	c.Println("There was an error! Oh snap!")
	os.Exit(1)
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages