• Stars
    star
    429
  • Rank 101,271 (Top 2 %)
  • Language
    Go
  • License
    MIT License
  • Created over 10 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Intuitive package for prettifying terminal/console output. http://godoc.org/github.com/ttacon/chalk

chalk

Chalk is a go package for styling console/terminal output.

Check out godoc for some example usage: http://godoc.org/github.com/ttacon/chalk

The api is pretty clean, there are default Colors and TextStyles which can be mixed to create more intense Styles. Styles and Colors can be printed in normal strings (i.e. fmt.Sprintf(chalk.Red)), but Styles, Colors and TextStyles are more meant to be used to style specific text segments (i.e. fmt.Println(chalk.Red.Color("this is red")) or fmt.Println(myStyle.Style("this is blue text that is underlined"))).

Examples

There are a few examples in the examples directory if you want to see a very simplified version of what you can do with chalk.

The following code:

package main

import (
	"fmt"

	"github.com/ttacon/chalk"
)

func main() {
	// You can just use colors
	fmt.Println(chalk.Red, "Writing in colors", chalk.Cyan, "is so much fun", chalk.Reset)
	fmt.Println(chalk.Magenta.Color("You can use colors to color specific phrases"))

	// You can just use text styles
	fmt.Println(chalk.Bold.TextStyle("We can have bold text"))
	fmt.Println(chalk.Underline.TextStyle("We can have underlined text"))
	fmt.Println(chalk.Bold, "But text styles don't work quite like colors :(")

	// Or you can use styles
	blueOnWhite := chalk.Blue.NewStyle().WithBackground(chalk.White)
	fmt.Printf("%s%s%s\n", blueOnWhite, "And they also have backgrounds!", chalk.Reset)
	fmt.Println(
		blueOnWhite.Style("You can style strings the same way you can color them!"))
	fmt.Println(
		blueOnWhite.WithTextStyle(chalk.Bold).
			Style("You can mix text styles with colors, too!"))

	// You can also easily make styling functions thanks to go's functional side
	lime := chalk.Green.NewStyle().
		WithBackground(chalk.Black).
		WithTextStyle(chalk.Bold).
		Style
	fmt.Println(lime("look at this cool lime text!"))
}

Outputs screenshot

WARNING

This package should be pretty stable (I don't forsee backwards incompatible changes), but I'm not making any promises :)

More Repositories

1

libphonenumber

golang port of Google's libphonenumber
Go
616
star
2

box

golang API for box
Go
17
star
3

emoji

emoji for golang
Go
10
star
4

go-utils

a collection of utilities that I find usefull
Go
8
star
5

glorious

Go
7
star
6

uri

RFC 3986 compliant uri builder/parser
Go
5
star
7

mixmax-api

Cheeky wrapper around the Mixmax API
JavaScript
4
star
8

tesseract

an pure Go implementation of tesseract
C++
4
star
9

rpp

Go
3
star
10

builder

what it says
Go
3
star
11

combee

testing shell for bee-queue
JavaScript
3
star
12

godef

Fork from code.google.com/p/rog-go/exp/cmd/godef
Go
3
star
13

simplehttpserver

An idiomatic go version of "python -m SimpleHTTPServer", also less verbose to type
Go
2
star
14

jiraquery

Go
2
star
15

pouch

ORMs done fun
Go
2
star
16

awesome-virtual-conferences

2
star
17

toml2cli

Because writing CLI boilerplate is boring
Go
2
star
18

whodo

a tool for seeing who has left what todos in your go code
Go
2
star
19

sentry-assign

Simple service for auto-assigning users to projects in Sentry
Go
2
star
20

gobi

Go
2
star
21

spf-tree

Shows the SPF lookups for a mail host as a tree
Go
2
star
22

synchronize-fiber-count

counting fibers
JavaScript
2
star
23

autumn

Because setting up a new service should be easy.
Go
1
star
24

twine

Go
1
star
25

qatch

Slow query catcher
JavaScript
1
star
26

dote

Go
1
star
27

synthd

TypeScript
1
star
28

scrap-yard

Collection of tools and code thrown together to answer questions
Go
1
star
29

requests

Easy request building library
Go
1
star
30

gemini

Go
1
star
31

instagram

golang client for instagram
Go
1
star
32

minfo

Go
1
star
33

fs

Go
1
star
34

gile

Simple jQuery plugin for creating custom styled form file elements with CSS.
JavaScript
1
star
35

terraform-sentry-project

An opinionated take on how to structure Sentry projects in terraform
Go
1
star
36

pipes

utility package for piping shell commands
Go
1
star
37

sqlgen

yolo...
1
star
38

horhur

Go
1
star
39

beautiful-goop

beautiful soup for go
Go
1
star
40

stash

go stash client
Go
1
star
41

synthd-bin

synthd CLI utility
TypeScript
1
star
42

gofourit

Ensure singleton execution of cron jobs across a distributed system.
Go
1
star
43

terraform-malicious-null-resource

HCL
1
star