Skip to content

Commit

Permalink
Expose defaultPrinter as DefaultPrinter.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmalloc committed Nov 21, 2020
1 parent fecb71e commit 71f4c51
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ The format is based on [Keep a Changelog], and this project adheres to
[Keep a Changelog]: https://keepachangelog.com/en/1.0.0/
[Semantic Versioning]: https://semver.org/spec/v2.0.0.html

## [0.4.1] - 2020-11-21

## Added

- Add `DefaultPrinter`, the printer used by `Write()`, `Format()` and `Print()`

## [0.4.0] - 2020-05-05

## Added
Expand Down Expand Up @@ -114,6 +120,7 @@ The format is based on [Keep a Changelog], and this project adheres to
[0.3.4]: https://github.com/dogmatiq/dapper/releases/tag/v0.3.4
[0.3.5]: https://github.com/dogmatiq/dapper/releases/tag/v0.3.5
[0.4.0]: https://github.com/dogmatiq/dapper/releases/tag/v0.4.0
[0.4.1]: https://github.com/dogmatiq/dapper/releases/tag/v0.4.1

[#6]: https://github.com/dogmatiq/dapper/issues/6
[#7]: https://github.com/dogmatiq/dapper/issues/7
Expand Down
9 changes: 5 additions & 4 deletions printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ func (p *Printer) Format(v interface{}) string {
return b.String()
}

var defaultPrinter = Printer{
// DefaultPrinter is the printer used by Write(), Format() and Print().
var DefaultPrinter = Printer{
Config: Config{
Filters: []Filter{
ReflectTypeFilter,
Expand All @@ -137,12 +138,12 @@ var defaultPrinter = Printer{
//
// It returns the number of bytes written.
func Write(w io.Writer, v interface{}) (int, error) {
return defaultPrinter.Write(w, v)
return DefaultPrinter.Write(w, v)
}

// Format returns a pretty-printed representation of v.
func Format(v interface{}) string {
return defaultPrinter.Format(v)
return DefaultPrinter.Format(v)
}

var newLine = []byte{'\n'}
Expand All @@ -153,7 +154,7 @@ func Print(values ...interface{}) {
mux.Lock()
defer mux.Unlock()
for _, v := range values {
defaultPrinter.Write(os.Stdout, v)
DefaultPrinter.Write(os.Stdout, v)
os.Stdout.Write(newLine)
}
}

0 comments on commit 71f4c51

Please sign in to comment.