pp

Colored pretty printer for Go language

  • Owner: k0kubun/pp
  • Platform:
  • License:: MIT License
  • Category::
  • Topic:
  • Like:
    0
      Compare:

Github stars Tracking Chart

pp wercker status

Colored pretty printer for Go language

Usage

Just call pp.Print().

import "github.com/k0kubun/pp"

m := map[string]string{"foo": "bar", "hello": "world"}
pp.Print(m)

API

fmt package-like functions are provided.

pp.Print()
pp.Println()
pp.Sprint()
pp.Fprintf()
// ...

You can also create own instances that do not interfer with the default printer

mypp := pp.New()
mypp.SetOutput(os.Stderr)
mypp.Println()
// ...

API doc is available at: http://godoc.org/github.com/k0kubun/pp

Custom colors

If you require, you may change the colors (all or some) for syntax highlighting:

// Create a struct describing your scheme
scheme := pp.ColorScheme{
	Integer:       pp.Green, pp.Bold,
	Float:         pp.Black, pp.BackgroundWhite, pp.Bold,
	String:        pp.Yellow,
}

// Register it for usage
pp.SetColorScheme(scheme)

Look into ColorScheme struct for the field names.

If you would like to revert to the default highlighting, you may do so by calling pp.ResetColorScheme().

Out of the following color flags, you may combine any color with a background color and optionally with the bold parameter. Please note that bold will likely not work on the windows platform.

// Colors
Black
Red
Green
Yellow
Blue
Magenta
Cyan
White

// Background colors
BackgroundBlack
BackgroundRed
BackgroundGreen
BackgroundYellow
BackgroundBlue
BackgroundMagenta
BackgroundCyan
BackgroundWhite

// Other
Bold

// Special
NoColor

Demo

Timeline

UserStream event

Works on windows

License

MIT License

Main metrics

Overview
Name With Ownerk0kubun/pp
Primary LanguageGo
Program languageGo (Language Count: 1)
Platform
License:MIT License
所有者活动
Created At2014-12-01 14:15:31
Pushed At2025-06-01 23:39:32
Last Commit At2025-05-26 06:37:19
Release Count27
Last Release Namev3.4.1 (Posted on )
First Release Namev0.0.1 (Posted on )
用户参与
Stargazers Count1.9k
Watchers Count19
Fork Count105
Commits Count227
Has Issues Enabled
Issues Count0
Issue Open Count0
Pull Requests Count52
Pull Requests Open Count1
Pull Requests Close Count11
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private