fixed dependencies
This commit is contained in:
2
vendor/github.com/k0kubun/pp/v3/.github_changelog_generator
generated
vendored
Normal file
2
vendor/github.com/k0kubun/pp/v3/.github_changelog_generator
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
user=k0kubun
|
||||
project=pp
|
||||
258
vendor/github.com/k0kubun/pp/v3/CHANGELOG.md
generated
vendored
Normal file
258
vendor/github.com/k0kubun/pp/v3/CHANGELOG.md
generated
vendored
Normal file
@@ -0,0 +1,258 @@
|
||||
# Changelog
|
||||
|
||||
## [v3.2.0](https://github.com/k0kubun/pp/tree/v3.2.0)
|
||||
|
||||
[Full Changelog](https://github.com/k0kubun/pp/compare/v3.1.0...v3.2.0)
|
||||
|
||||
**Closed issues:**
|
||||
|
||||
- ignore private fields in a struct in pretty print golang [\#74](https://github.com/k0kubun/pp/issues/74)
|
||||
- Bug?: Colorize map field names/keys using "FieldName" color scheme setting [\#72](https://github.com/k0kubun/pp/issues/72)
|
||||
- Printf not work correctly [\#70](https://github.com/k0kubun/pp/issues/70)
|
||||
- How to use the latest version? [\#69](https://github.com/k0kubun/pp/issues/69)
|
||||
- Please provide a simple way to disable color [\#67](https://github.com/k0kubun/pp/issues/67)
|
||||
- disable printing of struct metadata [\#66](https://github.com/k0kubun/pp/issues/66)
|
||||
|
||||
**Merged pull requests:**
|
||||
|
||||
- Expose defaultPrettyPrinter as pp.Default [\#75](https://github.com/k0kubun/pp/pull/75) ([k0kubun](https://github.com/k0kubun))
|
||||
- Bump github.com/mattn/go-colorable from 0.1.12 to 0.1.13 [\#73](https://github.com/k0kubun/pp/pull/73) ([dependabot[bot]](https://github.com/apps/dependabot))
|
||||
- doc: fix pp.go arguments word typo [\#68](https://github.com/k0kubun/pp/pull/68) ([rasecoiac03](https://github.com/rasecoiac03))
|
||||
|
||||
## [v3.1.0](https://github.com/k0kubun/pp/tree/v3.1.0) (2022-01-06)
|
||||
|
||||
[Full Changelog](https://github.com/k0kubun/pp/compare/v3.0.10...v3.1.0)
|
||||
|
||||
**Merged pull requests:**
|
||||
|
||||
- Use SetDecimalUnit\(true\) by default [\#65](https://github.com/k0kubun/pp/pull/65) ([k0kubun](https://github.com/k0kubun))
|
||||
|
||||
## [v3.0.10](https://github.com/k0kubun/pp/tree/v3.0.10) (2022-01-06)
|
||||
|
||||
[Full Changelog](https://github.com/k0kubun/pp/compare/v3.0.9...v3.0.10)
|
||||
|
||||
**Merged pull requests:**
|
||||
|
||||
- Remove k0kubun/colorstring from dependencies [\#64](https://github.com/k0kubun/pp/pull/64) ([k0kubun](https://github.com/k0kubun))
|
||||
|
||||
## [v3.0.9](https://github.com/k0kubun/pp/tree/v3.0.9) (2022-01-06)
|
||||
|
||||
[Full Changelog](https://github.com/k0kubun/pp/compare/v3.0.8...v3.0.9)
|
||||
|
||||
**Merged pull requests:**
|
||||
|
||||
- Bump github.com/mattn/go-colorable from 0.1.7 to 0.1.12 [\#63](https://github.com/k0kubun/pp/pull/63) ([dependabot[bot]](https://github.com/apps/dependabot))
|
||||
|
||||
## [v3.0.8](https://github.com/k0kubun/pp/tree/v3.0.8) (2021-11-30)
|
||||
|
||||
[Full Changelog](https://github.com/k0kubun/pp/compare/v3.0.7...v3.0.8)
|
||||
|
||||
**Closed issues:**
|
||||
|
||||
- Add option to skip unexported fields [\#59](https://github.com/k0kubun/pp/issues/59)
|
||||
- Verb '%T' is working incorrectly in formatted print [\#58](https://github.com/k0kubun/pp/issues/58)
|
||||
- Option to print byte as decimal [\#54](https://github.com/k0kubun/pp/issues/54)
|
||||
- Option for thousands separator [\#53](https://github.com/k0kubun/pp/issues/53)
|
||||
- The color part of vim is messy [\#52](https://github.com/k0kubun/pp/issues/52)
|
||||
- Bug: `printTime` assumes the standard library time [\#47](https://github.com/k0kubun/pp/issues/47)
|
||||
- Feature request: Add `pp:"noprint"` tag [\#42](https://github.com/k0kubun/pp/issues/42)
|
||||
- Feature request: omitempty [\#22](https://github.com/k0kubun/pp/issues/22)
|
||||
- Unable to print invalid address [\#21](https://github.com/k0kubun/pp/issues/21)
|
||||
|
||||
**Merged pull requests:**
|
||||
|
||||
- build: upgrade `go` directive in `go.mod` to 1.17 [\#62](https://github.com/k0kubun/pp/pull/62) ([Juneezee](https://github.com/Juneezee))
|
||||
- SetThousandsSeparator [\#61](https://github.com/k0kubun/pp/pull/61) ([mariusgrigoriu](https://github.com/mariusgrigoriu))
|
||||
- Add ExportedOnly option [\#60](https://github.com/k0kubun/pp/pull/60) ([k0kubun](https://github.com/k0kubun))
|
||||
- Add SetDecimalUint option [\#55](https://github.com/k0kubun/pp/pull/55) ([k0kubun](https://github.com/k0kubun))
|
||||
- Add Badge for pkg.go.dev [\#51](https://github.com/k0kubun/pp/pull/51) ([zakuro9715](https://github.com/zakuro9715))
|
||||
- Fix typo in README.md [\#50](https://github.com/k0kubun/pp/pull/50) ([bl-ue](https://github.com/bl-ue))
|
||||
- Add Struct Tag Support for Printing [\#49](https://github.com/k0kubun/pp/pull/49) ([rickbau5](https://github.com/rickbau5))
|
||||
- Ensure time.Time is from standard library [\#48](https://github.com/k0kubun/pp/pull/48) ([bquenin](https://github.com/bquenin))
|
||||
|
||||
## [v3.0.7](https://github.com/k0kubun/pp/tree/v3.0.7) (2020-11-18)
|
||||
|
||||
[Full Changelog](https://github.com/k0kubun/pp/compare/v3.0.6...v3.0.7)
|
||||
|
||||
**Closed issues:**
|
||||
|
||||
- Sort map by key before printing [\#23](https://github.com/k0kubun/pp/issues/23)
|
||||
|
||||
**Merged pull requests:**
|
||||
|
||||
- Resurrect Go 1.11 support [\#46](https://github.com/k0kubun/pp/pull/46) ([k0kubun](https://github.com/k0kubun))
|
||||
|
||||
## [v3.0.6](https://github.com/k0kubun/pp/tree/v3.0.6) (2020-11-14)
|
||||
|
||||
[Full Changelog](https://github.com/k0kubun/pp/compare/v3.0.5...v3.0.6)
|
||||
|
||||
**Merged pull requests:**
|
||||
|
||||
- Sort keys of maps [\#45](https://github.com/k0kubun/pp/pull/45) ([k0kubun](https://github.com/k0kubun))
|
||||
|
||||
## [v3.0.5](https://github.com/k0kubun/pp/tree/v3.0.5) (2020-11-14)
|
||||
|
||||
[Full Changelog](https://github.com/k0kubun/pp/compare/v3.0.4...v3.0.5)
|
||||
|
||||
## [v3.0.4](https://github.com/k0kubun/pp/tree/v3.0.4) (2020-11-12)
|
||||
|
||||
[Full Changelog](https://github.com/k0kubun/pp/compare/v3.0.3...v3.0.4)
|
||||
|
||||
**Closed issues:**
|
||||
|
||||
- Feature request: Pretty print big.Int and big.Float? [\#41](https://github.com/k0kubun/pp/issues/41)
|
||||
|
||||
**Merged pull requests:**
|
||||
|
||||
- chore: optimize CI [\#44](https://github.com/k0kubun/pp/pull/44) ([deliangyang](https://github.com/deliangyang))
|
||||
- refactor: use defer release lock [\#43](https://github.com/k0kubun/pp/pull/43) ([deliangyang](https://github.com/deliangyang))
|
||||
|
||||
## [v3.0.3](https://github.com/k0kubun/pp/tree/v3.0.3) (2020-08-11)
|
||||
|
||||
[Full Changelog](https://github.com/k0kubun/pp/compare/v3.0.2...v3.0.3)
|
||||
|
||||
**Closed issues:**
|
||||
|
||||
- go mod doesn't install 3.0.2 [\#40](https://github.com/k0kubun/pp/issues/40)
|
||||
|
||||
## [v3.0.2](https://github.com/k0kubun/pp/tree/v3.0.2) (2020-05-05)
|
||||
|
||||
[Full Changelog](https://github.com/k0kubun/pp/compare/v3.0.1...v3.0.2)
|
||||
|
||||
**Closed issues:**
|
||||
|
||||
- WithLineInfo print the wrong line [\#39](https://github.com/k0kubun/pp/issues/39)
|
||||
- Display of nil slice as same as an empty slice [\#36](https://github.com/k0kubun/pp/issues/36)
|
||||
- Unsure why number coming out in base 16 [\#27](https://github.com/k0kubun/pp/issues/27)
|
||||
- disable colors when not output is not a tty [\#26](https://github.com/k0kubun/pp/issues/26)
|
||||
|
||||
**Merged pull requests:**
|
||||
|
||||
- Allow changing coloringEnabled per pp instance [\#37](https://github.com/k0kubun/pp/pull/37) ([k0kubun](https://github.com/k0kubun))
|
||||
- support Go modules [\#35](https://github.com/k0kubun/pp/pull/35) ([itchyny](https://github.com/itchyny))
|
||||
- Add max depth var [\#34](https://github.com/k0kubun/pp/pull/34) ([sumerc](https://github.com/sumerc))
|
||||
- Allow own instances of pp [\#33](https://github.com/k0kubun/pp/pull/33) ([Eun](https://github.com/Eun))
|
||||
- fix typo of foreground [\#32](https://github.com/k0kubun/pp/pull/32) ([shogo82148](https://github.com/shogo82148))
|
||||
|
||||
## [v3.0.1](https://github.com/k0kubun/pp/tree/v3.0.1) (2019-04-02)
|
||||
|
||||
[Full Changelog](https://github.com/k0kubun/pp/compare/v3.0.0...v3.0.1)
|
||||
|
||||
## [v3.0.0](https://github.com/k0kubun/pp/tree/v3.0.0) (2019-03-04)
|
||||
|
||||
[Full Changelog](https://github.com/k0kubun/pp/compare/v2.4.0...v3.0.0)
|
||||
|
||||
## [v2.4.0](https://github.com/k0kubun/pp/tree/v2.4.0) (2019-03-03)
|
||||
|
||||
[Full Changelog](https://github.com/k0kubun/pp/compare/v2.3.0...v2.4.0)
|
||||
|
||||
**Merged pull requests:**
|
||||
|
||||
- Fix newline of map type [\#29](https://github.com/k0kubun/pp/pull/29) ([itchyny](https://github.com/itchyny))
|
||||
- add MIT license file [\#28](https://github.com/k0kubun/pp/pull/28) ([alteholz](https://github.com/alteholz))
|
||||
- Update the map printer to properly print maps. [\#25](https://github.com/k0kubun/pp/pull/25) ([denniszl](https://github.com/denniszl))
|
||||
|
||||
## [v2.3.0](https://github.com/k0kubun/pp/tree/v2.3.0) (2017-01-23)
|
||||
|
||||
[Full Changelog](https://github.com/k0kubun/pp/compare/v2.2.0...v2.3.0)
|
||||
|
||||
**Merged pull requests:**
|
||||
|
||||
- Add WithLineInfo method for print filename and line number along [\#24](https://github.com/k0kubun/pp/pull/24) ([huydx](https://github.com/huydx))
|
||||
|
||||
## [v2.2.0](https://github.com/k0kubun/pp/tree/v2.2.0) (2015-07-23)
|
||||
|
||||
[Full Changelog](https://github.com/k0kubun/pp/compare/v2.1.0...v2.2.0)
|
||||
|
||||
**Closed issues:**
|
||||
|
||||
- please do not use unsafe package [\#20](https://github.com/k0kubun/pp/issues/20)
|
||||
|
||||
**Merged pull requests:**
|
||||
|
||||
- check whether reflect.Value can call `Interface()` [\#19](https://github.com/k0kubun/pp/pull/19) ([skatsuta](https://github.com/skatsuta))
|
||||
- Fix indent for slices [\#18](https://github.com/k0kubun/pp/pull/18) ([sdidyk](https://github.com/sdidyk))
|
||||
|
||||
## [v2.1.0](https://github.com/k0kubun/pp/tree/v2.1.0) (2015-04-25)
|
||||
|
||||
[Full Changelog](https://github.com/k0kubun/pp/compare/v2.0.1...v2.1.0)
|
||||
|
||||
**Merged pull requests:**
|
||||
|
||||
- Custom colors [\#17](https://github.com/k0kubun/pp/pull/17) ([sdidyk](https://github.com/sdidyk))
|
||||
- Some changes of printer [\#16](https://github.com/k0kubun/pp/pull/16) ([sdidyk](https://github.com/sdidyk))
|
||||
- Suppress panic caused by Float values [\#15](https://github.com/k0kubun/pp/pull/15) ([yudai](https://github.com/yudai))
|
||||
|
||||
## [v2.0.1](https://github.com/k0kubun/pp/tree/v2.0.1) (2015-03-01)
|
||||
|
||||
[Full Changelog](https://github.com/k0kubun/pp/compare/v2.0.0...v2.0.1)
|
||||
|
||||
**Merged pull requests:**
|
||||
|
||||
- escape sequences to pipe [\#13](https://github.com/k0kubun/pp/pull/13) ([mattn](https://github.com/mattn))
|
||||
|
||||
## [v2.0.0](https://github.com/k0kubun/pp/tree/v2.0.0) (2015-02-14)
|
||||
|
||||
[Full Changelog](https://github.com/k0kubun/pp/compare/v1.3.0...v2.0.0)
|
||||
|
||||
**Closed issues:**
|
||||
|
||||
- Fold large buffers [\#8](https://github.com/k0kubun/pp/issues/8)
|
||||
|
||||
**Merged pull requests:**
|
||||
|
||||
- Fold a large buffer [\#12](https://github.com/k0kubun/pp/pull/12) ([k0kubun](https://github.com/k0kubun))
|
||||
|
||||
## [v1.3.0](https://github.com/k0kubun/pp/tree/v1.3.0) (2015-02-14)
|
||||
|
||||
[Full Changelog](https://github.com/k0kubun/pp/compare/v1.2.0...v1.3.0)
|
||||
|
||||
**Closed issues:**
|
||||
|
||||
- time.Time formatter [\#2](https://github.com/k0kubun/pp/issues/2)
|
||||
|
||||
**Merged pull requests:**
|
||||
|
||||
- Implement time.Time pretty printer [\#11](https://github.com/k0kubun/pp/pull/11) ([k0kubun](https://github.com/k0kubun))
|
||||
|
||||
## [v1.2.0](https://github.com/k0kubun/pp/tree/v1.2.0) (2015-02-14)
|
||||
|
||||
[Full Changelog](https://github.com/k0kubun/pp/compare/v1.1.0...v1.2.0)
|
||||
|
||||
**Merged pull requests:**
|
||||
|
||||
- Color escaped characters inside strings [\#10](https://github.com/k0kubun/pp/pull/10) ([motemen](https://github.com/motemen))
|
||||
|
||||
## [v1.1.0](https://github.com/k0kubun/pp/tree/v1.1.0) (2015-02-14)
|
||||
|
||||
[Full Changelog](https://github.com/k0kubun/pp/compare/v1.0.0...v1.1.0)
|
||||
|
||||
**Merged pull requests:**
|
||||
|
||||
- Handle circular structures [\#9](https://github.com/k0kubun/pp/pull/9) ([motemen](https://github.com/motemen))
|
||||
|
||||
## [v1.0.0](https://github.com/k0kubun/pp/tree/v1.0.0) (2015-01-09)
|
||||
|
||||
[Full Changelog](https://github.com/k0kubun/pp/compare/v0.0.1...v1.0.0)
|
||||
|
||||
**Closed issues:**
|
||||
|
||||
- test failed if Golang over 1.4 [\#5](https://github.com/k0kubun/pp/issues/5)
|
||||
|
||||
**Merged pull requests:**
|
||||
|
||||
- remove unused struct. [\#7](https://github.com/k0kubun/pp/pull/7) ([walf443](https://github.com/walf443))
|
||||
- customizable Print\* functions output [\#6](https://github.com/k0kubun/pp/pull/6) ([walf443](https://github.com/walf443))
|
||||
|
||||
## [v0.0.1](https://github.com/k0kubun/pp/tree/v0.0.1) (2014-12-29)
|
||||
|
||||
[Full Changelog](https://github.com/k0kubun/pp/compare/71948a64abfb9f3877ee472dba16472ca6d8e773...v0.0.1)
|
||||
|
||||
**Merged pull requests:**
|
||||
|
||||
- fix: `Fprintln` infinite loop bug. [\#3](https://github.com/k0kubun/pp/pull/3) ([kyokomi](https://github.com/kyokomi))
|
||||
- Support windows [\#1](https://github.com/k0kubun/pp/pull/1) ([k0kubun](https://github.com/k0kubun))
|
||||
|
||||
|
||||
|
||||
\* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)*
|
||||
21
vendor/github.com/k0kubun/pp/v3/LICENSE.txt
generated
vendored
Normal file
21
vendor/github.com/k0kubun/pp/v3/LICENSE.txt
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Takashi Kokubun
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
107
vendor/github.com/k0kubun/pp/v3/README.md
generated
vendored
Normal file
107
vendor/github.com/k0kubun/pp/v3/README.md
generated
vendored
Normal file
@@ -0,0 +1,107 @@
|
||||
# pp [](https://github.com/k0kubun/pp/actions) [](https://pkg.go.dev/github.com/k0kubun/pp/v3)
|
||||
|
||||
Colored pretty printer for Go language
|
||||
|
||||

|
||||
|
||||
## Usage
|
||||
|
||||
Just call `pp.Print()`.
|
||||
|
||||
```go
|
||||
import "github.com/k0kubun/pp/v3"
|
||||
|
||||
m := map[string]string{"foo": "bar", "hello": "world"}
|
||||
pp.Print(m)
|
||||
```
|
||||
|
||||

|
||||
|
||||
### API
|
||||
|
||||
fmt package-like functions are provided.
|
||||
|
||||
```go
|
||||
pp.Print()
|
||||
pp.Println()
|
||||
pp.Sprint()
|
||||
pp.Fprintf()
|
||||
// ...
|
||||
```
|
||||
|
||||
You can also create own instances that do not interfere with the default printer:
|
||||
|
||||
```go
|
||||
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:
|
||||
|
||||
```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.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
|
||||
|
||||

|
||||
|
||||
### UserStream event
|
||||
|
||||

|
||||
|
||||
### Works on windows
|
||||
|
||||

|
||||
|
||||
## License
|
||||
|
||||
MIT License
|
||||
125
vendor/github.com/k0kubun/pp/v3/color.go
generated
vendored
Normal file
125
vendor/github.com/k0kubun/pp/v3/color.go
generated
vendored
Normal file
@@ -0,0 +1,125 @@
|
||||
// color.go: Color API and implementation
|
||||
package pp
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
const (
|
||||
// No color
|
||||
NoColor uint16 = 1 << 15
|
||||
)
|
||||
|
||||
const (
|
||||
// Foreground colors for ColorScheme.
|
||||
_ uint16 = iota | NoColor
|
||||
Black
|
||||
Red
|
||||
Green
|
||||
Yellow
|
||||
Blue
|
||||
Magenta
|
||||
Cyan
|
||||
White
|
||||
bitsForeground = 0
|
||||
maskForeground = 0xf
|
||||
ansiForegroundOffset = 30 - 1
|
||||
)
|
||||
|
||||
const (
|
||||
// Background colors for ColorScheme.
|
||||
_ uint16 = iota<<bitsBackground | NoColor
|
||||
BackgroundBlack
|
||||
BackgroundRed
|
||||
BackgroundGreen
|
||||
BackgroundYellow
|
||||
BackgroundBlue
|
||||
BackgroundMagenta
|
||||
BackgroundCyan
|
||||
BackgroundWhite
|
||||
bitsBackground = 4
|
||||
maskBackground = 0xf << bitsBackground
|
||||
ansiBackgroundOffset = 40 - 1
|
||||
)
|
||||
|
||||
const (
|
||||
// Bold flag for ColorScheme.
|
||||
Bold uint16 = 1<<bitsBold | NoColor
|
||||
bitsBold = 8
|
||||
maskBold = 1 << bitsBold
|
||||
ansiBold = 1
|
||||
)
|
||||
|
||||
// To use with SetColorScheme.
|
||||
type ColorScheme struct {
|
||||
Bool uint16
|
||||
Integer uint16
|
||||
Float uint16
|
||||
String uint16
|
||||
StringQuotation uint16
|
||||
EscapedChar uint16
|
||||
FieldName uint16
|
||||
PointerAdress uint16
|
||||
Nil uint16
|
||||
Time uint16
|
||||
StructName uint16
|
||||
ObjectLength uint16
|
||||
}
|
||||
|
||||
var (
|
||||
// DEPRECATED: Use PrettyPrinter.SetColoringEnabled().
|
||||
ColoringEnabled = true
|
||||
|
||||
defaultScheme = ColorScheme{
|
||||
Bool: Cyan | Bold,
|
||||
Integer: Blue | Bold,
|
||||
Float: Magenta | Bold,
|
||||
String: Red,
|
||||
StringQuotation: Red | Bold,
|
||||
EscapedChar: Magenta | Bold,
|
||||
FieldName: Yellow,
|
||||
PointerAdress: Blue | Bold,
|
||||
Nil: Cyan | Bold,
|
||||
Time: Blue | Bold,
|
||||
StructName: Green,
|
||||
ObjectLength: Blue,
|
||||
}
|
||||
)
|
||||
|
||||
func (cs *ColorScheme) fixColors() {
|
||||
typ := reflect.Indirect(reflect.ValueOf(cs))
|
||||
defaultType := reflect.ValueOf(defaultScheme)
|
||||
for i := 0; i < typ.NumField(); i++ {
|
||||
field := typ.Field(i)
|
||||
if field.Uint() == 0 {
|
||||
field.SetUint(defaultType.Field(i).Uint())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func colorizeText(text string, color uint16) string {
|
||||
foreground := color & maskForeground >> bitsForeground
|
||||
background := color & maskBackground >> bitsBackground
|
||||
bold := color & maskBold
|
||||
|
||||
if foreground == 0 && background == 0 && bold == 0 {
|
||||
return text
|
||||
}
|
||||
|
||||
modBold := ""
|
||||
modForeground := ""
|
||||
modBackground := ""
|
||||
|
||||
if bold > 0 {
|
||||
modBold = "\033[1m"
|
||||
}
|
||||
if foreground > 0 {
|
||||
modForeground = fmt.Sprintf("\033[%dm", foreground+ansiForegroundOffset)
|
||||
}
|
||||
if background > 0 {
|
||||
modBackground = fmt.Sprintf("\033[%dm", background+ansiBackgroundOffset)
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%s%s%s%s\033[0m", modForeground, modBackground, modBold, text)
|
||||
}
|
||||
308
vendor/github.com/k0kubun/pp/v3/pp.go
generated
vendored
Normal file
308
vendor/github.com/k0kubun/pp/v3/pp.go
generated
vendored
Normal file
@@ -0,0 +1,308 @@
|
||||
// pp.go: API definitions. The core implementation is delegated to printer.go.
|
||||
package pp
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"runtime"
|
||||
"sync"
|
||||
|
||||
"github.com/mattn/go-colorable"
|
||||
)
|
||||
|
||||
// Global variable API
|
||||
// see also: color.go
|
||||
var (
|
||||
// Default pretty printer. It's public so that you can modify config globally.
|
||||
Default = newPrettyPrinter(3) // pp.* => PrettyPrinter.* => formatAll
|
||||
// If the length of array or slice is larger than this,
|
||||
// the buffer will be shorten as {...}.
|
||||
BufferFoldThreshold = 1024
|
||||
// PrintMapTypes when set to true will have map types will always appended to maps.
|
||||
PrintMapTypes = true
|
||||
// WithLineInfo add file name and line information to output
|
||||
// call this function with care, because getting stack has performance penalty
|
||||
WithLineInfo bool
|
||||
)
|
||||
|
||||
// Internals
|
||||
var (
|
||||
defaultOut = colorable.NewColorableStdout()
|
||||
defaultWithLineInfo = false
|
||||
)
|
||||
|
||||
type PrettyPrinter struct {
|
||||
// WithLineInfo adds file name and line information to output.
|
||||
// Call this function with care, because getting stack has performance penalty.
|
||||
WithLineInfo bool
|
||||
// To support WithLineInfo, we need to know which frame we should look at.
|
||||
// Thus callerLevel sets the number of frames it needs to skip.
|
||||
callerLevel int
|
||||
out io.Writer
|
||||
currentScheme ColorScheme
|
||||
outLock sync.Mutex
|
||||
maxDepth int
|
||||
coloringEnabled bool
|
||||
decimalUint bool
|
||||
thousandsSeparator bool
|
||||
// This skips unexported fields of structs.
|
||||
exportedOnly bool
|
||||
}
|
||||
|
||||
// New creates a new PrettyPrinter that can be used to pretty print values
|
||||
func New() *PrettyPrinter {
|
||||
return newPrettyPrinter(2) // PrettyPrinter.* => formatAll
|
||||
}
|
||||
|
||||
func newPrettyPrinter(callerLevel int) *PrettyPrinter {
|
||||
return &PrettyPrinter{
|
||||
WithLineInfo: defaultWithLineInfo,
|
||||
callerLevel: callerLevel,
|
||||
out: defaultOut,
|
||||
currentScheme: defaultScheme,
|
||||
maxDepth: -1,
|
||||
coloringEnabled: true,
|
||||
decimalUint: true,
|
||||
exportedOnly: false,
|
||||
}
|
||||
}
|
||||
|
||||
// Print prints given arguments.
|
||||
func (pp *PrettyPrinter) Print(a ...interface{}) (n int, err error) {
|
||||
return fmt.Fprint(pp.out, pp.formatAll(a)...)
|
||||
}
|
||||
|
||||
// Printf prints a given format.
|
||||
func (pp *PrettyPrinter) Printf(format string, a ...interface{}) (n int, err error) {
|
||||
return fmt.Fprintf(pp.out, format, pp.formatAll(a)...)
|
||||
}
|
||||
|
||||
// Println prints given arguments with newline.
|
||||
func (pp *PrettyPrinter) Println(a ...interface{}) (n int, err error) {
|
||||
return fmt.Fprintln(pp.out, pp.formatAll(a)...)
|
||||
}
|
||||
|
||||
// Sprint formats given arguments and returns the result as string.
|
||||
func (pp *PrettyPrinter) Sprint(a ...interface{}) string {
|
||||
return fmt.Sprint(pp.formatAll(a)...)
|
||||
}
|
||||
|
||||
// Sprintf formats with pretty print and returns the result as string.
|
||||
func (pp *PrettyPrinter) Sprintf(format string, a ...interface{}) string {
|
||||
return fmt.Sprintf(format, pp.formatAll(a)...)
|
||||
}
|
||||
|
||||
// Sprintln formats given arguments with newline and returns the result as string.
|
||||
func (pp *PrettyPrinter) Sprintln(a ...interface{}) string {
|
||||
return fmt.Sprintln(pp.formatAll(a)...)
|
||||
}
|
||||
|
||||
// Fprint prints given arguments to a given writer.
|
||||
func (pp *PrettyPrinter) Fprint(w io.Writer, a ...interface{}) (n int, err error) {
|
||||
return fmt.Fprint(w, pp.formatAll(a)...)
|
||||
}
|
||||
|
||||
// Fprintf prints format to a given writer.
|
||||
func (pp *PrettyPrinter) Fprintf(w io.Writer, format string, a ...interface{}) (n int, err error) {
|
||||
return fmt.Fprintf(w, format, pp.formatAll(a)...)
|
||||
}
|
||||
|
||||
// Fprintln prints given arguments to a given writer with newline.
|
||||
func (pp *PrettyPrinter) Fprintln(w io.Writer, a ...interface{}) (n int, err error) {
|
||||
return fmt.Fprintln(w, pp.formatAll(a)...)
|
||||
}
|
||||
|
||||
// Errorf formats given arguments and returns it as error type.
|
||||
func (pp *PrettyPrinter) Errorf(format string, a ...interface{}) error {
|
||||
return errors.New(pp.Sprintf(format, a...))
|
||||
}
|
||||
|
||||
// Fatal prints given arguments and finishes execution with exit status 1.
|
||||
func (pp *PrettyPrinter) Fatal(a ...interface{}) {
|
||||
fmt.Fprint(pp.out, pp.formatAll(a)...)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Fatalf prints a given format and finishes execution with exit status 1.
|
||||
func (pp *PrettyPrinter) Fatalf(format string, a ...interface{}) {
|
||||
fmt.Fprintf(pp.out, format, pp.formatAll(a)...)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Fatalln prints given arguments with newline and finishes execution with exit status 1.
|
||||
func (pp *PrettyPrinter) Fatalln(a ...interface{}) {
|
||||
fmt.Fprintln(pp.out, pp.formatAll(a)...)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
func (pp *PrettyPrinter) SetColoringEnabled(enabled bool) {
|
||||
pp.coloringEnabled = enabled
|
||||
}
|
||||
|
||||
func (pp *PrettyPrinter) SetDecimalUint(enabled bool) {
|
||||
pp.decimalUint = enabled
|
||||
}
|
||||
|
||||
func (pp *PrettyPrinter) SetExportedOnly(enabled bool) {
|
||||
pp.exportedOnly = enabled
|
||||
}
|
||||
|
||||
func (pp *PrettyPrinter) SetThousandsSeparator(enabled bool) {
|
||||
pp.thousandsSeparator = enabled
|
||||
}
|
||||
|
||||
// SetOutput sets pp's output
|
||||
func (pp *PrettyPrinter) SetOutput(o io.Writer) {
|
||||
pp.outLock.Lock()
|
||||
defer pp.outLock.Unlock()
|
||||
|
||||
pp.out = o
|
||||
}
|
||||
|
||||
// GetOutput returns pp's output.
|
||||
func (pp *PrettyPrinter) GetOutput() io.Writer {
|
||||
return pp.out
|
||||
}
|
||||
|
||||
// ResetOutput sets pp's output back to the default output
|
||||
func (pp *PrettyPrinter) ResetOutput() {
|
||||
pp.outLock.Lock()
|
||||
defer pp.outLock.Unlock()
|
||||
|
||||
pp.out = defaultOut
|
||||
}
|
||||
|
||||
// SetColorScheme takes a colorscheme used by all future Print calls.
|
||||
func (pp *PrettyPrinter) SetColorScheme(scheme ColorScheme) {
|
||||
scheme.fixColors()
|
||||
pp.currentScheme = scheme
|
||||
}
|
||||
|
||||
// ResetColorScheme resets colorscheme to default.
|
||||
func (pp *PrettyPrinter) ResetColorScheme() {
|
||||
pp.currentScheme = defaultScheme
|
||||
}
|
||||
|
||||
func (pp *PrettyPrinter) formatAll(objects []interface{}) []interface{} {
|
||||
results := []interface{}{}
|
||||
|
||||
// fix for backwards capability
|
||||
withLineInfo := pp.WithLineInfo
|
||||
if pp == Default {
|
||||
withLineInfo = WithLineInfo
|
||||
}
|
||||
|
||||
if withLineInfo {
|
||||
_, fn, line, _ := runtime.Caller(pp.callerLevel)
|
||||
results = append(results, fmt.Sprintf("%s:%d\n", fn, line))
|
||||
}
|
||||
|
||||
for _, object := range objects {
|
||||
results = append(results, pp.format(object))
|
||||
}
|
||||
return results
|
||||
}
|
||||
|
||||
// Print prints given arguments.
|
||||
func Print(a ...interface{}) (n int, err error) {
|
||||
return Default.Print(a...)
|
||||
}
|
||||
|
||||
// Printf prints a given format.
|
||||
func Printf(format string, a ...interface{}) (n int, err error) {
|
||||
return Default.Printf(format, a...)
|
||||
}
|
||||
|
||||
// Println prints given arguments with newline.
|
||||
func Println(a ...interface{}) (n int, err error) {
|
||||
return Default.Println(a...)
|
||||
}
|
||||
|
||||
// Sprint formats given arguments and returns the result as string.
|
||||
func Sprint(a ...interface{}) string {
|
||||
return Default.Sprint(a...)
|
||||
}
|
||||
|
||||
// Sprintf formats with pretty print and returns the result as string.
|
||||
func Sprintf(format string, a ...interface{}) string {
|
||||
return Default.Sprintf(format, a...)
|
||||
}
|
||||
|
||||
// Sprintln formats given arguments with newline and returns the result as string.
|
||||
func Sprintln(a ...interface{}) string {
|
||||
return Default.Sprintln(a...)
|
||||
}
|
||||
|
||||
// Fprint prints given arguments to a given writer.
|
||||
func Fprint(w io.Writer, a ...interface{}) (n int, err error) {
|
||||
return Default.Fprint(w, a...)
|
||||
}
|
||||
|
||||
// Fprintf prints format to a given writer.
|
||||
func Fprintf(w io.Writer, format string, a ...interface{}) (n int, err error) {
|
||||
return Default.Fprintf(w, format, a...)
|
||||
}
|
||||
|
||||
// Fprintln prints given arguments to a given writer with newline.
|
||||
func Fprintln(w io.Writer, a ...interface{}) (n int, err error) {
|
||||
return Default.Fprintln(w, a...)
|
||||
}
|
||||
|
||||
// Errorf formats given arguments and returns it as error type.
|
||||
func Errorf(format string, a ...interface{}) error {
|
||||
return Default.Errorf(format, a...)
|
||||
}
|
||||
|
||||
// Fatal prints given arguments and finishes execution with exit status 1.
|
||||
func Fatal(a ...interface{}) {
|
||||
Default.Fatal(a...)
|
||||
}
|
||||
|
||||
// Fatalf prints a given format and finishes execution with exit status 1.
|
||||
func Fatalf(format string, a ...interface{}) {
|
||||
Default.Fatalf(format, a...)
|
||||
}
|
||||
|
||||
// Fatalln prints given arguments with newline and finishes execution with exit status 1.
|
||||
func Fatalln(a ...interface{}) {
|
||||
Default.Fatalln(a...)
|
||||
}
|
||||
|
||||
// Change Print* functions' output to a given writer.
|
||||
// For example, you can limit output by ENV.
|
||||
//
|
||||
// func init() {
|
||||
// if os.Getenv("DEBUG") == "" {
|
||||
// pp.SetDefaultOutput(ioutil.Discard)
|
||||
// }
|
||||
// }
|
||||
func SetDefaultOutput(o io.Writer) {
|
||||
Default.SetOutput(o)
|
||||
}
|
||||
|
||||
// GetOutput returns pp's default output.
|
||||
func GetDefaultOutput() io.Writer {
|
||||
return Default.GetOutput()
|
||||
}
|
||||
|
||||
// Change Print* functions' output to default one.
|
||||
func ResetDefaultOutput() {
|
||||
Default.ResetOutput()
|
||||
}
|
||||
|
||||
// SetColorScheme takes a colorscheme used by all future Print calls.
|
||||
func SetColorScheme(scheme ColorScheme) {
|
||||
Default.SetColorScheme(scheme)
|
||||
}
|
||||
|
||||
// ResetColorScheme resets colorscheme to default.
|
||||
func ResetColorScheme() {
|
||||
Default.ResetColorScheme()
|
||||
}
|
||||
|
||||
// SetMaxDepth sets the printer's Depth, -1 prints all
|
||||
func SetDefaultMaxDepth(v int) {
|
||||
Default.maxDepth = v
|
||||
}
|
||||
526
vendor/github.com/k0kubun/pp/v3/printer.go
generated
vendored
Normal file
526
vendor/github.com/k0kubun/pp/v3/printer.go
generated
vendored
Normal file
@@ -0,0 +1,526 @@
|
||||
// printer.go: The actual pretty print implementation. Everything in this file should be private.
|
||||
package pp
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"math"
|
||||
"math/big"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"text/tabwriter"
|
||||
"time"
|
||||
|
||||
"golang.org/x/text/language"
|
||||
"golang.org/x/text/message"
|
||||
)
|
||||
|
||||
const (
|
||||
indentWidth = 2
|
||||
)
|
||||
|
||||
func (pp *PrettyPrinter) format(object interface{}) string {
|
||||
return newPrinter(object, &pp.currentScheme, pp.maxDepth, pp.coloringEnabled, pp.decimalUint, pp.exportedOnly, pp.thousandsSeparator).String()
|
||||
}
|
||||
|
||||
func newPrinter(object interface{}, currentScheme *ColorScheme, maxDepth int, coloringEnabled bool, decimalUint bool, exportedOnly bool, thousandsSeparator bool) *printer {
|
||||
buffer := bytes.NewBufferString("")
|
||||
tw := new(tabwriter.Writer)
|
||||
tw.Init(buffer, indentWidth, 0, 1, ' ', 0)
|
||||
|
||||
printer := &printer{
|
||||
Buffer: buffer,
|
||||
tw: tw,
|
||||
depth: 0,
|
||||
maxDepth: maxDepth,
|
||||
value: reflect.ValueOf(object),
|
||||
visited: map[uintptr]bool{},
|
||||
currentScheme: currentScheme,
|
||||
coloringEnabled: coloringEnabled,
|
||||
decimalUint: decimalUint,
|
||||
exportedOnly: exportedOnly,
|
||||
thousandsSeparator: thousandsSeparator,
|
||||
}
|
||||
|
||||
if thousandsSeparator {
|
||||
printer.localizedPrinter = message.NewPrinter(language.English)
|
||||
}
|
||||
|
||||
return printer
|
||||
}
|
||||
|
||||
type printer struct {
|
||||
*bytes.Buffer
|
||||
tw *tabwriter.Writer
|
||||
depth int
|
||||
maxDepth int
|
||||
value reflect.Value
|
||||
visited map[uintptr]bool
|
||||
currentScheme *ColorScheme
|
||||
coloringEnabled bool
|
||||
decimalUint bool
|
||||
exportedOnly bool
|
||||
thousandsSeparator bool
|
||||
localizedPrinter *message.Printer
|
||||
}
|
||||
|
||||
func (p *printer) String() string {
|
||||
switch p.value.Kind() {
|
||||
case reflect.Bool:
|
||||
p.colorPrint(p.raw(), p.currentScheme.Bool)
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
|
||||
reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64,
|
||||
reflect.Uintptr, reflect.Complex64, reflect.Complex128:
|
||||
p.colorPrint(p.raw(), p.currentScheme.Integer)
|
||||
case reflect.Float32, reflect.Float64:
|
||||
p.colorPrint(p.raw(), p.currentScheme.Float)
|
||||
case reflect.String:
|
||||
p.printString()
|
||||
case reflect.Map:
|
||||
p.printMap()
|
||||
case reflect.Struct:
|
||||
p.printStruct()
|
||||
case reflect.Array, reflect.Slice:
|
||||
p.printSlice()
|
||||
case reflect.Chan:
|
||||
p.printf("(%s)(%s)", p.typeString(), p.pointerAddr())
|
||||
case reflect.Interface:
|
||||
p.printInterface()
|
||||
case reflect.Ptr:
|
||||
p.printPtr()
|
||||
case reflect.Func:
|
||||
p.printf("%s {...}", p.typeString())
|
||||
case reflect.UnsafePointer:
|
||||
p.printf("%s(%s)", p.typeString(), p.pointerAddr())
|
||||
case reflect.Invalid:
|
||||
p.print(p.nil())
|
||||
default:
|
||||
p.print(p.raw())
|
||||
}
|
||||
|
||||
p.tw.Flush()
|
||||
return p.Buffer.String()
|
||||
}
|
||||
|
||||
func (p *printer) print(text string) {
|
||||
fmt.Fprint(p.tw, text)
|
||||
}
|
||||
|
||||
func (p *printer) printf(format string, args ...interface{}) {
|
||||
text := fmt.Sprintf(format, args...)
|
||||
p.print(text)
|
||||
}
|
||||
|
||||
func (p *printer) println(text string) {
|
||||
p.print(text + "\n")
|
||||
}
|
||||
|
||||
func (p *printer) indentPrint(text string) {
|
||||
p.print(p.indent() + text)
|
||||
}
|
||||
|
||||
func (p *printer) indentPrintf(format string, args ...interface{}) {
|
||||
text := fmt.Sprintf(format, args...)
|
||||
p.indentPrint(text)
|
||||
}
|
||||
|
||||
func (p *printer) colorPrint(text string, color uint16) {
|
||||
p.print(p.colorize(text, color))
|
||||
}
|
||||
|
||||
func (p *printer) printString() {
|
||||
quoted := strconv.Quote(p.value.String())
|
||||
quoted = quoted[1 : len(quoted)-1]
|
||||
|
||||
p.colorPrint(`"`, p.currentScheme.StringQuotation)
|
||||
for len(quoted) > 0 {
|
||||
pos := strings.IndexByte(quoted, '\\')
|
||||
if pos == -1 {
|
||||
p.colorPrint(quoted, p.currentScheme.String)
|
||||
break
|
||||
}
|
||||
if pos != 0 {
|
||||
p.colorPrint(quoted[0:pos], p.currentScheme.String)
|
||||
}
|
||||
|
||||
n := 1
|
||||
switch quoted[pos+1] {
|
||||
case 'x': // "\x00"
|
||||
n = 3
|
||||
case 'u': // "\u0000"
|
||||
n = 5
|
||||
case 'U': // "\U00000000"
|
||||
n = 9
|
||||
case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9': // "\000"
|
||||
n = 3
|
||||
}
|
||||
p.colorPrint(quoted[pos:pos+n+1], p.currentScheme.EscapedChar)
|
||||
quoted = quoted[pos+n+1:]
|
||||
}
|
||||
p.colorPrint(`"`, p.currentScheme.StringQuotation)
|
||||
}
|
||||
|
||||
func (p *printer) printMap() {
|
||||
if p.value.Len() == 0 {
|
||||
p.printf("%s{}", p.typeString())
|
||||
return
|
||||
}
|
||||
|
||||
if p.visited[p.value.Pointer()] {
|
||||
p.printf("%s{...}", p.typeString())
|
||||
return
|
||||
}
|
||||
p.visited[p.value.Pointer()] = true
|
||||
|
||||
if PrintMapTypes {
|
||||
p.printf("%s{\n", p.typeString())
|
||||
} else {
|
||||
p.println("{")
|
||||
}
|
||||
p.indented(func() {
|
||||
value := sortMap(p.value)
|
||||
for i := 0; i < value.Len(); i++ {
|
||||
p.indentPrintf("%s:\t%s,\n", p.format(value.keys[i]), p.format(value.values[i]))
|
||||
}
|
||||
})
|
||||
p.indentPrint("}")
|
||||
}
|
||||
|
||||
func (p *printer) printStruct() {
|
||||
if p.value.CanInterface() {
|
||||
if p.value.Type().String() == "time.Time" && p.value.Type().PkgPath() == "time" {
|
||||
p.printTime()
|
||||
return
|
||||
} else if p.value.Type().String() == "big.Int" {
|
||||
bigInt := p.value.Interface().(big.Int)
|
||||
p.print(p.colorize(bigInt.String(), p.currentScheme.Integer))
|
||||
return
|
||||
} else if p.value.Type().String() == "big.Float" {
|
||||
bigFloat := p.value.Interface().(big.Float)
|
||||
p.print(p.colorize(bigFloat.String(), p.currentScheme.Float))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
var fields []int
|
||||
for i := 0; i < p.value.NumField(); i++ {
|
||||
field := p.value.Type().Field(i)
|
||||
value := p.value.Field(i)
|
||||
// ignore unexported if needed
|
||||
if p.exportedOnly && field.PkgPath != "" {
|
||||
continue
|
||||
}
|
||||
// ignore fields if zero value, or explicitly set
|
||||
if tag := field.Tag.Get("pp"); tag != "" {
|
||||
parts := strings.Split(tag, ",")
|
||||
if len(parts) == 2 && parts[1] == "omitempty" && valueIsZero(value) {
|
||||
continue
|
||||
}
|
||||
if parts[0] == "-" {
|
||||
continue
|
||||
}
|
||||
}
|
||||
fields = append(fields, i)
|
||||
}
|
||||
|
||||
if len(fields) == 0 {
|
||||
p.print(p.typeString() + "{}")
|
||||
return
|
||||
}
|
||||
|
||||
p.println(p.typeString() + "{")
|
||||
p.indented(func() {
|
||||
for _, i := range fields {
|
||||
field := p.value.Type().Field(i)
|
||||
value := p.value.Field(i)
|
||||
|
||||
fieldName := field.Name
|
||||
if tag := field.Tag.Get("pp"); tag != "" {
|
||||
tagName := strings.Split(tag, ",")
|
||||
if tagName[0] != "" {
|
||||
fieldName = tagName[0]
|
||||
}
|
||||
}
|
||||
|
||||
colorizedFieldName := p.colorize(fieldName, p.currentScheme.FieldName)
|
||||
p.indentPrintf("%s:\t%s,\n", colorizedFieldName, p.format(value))
|
||||
}
|
||||
})
|
||||
p.indentPrint("}")
|
||||
}
|
||||
|
||||
func (p *printer) printTime() {
|
||||
tm := p.value.Interface().(time.Time)
|
||||
p.printf(
|
||||
"%s-%s-%s %s:%s:%s %s",
|
||||
p.colorize(strconv.Itoa(tm.Year()), p.currentScheme.Time),
|
||||
p.colorize(fmt.Sprintf("%02d", tm.Month()), p.currentScheme.Time),
|
||||
p.colorize(fmt.Sprintf("%02d", tm.Day()), p.currentScheme.Time),
|
||||
p.colorize(fmt.Sprintf("%02d", tm.Hour()), p.currentScheme.Time),
|
||||
p.colorize(fmt.Sprintf("%02d", tm.Minute()), p.currentScheme.Time),
|
||||
p.colorize(fmt.Sprintf("%02d", tm.Second()), p.currentScheme.Time),
|
||||
p.colorize(tm.Location().String(), p.currentScheme.Time),
|
||||
)
|
||||
}
|
||||
|
||||
func (p *printer) printSlice() {
|
||||
if p.value.Kind() == reflect.Slice && p.value.IsNil() {
|
||||
p.printf("%s(%s)", p.typeString(), p.nil())
|
||||
return
|
||||
}
|
||||
if p.value.Len() == 0 {
|
||||
p.printf("%s{}", p.typeString())
|
||||
return
|
||||
}
|
||||
|
||||
if p.value.Kind() == reflect.Slice {
|
||||
if p.visited[p.value.Pointer()] {
|
||||
// Stop travarsing cyclic reference
|
||||
p.printf("%s{...}", p.typeString())
|
||||
return
|
||||
}
|
||||
p.visited[p.value.Pointer()] = true
|
||||
}
|
||||
|
||||
// Fold a large buffer
|
||||
if p.value.Len() > BufferFoldThreshold {
|
||||
p.printf("%s{...}", p.typeString())
|
||||
return
|
||||
}
|
||||
|
||||
p.println(p.typeString() + "{")
|
||||
p.indented(func() {
|
||||
groupsize := 0
|
||||
switch p.value.Type().Elem().Kind() {
|
||||
case reflect.Uint8:
|
||||
groupsize = 16
|
||||
case reflect.Uint16:
|
||||
groupsize = 8
|
||||
case reflect.Uint32:
|
||||
groupsize = 8
|
||||
case reflect.Uint64:
|
||||
groupsize = 4
|
||||
}
|
||||
|
||||
if groupsize > 0 {
|
||||
for i := 0; i < p.value.Len(); i++ {
|
||||
// indent for new group
|
||||
if i%groupsize == 0 {
|
||||
p.print(p.indent())
|
||||
}
|
||||
// slice element
|
||||
p.printf("%s,", p.format(p.value.Index(i)))
|
||||
// space or newline
|
||||
if (i+1)%groupsize == 0 || i+1 == p.value.Len() {
|
||||
p.print("\n")
|
||||
} else {
|
||||
p.print(" ")
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for i := 0; i < p.value.Len(); i++ {
|
||||
p.indentPrintf("%s,\n", p.format(p.value.Index(i)))
|
||||
}
|
||||
}
|
||||
})
|
||||
p.indentPrint("}")
|
||||
}
|
||||
|
||||
func (p *printer) printInterface() {
|
||||
e := p.value.Elem()
|
||||
if e.Kind() == reflect.Invalid {
|
||||
p.print(p.nil())
|
||||
} else if e.IsValid() {
|
||||
p.print(p.format(e))
|
||||
} else {
|
||||
p.printf("%s(%s)", p.typeString(), p.nil())
|
||||
}
|
||||
}
|
||||
|
||||
func (p *printer) printPtr() {
|
||||
if p.visited[p.value.Pointer()] {
|
||||
p.printf("&%s{...}", p.elemTypeString())
|
||||
return
|
||||
}
|
||||
if p.value.Pointer() != 0 {
|
||||
p.visited[p.value.Pointer()] = true
|
||||
}
|
||||
|
||||
if p.value.Elem().IsValid() {
|
||||
p.printf("&%s", p.format(p.value.Elem()))
|
||||
} else {
|
||||
p.printf("(%s)(%s)", p.typeString(), p.nil())
|
||||
}
|
||||
}
|
||||
|
||||
func (p *printer) pointerAddr() string {
|
||||
return p.colorize(fmt.Sprintf("%#v", p.value.Pointer()), p.currentScheme.PointerAdress)
|
||||
}
|
||||
|
||||
func (p *printer) typeString() string {
|
||||
return p.colorizeType(p.value.Type().String())
|
||||
}
|
||||
|
||||
func (p *printer) elemTypeString() string {
|
||||
return p.colorizeType(p.value.Elem().Type().String())
|
||||
}
|
||||
|
||||
func (p *printer) colorizeType(t string) string {
|
||||
prefix := ""
|
||||
|
||||
if p.matchRegexp(t, `^\[\].+$`) {
|
||||
prefix = "[]"
|
||||
t = t[2:]
|
||||
}
|
||||
|
||||
if p.matchRegexp(t, `^\[\d+\].+$`) {
|
||||
num := regexp.MustCompile(`\d+`).FindString(t)
|
||||
prefix = fmt.Sprintf("[%s]", p.colorize(num, p.currentScheme.ObjectLength))
|
||||
t = t[2+len(num):]
|
||||
}
|
||||
|
||||
if p.matchRegexp(t, `^[^\.]+\.[^\.]+$`) {
|
||||
ts := strings.Split(t, ".")
|
||||
t = fmt.Sprintf("%s.%s", ts[0], p.colorize(ts[1], p.currentScheme.StructName))
|
||||
} else {
|
||||
t = p.colorize(t, p.currentScheme.StructName)
|
||||
}
|
||||
return prefix + t
|
||||
}
|
||||
|
||||
func (p *printer) matchRegexp(text, exp string) bool {
|
||||
return regexp.MustCompile(exp).MatchString(text)
|
||||
}
|
||||
|
||||
func (p *printer) indented(proc func()) {
|
||||
p.depth++
|
||||
if p.maxDepth == -1 || p.depth <= p.maxDepth {
|
||||
proc()
|
||||
}
|
||||
p.depth--
|
||||
}
|
||||
|
||||
func (p *printer) fmtOrLocalizedSprintf(format string, a ...interface{}) string {
|
||||
if p.localizedPrinter == nil {
|
||||
return fmt.Sprintf(format, a...)
|
||||
}
|
||||
|
||||
return p.localizedPrinter.Sprintf(format, a...)
|
||||
}
|
||||
|
||||
func (p *printer) raw() string {
|
||||
// Some value causes panic when Interface() is called.
|
||||
switch p.value.Kind() {
|
||||
case reflect.Bool:
|
||||
return fmt.Sprintf("%#v", p.value.Bool())
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||
return p.fmtOrLocalizedSprintf("%v", p.value.Int())
|
||||
case reflect.Uint, reflect.Uintptr:
|
||||
if p.decimalUint {
|
||||
return p.fmtOrLocalizedSprintf("%d", p.value.Uint())
|
||||
} else {
|
||||
return fmt.Sprintf("%#v", p.value.Uint())
|
||||
}
|
||||
case reflect.Uint8:
|
||||
if p.decimalUint {
|
||||
return fmt.Sprintf("%d", p.value.Uint())
|
||||
} else {
|
||||
return fmt.Sprintf("0x%02x", p.value.Uint())
|
||||
}
|
||||
case reflect.Uint16:
|
||||
if p.decimalUint {
|
||||
return p.fmtOrLocalizedSprintf("%d", p.value.Uint())
|
||||
} else {
|
||||
return fmt.Sprintf("0x%04x", p.value.Uint())
|
||||
}
|
||||
case reflect.Uint32:
|
||||
if p.decimalUint {
|
||||
return p.fmtOrLocalizedSprintf("%d", p.value.Uint())
|
||||
} else {
|
||||
return fmt.Sprintf("0x%08x", p.value.Uint())
|
||||
}
|
||||
case reflect.Uint64:
|
||||
if p.decimalUint {
|
||||
return p.fmtOrLocalizedSprintf("%d", p.value.Uint())
|
||||
} else {
|
||||
return fmt.Sprintf("0x%016x", p.value.Uint())
|
||||
}
|
||||
case reflect.Float32, reflect.Float64:
|
||||
return p.fmtOrLocalizedSprintf("%f", p.value.Float())
|
||||
case reflect.Complex64, reflect.Complex128:
|
||||
return fmt.Sprintf("%#v", p.value.Complex())
|
||||
default:
|
||||
return fmt.Sprintf("%#v", p.value.Interface())
|
||||
}
|
||||
}
|
||||
|
||||
func (p *printer) nil() string {
|
||||
return p.colorize("nil", p.currentScheme.Nil)
|
||||
}
|
||||
|
||||
func (p *printer) colorize(text string, color uint16) string {
|
||||
if ColoringEnabled && p.coloringEnabled {
|
||||
return colorizeText(text, color)
|
||||
} else {
|
||||
return text
|
||||
}
|
||||
}
|
||||
|
||||
func (p *printer) format(object interface{}) string {
|
||||
pp := newPrinter(object, p.currentScheme, p.maxDepth, p.coloringEnabled, p.decimalUint, p.exportedOnly, p.thousandsSeparator)
|
||||
pp.depth = p.depth
|
||||
pp.visited = p.visited
|
||||
if value, ok := object.(reflect.Value); ok {
|
||||
pp.value = value
|
||||
}
|
||||
return pp.String()
|
||||
}
|
||||
|
||||
func (p *printer) indent() string {
|
||||
return strings.Repeat("\t", p.depth)
|
||||
}
|
||||
|
||||
// valueIsZero reports whether v is the zero value for its type.
|
||||
// It returns false if the argument is invalid.
|
||||
// This is a copy paste of reflect#IsZero from go1.15. It is not present before go1.13 (source: https://golang.org/doc/go1.13#library)
|
||||
// source: https://golang.org/src/reflect/value.go?s=34297:34325#L1090
|
||||
// This will need to be updated for new types or the decision should be made to drop support for Go version pre go1.13
|
||||
func valueIsZero(v reflect.Value) bool {
|
||||
switch v.Kind() {
|
||||
case reflect.Bool:
|
||||
return !v.Bool()
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||
return v.Int() == 0
|
||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
|
||||
return v.Uint() == 0
|
||||
case reflect.Float32, reflect.Float64:
|
||||
return math.Float64bits(v.Float()) == 0
|
||||
case reflect.Complex64, reflect.Complex128:
|
||||
c := v.Complex()
|
||||
return math.Float64bits(real(c)) == 0 && math.Float64bits(imag(c)) == 0
|
||||
case reflect.Array:
|
||||
for i := 0; i < v.Len(); i++ {
|
||||
if !valueIsZero(v.Index(i)) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
case reflect.Chan, reflect.Func, reflect.Interface, reflect.Map, reflect.Ptr, reflect.Slice, reflect.UnsafePointer:
|
||||
return v.IsNil()
|
||||
case reflect.String:
|
||||
return v.Len() == 0
|
||||
case reflect.Struct:
|
||||
for i := 0; i < v.NumField(); i++ {
|
||||
if !valueIsZero(v.Field(i)) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
default:
|
||||
// this is the only difference between stdlib reflect#IsZero and this function. We're not going to
|
||||
// panic on the default cause, even
|
||||
return false
|
||||
}
|
||||
}
|
||||
76
vendor/github.com/k0kubun/pp/v3/sort.go
generated
vendored
Normal file
76
vendor/github.com/k0kubun/pp/v3/sort.go
generated
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
// sort.go: Implementation for sorting map keys
|
||||
package pp
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"sort"
|
||||
)
|
||||
|
||||
func sortMap(value reflect.Value) *sortedMap {
|
||||
if value.Type().Kind() != reflect.Map {
|
||||
panic("sortMap is used for a non-Map value")
|
||||
}
|
||||
|
||||
keys := make([]reflect.Value, 0, value.Len())
|
||||
values := make([]reflect.Value, 0, value.Len())
|
||||
mapKeys := value.MapKeys()
|
||||
for i := 0; i < len(mapKeys); i++ {
|
||||
keys = append(keys, mapKeys[i])
|
||||
values = append(values, value.MapIndex(mapKeys[i]))
|
||||
}
|
||||
|
||||
sorted := &sortedMap{
|
||||
keys: keys,
|
||||
values: values,
|
||||
}
|
||||
sort.Stable(sorted)
|
||||
return sorted
|
||||
}
|
||||
|
||||
type sortedMap struct {
|
||||
keys []reflect.Value
|
||||
values []reflect.Value
|
||||
}
|
||||
|
||||
// Functions for sort.Interface
|
||||
|
||||
func (s *sortedMap) Len() int {
|
||||
return len(s.keys)
|
||||
}
|
||||
|
||||
func (s *sortedMap) Swap(i, j int) {
|
||||
s.keys[i], s.keys[j] = s.keys[j], s.keys[i]
|
||||
s.values[i], s.values[j] = s.values[j], s.values[i]
|
||||
}
|
||||
|
||||
func (s *sortedMap) Less(i, j int) bool {
|
||||
a, b := s.keys[i], s.keys[j]
|
||||
if a.Type() != b.Type() {
|
||||
return false // give up
|
||||
}
|
||||
|
||||
// Return true if b is bigger
|
||||
switch a.Kind() {
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||
return a.Int() < b.Int()
|
||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
|
||||
return a.Uint() < b.Uint()
|
||||
case reflect.String:
|
||||
return a.String() < b.String()
|
||||
case reflect.Float32, reflect.Float64:
|
||||
if a.Float() != a.Float() || b.Float() != b.Float() {
|
||||
return false // NaN
|
||||
}
|
||||
return a.Float() < b.Float()
|
||||
case reflect.Bool:
|
||||
return !a.Bool() && b.Bool()
|
||||
case reflect.Ptr:
|
||||
return a.Pointer() < b.Pointer()
|
||||
case reflect.Struct:
|
||||
return a.NumField() < b.NumField()
|
||||
case reflect.Array:
|
||||
return a.Len() < b.Len()
|
||||
default:
|
||||
return false // not supported yet
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user