Colored pretty printer for Go language

Overview

pp Go Go Reference

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 interfere with the default printer:

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

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

Comments
  • Option to print byte as decimal

    Option to print byte as decimal

    When print the byte slice, pp print as hex, quite hard to see.

    E.g:

    pp.Println("65:", []byte{65})
    

    will print:

    print:
    "65:" []uint8{
      0x41,
    }
    

    Expected something like:

    "65:" []uint8{
      65,
    }
    

    Is this possible and useful?

    opened by taynguyen 10
  • Please provide a simple way to disable color

    Please provide a simple way to disable color

    It would be nice to have a simple way to disable all color (e.g., a function call, or option for New(). The standard way is working fine, though; it's just a nuisance.

    opened by jlearman 9
  • Add support for customized colors

    Add support for customized colors

    Support for customized colors including the ability to mix font and background colors by using a Flag-based description of the colors.

    Any questions, thoughts or feedback? :)

    opened by JanBerktold 8
  • disable colors when not output is not a tty

    disable colors when not output is not a tty

    Colors are great and make the output very readable, however it's a pain when trying to output to a file

    go-isatty[1] seems like it would be a good addition to this project to solve this

    [1] https://github.com/mattn/go-isatty

    opened by mtourne 6
  • escape sequences to pipe

    escape sequences to pipe

    pp write escape sequences into output stream. when the output is not a terminal, i wonder how pp should do work.

    • remove escape sequences?
    • same as terminal?

    I'm thinking pp SHOULD NOT have behavior against whether stdout is terminal or not. So, I want to you to provide A WAY to remove escape sequence for pp, but formatting is enabled.

    How do you think?

    opened by mattn 6
  • Feature request: Pretty print big.Int and big.Float?

    Feature request: Pretty print big.Int and big.Float?

    cause stuff like

    &big.Int{
                  neg: false,
                  abs: big.nat{
                    0x908f8474ea971baf,
                  },
    }
    

    does look too messy to be honest. Also, some default cool things like http response, rsa keys, etc. could be looking more cool (only most popular, much of default types should be printed explicitly)

    opened by quenbyako 5
  • Sort map by key before printing

    Sort map by key before printing

    I wish there is an option / set of methods that will print maps with keys sorted in a best-effort manner. This can be extremely helpful in diffing outputs across runs.

    (As you likely know, spew has a SortKeys global config that achieves exactly this.)

    Thank you for your consideration.

    opened by maverickwoo 5
  • SetThousandsSeparator

    SetThousandsSeparator

    Experimenting with a fix #53

    golfing.org/x/text/message provides a drop in replacement for fmt that can close #53. It seems to be a super clean way of taking care of this and perhaps supporting other localization in the future.

    The catch? You get default behavior with %#v, but you do get localization with %d, %f, %v, and possibly others. I'm wondering if this could be an acceptable implementation. We could add an option to set the language, and potentially use alternatives to %#v as needed similar to what was done in #55.

    Does this seem like a reasonable way to go?

    opened by mariusgrigoriu 4
  • Option for thousands separator

    Option for thousands separator

    It seems like it would be a good idea to have an option for a thousands separator for floats and ints, which can make structs with many large numbers easier to read. For example:

    myStruct{
      myfloat: 1,000,000.00,
    }
    

    What do you think?

    opened by mariusgrigoriu 4
  • Add max depth var

    Add max depth var

    Hey,

    I am using this to print out deep structures, to filter out some unnecessary structs.

    Just sending maybe you would like to merge it. I have not added tests as I am not sure if this is something you would like to merge.

    Thanks,

    opened by sumerc 4
  • added Debug and Debugf and Debugln for easy debugging.

    added Debug and Debugf and Debugln for easy debugging.

    In some case, I'd like to switch on/off to pp's output without changing code.

    Golang force me to remove import statement, and unused variables. It's hard for casual use.

    opened by walf443 4
Releases(v3.2.0)
  • v3.2.0(Oct 16, 2022)

    Changes

    • Expose the default printer as pp.Default
      • You can call it to use newer configuration API globally

    Example:

    pp.Default.SetExportedOnly(true)
    

    Impact

    The following things will newly be configurable globally:

    • SetDecimalUnit
    • SetExportedOnly
    • SetOutput
    • SetThousandsSeparator

    The following things were already available as pp.*, but now you're encouraged to use pp.Default.* instead:

    • SetColoringEnabled
      • Original ColoringEnabled
    • SetColorScheme, ResetColorScheme
    • SetOutput, ResetOutput
      • Original: SetDefaultOutput, ResetDefaultOutput
    Source code(tar.gz)
    Source code(zip)
Owner
Takashi Kokubun
Ruby committer developing JIT compiler. Maintainer of ERB and Haml.
Takashi Kokubun
Litter is a pretty printer library for Go data structures to aid in debugging and testing.

Litter Litter is a pretty printer library for Go data structures to aid in debugging and testing. Litter is provided by Sanity: The Headless CMS Const

Sanity 1.4k Dec 1, 2022
Implements a deep pretty printer for Go data structures to aid in debugging

spew Spew implements a deep pretty printer for Go data structures to aid in debugging. A comprehensive suite of tests with 100% test coverage is provi

null 93 Oct 31, 2022
Package httpretty prints the HTTP requests you make with Go pretty on your terminal.

httpretty Package httpretty prints the HTTP requests of your Go programs pretty on your terminal screen. It is mostly inspired in curl's --verbose mod

Henrique Vicente 279 Nov 16, 2022
🪵 A dead simple, pretty, and feature-rich logger for golang

?? lumber ?? A dead simple, pretty, and feature-rich logger for golang ?? Install ?? Logging Functions lumber.Success() lumber.Info() lumber.Debug() l

Matt Gleich 50 Jul 20, 2022
Delve is a debugger for the Go programming language.

The GitHub issue tracker is for bugs only. Please use the developer mailing list for any feature proposals and discussions. About Delve Installation L

null 19.6k Dec 4, 2022
groqfmt is a formatter for the GROQ query language

groqfmt groqfmt is a formatter for the GROQ query language. Usage Either: groqfmt INPUT > OUTPUT or: cat INPUT | groqfmt > OUTPUT or cat INPUT | groqf

Sanity 9 Oct 6, 2022
Gomon - Go language based system monitor

Copyright © 2021 The Gomon Project. Welcome to Gomon, the Go language based system monitor Welcome to Gomon, the Go language based system monitor Over

zosmac 3 Nov 18, 2022
Sand is the next, versatile, high-level compiled or interpreted language that's easy to learn and performant to run.

Sand is the newest, dynamically typed, interpreted programming language. Table of Contents History Project Stats History Sand was created as part of @

Neuron AI 4 Mar 13, 2022
Learngo - The purpose of this repository is to teach the basics of go programming language.

Learn Go Programming The purpose of this repository is to teach the basics of go programming language. Go programming language is developed and active

Jithu Mohandas 0 Jan 3, 2022
Logger - Go language is interface-oriented to implement an asynchronous log writing program

logger日志库 1、安装 go get github.com/staryjie/[email protected] 2、使用 示例: package main import ( "github.com/staryjie/logger" "time" ) func initLogger(name,

StaryJie 0 Jan 4, 2022
Go-mix - Both a tutorial paper and a library of classic TAOCP algorithms in the Go language

MIX golang This package is both a tutorial paper and a library of classic TAOCP

Andrew Astakhov 0 Jul 25, 2022
💻 PTerm | Pretty Terminal Printer A golang module to print pretty text

✨ PTerm is a modern go module to beautify console output. Featuring charts, progressbars, tables, trees, and many more ?? It's completely configurable and 100% cross-platform compatible.

null 3.1k Nov 29, 2022
Implements a deep pretty printer for Go data structures to aid in debugging

go-spew Go-spew implements a deep pretty printer for Go data structures to aid in debugging. A comprehensive suite of tests with 100% test coverage is

Dave Collins 5.4k Dec 8, 2022
Implements a deep pretty printer for Go data structures to aid in debugging

go-spew Go-spew implements a deep pretty printer for Go data structures to aid in debugging. A comprehensive suite of tests with 100% test coverage is

Dave Collins 5.4k Dec 3, 2022
Litter is a pretty printer library for Go data structures to aid in debugging and testing.

Litter Litter is a pretty printer library for Go data structures to aid in debugging and testing. Litter is provided by Sanity: The Headless CMS Const

Sanity 1.4k Dec 1, 2022
Fast Color JSON Marshaller + Pretty Printer for Golang

ColorJSON: The Fast Color JSON Marshaller for Go What is this? This package is based heavily on hokaccha/go-prettyjson but has some noticible differen

Tyler Brock 116 Dec 2, 2022
Implements a deep pretty printer for Go data structures to aid in debugging

spew Spew implements a deep pretty printer for Go data structures to aid in debugging. A comprehensive suite of tests with 100% test coverage is provi

null 93 Oct 31, 2022
Small, fast library to create ANSI colored strings and codes. [go, golang]

ansi Package ansi is a small, fast library to create ANSI colored strings and codes. Install Get it go get -u github.com/mgutz/ansi Example import "gi

Mario Gutierrez 377 Nov 24, 2022
Colored RSS feeds in your console

RSS Console Feed Read colored rss feeds in your console Usage ./rss-console-feed

Joe Gasewicz 0 Dec 22, 2021
Unified diff parser and printer for Go

go-diff Diff parser and printer for Go. Installing go get -u github.com/sourcegraph/go-diff/diff Usage It doesn't actually compute a diff. It only rea

Sourcegraph 379 Nov 12, 2022