p

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 25, 2022 License: MIT Imports: 8 Imported by: 3

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fp

func Fp(w io.Writer, args ...interface{}) (int, error)

Fp prints dumped your specified data with colored and writes to w. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered.

Example
package main

import (
	"bytes"
	"fmt"

	"github.com/Code-Hex/dd/p"
)

func main() {
	// prints simple string literal.
	var buf bytes.Buffer
	p.Fp(&buf, "Hello, World")
	fmt.Print(buf.String())
}
Output:

�[38;5;186m"Hello, World"�[0m

func P

func P(args ...interface{}) (int, error)

P prints dumped your specified data with colored. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered.

Example
package main

import (
	"github.com/Code-Hex/dd/p"
)

func main() {
	// prints simple string literal.
	p.P("Hello, World")
}
Output:

�[38;5;186m"Hello, World"�[0m

Types

type OptionFunc

type OptionFunc func(opts *options)

OptionFunc is type of an option for any printers.

func WithDumpOptions

func WithDumpOptions(ddOpts ...dd.OptionFunc) OptionFunc

WithDumpOptions is an option to append options of dd.Dump function.

func WithFormatter added in v1.0.1

func WithFormatter(formatter chroma.Formatter) OptionFunc

WithFormatter is an option to set formatter of the terminal output. Default will be set TTY256(256-colour) formatter.

Available chroma built-in formatters: https://pkg.go.dev/github.com/alecthomas/chroma/formatters

func WithStyle

func WithStyle(style *chroma.Style) OptionFunc

WithStyle is an option to set style of the syntax highlighting. Default will be set Monokai style.

Available themes: https://pkg.go.dev/github.com/alecthomas/chroma/styles

type Printer

type Printer struct {
	// contains filtered or unexported fields
}

Printer is a printer.

func New

func New(opts ...OptionFunc) *Printer

New creates a new Printer.

func (*Printer) Fp

func (p *Printer) Fp(w io.Writer, args ...interface{}) (int, error)

Fp prints dumped your specified data with colored and writes to w. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered.

Example
package main

import (
	"bytes"
	"fmt"

	"github.com/Code-Hex/dd/p"
	"github.com/alecthomas/chroma/styles"
)

func main() {
	// prints simple string literal.
	var buf bytes.Buffer
	p.New(p.WithStyle(styles.Dracula)).Fp(&buf, "Hello, World")
	fmt.Print(buf.String())
}
Output:

�[38;5;228m"Hello, World"�[0m

func (*Printer) P

func (p *Printer) P(args ...interface{}) (int, error)

P prints dumped your specified data with colored. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered.

Example
package main

import (
	"github.com/Code-Hex/dd/p"
	"github.com/alecthomas/chroma/styles"
)

func main() {
	// prints simple string literal.
	p.New(p.WithStyle(styles.Dracula)).P("Hello, World")
}
Output:

�[38;5;228m"Hello, World"�[0m

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL