Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/k0kubun/pp
Colored pretty printer for Go language
https://github.com/k0kubun/pp
go pretty-printer
Last synced: 3 days ago
JSON representation
Colored pretty printer for Go language
- Host: GitHub
- URL: https://github.com/k0kubun/pp
- Owner: k0kubun
- License: mit
- Created: 2014-12-01T14:15:31.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2024-10-25T16:16:16.000Z (about 2 months ago)
- Last Synced: 2024-10-29T15:01:19.370Z (about 1 month ago)
- Topics: go, pretty-printer
- Language: Go
- Homepage: https://pkg.go.dev/github.com/k0kubun/pp/v3
- Size: 176 KB
- Stars: 1,857
- Watchers: 19
- Forks: 96
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE.txt
Awesome Lists containing this project
- awesome-go - pp - Colored pretty printer for Go language. (Logging / Search and Analytic Databases)
- awesomeLibrary - pp - Colored pretty printer for Go language (语言资源库 / go)
- go-awesome - pp - tool for printing color variables (Open source library / Debugging)
- awesome-go - pp - Colored pretty printer for Go language. Stars:`1.9K`. (Logging / Search and Analytic Databases)
- awesome-hacking-lists - k0kubun/pp - Colored pretty printer for Go language (Go)
README
# pp [![Go](https://github.com/k0kubun/pp/workflows/Go/badge.svg)](https://github.com/k0kubun/pp/actions) [![Go Reference](https://pkg.go.dev/badge/github.com/k0kubun/pp/v3.svg)](https://pkg.go.dev/github.com/k0kubun/pp/v3)
Colored pretty printer for Go language
![](http://i.gyazo.com/d3253ae839913b7239a7229caa4af551.png)
## Usage
Just call `pp.Print()`.
```go
import "github.com/k0kubun/pp/v3"m := map[string]string{"foo": "bar", "hello": "world"}
pp.Print(m)
```![](http://i.gyazo.com/0d08376ed2656257627f79626d5e0cde.png)
### API
fmt package-like functions are provided.
```go
pp.Print()
pp.Println()
pp.Sprint()
pp.Fprintf()
```See [the documentation](https://pkg.go.dev/github.com/k0kubun/pp/v3#section-documentation) for API details.
### Configuration
They can be customized globally with `pp.Default`.
```go
pp.Default.SetColoringEnabled(false)
pp.Println() // no color
```You can also create individual instances that do not interfere with the default printer:
```go
mypp := pp.New()
mypp.SetColoringEnabled(false)
mypp.SetExportedOnly(true)
mypp.SetOmitEmpty(true)
mypp.Println()
```See [PrettyPrinter documentation](https://pkg.go.dev/github.com/k0kubun/pp/v3#PrettyPrinter) for all available configurations.
### Custom colors
If you require, you may change the colors (all or some) for syntax highlighting:
```go
// 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.Default.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.
```go
// 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
![](http://i.gyazo.com/a8adaeec965db943486e35083cf707f2.png)
### UserStream event
![](http://i.gyazo.com/1e88915b3a6a9129f69fb5d961c4f079.png)
### Works on windows
![](http://i.gyazo.com/ab791997a980f1ab3ee2a01586efdce6.png)
## License
MIT License