vendor in deps so CI goes fast

This commit is contained in:
2022-02-01 21:36:27 -08:00
committed by user
parent 7a47873be3
commit 081028f3b2
646 changed files with 247908 additions and 0 deletions

21
vendor/github.com/pterm/pterm/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,21 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
# Test binary, built with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# Dependency directories (remove the comment below to include it)
vendor/
# This is where we test stuff
/experimenting/
/.history
/.vscode

92
vendor/github.com/pterm/pterm/.golangci.yml generated vendored Normal file
View File

@@ -0,0 +1,92 @@
linters-settings:
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
disabled-checks:
- dupImport
- ifElseChain
- octalLiteral
- whyNoLint
- wrapperFunc
- exitAfterDefer
- hugeParam
- ptrToRefParam
- paramTypeCombine
- unnamedResult
# maligned:
# suggest-new: true
misspell:
locale: US
linters:
disable-all: true
enable:
- gocritic
- gosec
- govet
- ineffassign
- interfacer
- unconvert
- gosimple
- godox
- whitespace
- staticcheck
# - bodyclose
# - maligned
# - godot
# - deadcode
# - depguard
# - dogsled
# - dupl
# - errcheck
# - exhaustive
# - funlen
# - gochecknoinits
# - goconst
# - gocyclo
# - gofmt
# - goimports
# - golint
# - gomnd
# - goprintffuncname
# - lll
# - misspell
# - nakedret
# - noctx
# - nolintlint
# - rowserrcheck
# - scopelint
# - structcheck
# - stylecheck
# - typecheck
# - unparam
# - unused
# - varcheck
# - whitespace
# - asciicheck
# - gochecknoglobals
# - gocognit
# - goerr113
# - nestif
# - prealloc
# - testpackage
# - wsl
issues:
# Excluding configuration per-path, per-linter, per-text and per-source
exclude-rules:
- path: _test\.go
linters:
- gocyclo
- errcheck
- dupl
- gosec
- gocritic
# https://github.com/go-critic/go-critic/issues/926
- linters:
- gocritic
text: "unnecessaryDefer:"
service:
golangci-lint-version: 1.31.x # use the fixed version to not introduce new linters unexpectedly

1003
vendor/github.com/pterm/pterm/CHANGELOG.md generated vendored Normal file

File diff suppressed because it is too large Load Diff

76
vendor/github.com/pterm/pterm/CODE_OF_CONDUCT.md generated vendored Normal file
View File

@@ -0,0 +1,76 @@
# Contributor Covenant Code of Conduct
## Our Pledge
In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, sex characteristics, gender identity and expression,
level of experience, education, socio-economic status, nationality, personal
appearance, race, religion, or sexual identity and orientation.
## Our Standards
Examples of behavior that contributes to creating a positive environment
include:
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
## Our Responsibilities
Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.
Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.
## Scope
This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at pterm@marvinjwendt.com. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.
Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
[homepage]: https://www.contributor-covenant.org
For answers to common questions about this code of conduct, see
https://www.contributor-covenant.org/faq

217
vendor/github.com/pterm/pterm/CONTRIBUTING.md generated vendored Normal file
View File

@@ -0,0 +1,217 @@
# Contributing to PTerm
> This document explains how to participate in the development of PTerm.\
If your goal is to report a bug instead of programming PTerm, you can do so [here](https://github.com/pterm/pterm/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc).
## Creating a new printer
> In this chapter we will show you how to create a new printer.
### `TextPrinter` Template
```go
package pterm
type TemplatePrinter struct{
// TODO: Add printer settings here
}
// Sprint formats using the default formats for its operands and returns the resulting string.
// Spaces are added between operands when neither is a string.
func (p TemplatePrinter) Sprint(a ...interface{}) string {
panic("write printer code here")
}
// Sprintln formats using the default formats for its operands and returns the resulting string.
// Spaces are always added between operands and a newline is appended.
func (p TemplatePrinter) Sprintln(a ...interface{}) string {
return Sprintln(p.Sprint(a...))
}
// Sprintf formats according to a format specifier and returns the resulting string.
func (p TemplatePrinter) Sprintf(format string, a ...interface{}) string {
return p.Sprint(Sprintf(format, a...))
}
// Print formats using the default formats for its operands and writes to standard output.
// Spaces are added between operands when neither is a string.
// It returns the number of bytes written and any write error encountered.
func (p TemplatePrinter) Print(a ...interface{}) *TextPrinter {
Print(p.Sprint(a...))
tp := TextPrinter(p)
return &tp
}
// Println formats using the default formats for its operands and writes to standard output.
// Spaces are always added between operands and a newline is appended.
// It returns the number of bytes written and any write error encountered.
func (p TemplatePrinter) Println(a ...interface{}) *TextPrinter {
Println(p.Sprint(a...))
tp := TextPrinter(p)
return &tp
}
// Printf formats according to a format specifier and writes to standard output.
// It returns the number of bytes written and any write error encountered.
func (p TemplatePrinter) Printf(format string, a ...interface{}) *TextPrinter {
Print(p.Sprintf(format, a...))
tp := TextPrinter(p)
return &tp
}
```
### `RenderablePrinter` Template
```go
package pterm
type TemplatePrinter struct{
// TODO: Add printer settings here
}
// Srender renders the Template as a string.
func (p TemplatePrinter) Srender() (string, error) {
var ret string
return ret, nil
}
// Render prints the Template to the terminal.
func (p TemplatePrinter) Render() error {
s, err := p.Srender()
if err != nil {
return err
}
Println(s)
return nil
}
```
### `LivePrinter` Template
```go
// Start the TemplatePrinter.
package pterm
import "github.com/pterm/pterm"
type TemplatePrinter struct{
}
func (s TemplatePrinter) Start(text...interface{}) (*TemplatePrinter, error) { // TODO: Replace Template with actual printer.
// TODO: start logic
return &s, nil
}
// Stop terminates the TemplatePrinter immediately.
// The TemplatePrinter will not resolve into anything.
func (s *TemplatePrinter) Stop() error {
// TODO: stop logic
return nil
}
// GenericStart runs Start, but returns a LivePrinter.
// This is used for the interface LivePrinter.
// You most likely want to use Start instead of this in your program.
func (s *TemplatePrinter) GenericStart() (*LivePrinter, error) {
_, err := s.Start()
lp := LivePrinter(s)
return &lp, err
}
// GenericStop runs Stop, but returns a LivePrinter.
// This is used for the interface LivePrinter.
// You most likely want to use Stop instead of this in your program.
func (s *TemplatePrinter) GenericStop() (*LivePrinter, error) {
err := s.Stop()
lp := LivePrinter(s)
return &lp, err
}
```
## Writing Tests
> Each method of PTerm must be tested.
### Required tests for every printer
#### Nil Check
> This ensures that a printer without set values will not produce errors.
```go
func TestTemplatePrinterNilPrint(t *testing.T) { // TODO: Replace "Template" with actual printer name.
p := TemplatePrinter{} // TODO: Replace "Template" with actual printer name.
p.Println("Hello, World!")
}
```
#### `WithXxx()` Methods
> Each method, which starts with `With` can be tested by checking if it actually creates a new printer and sets the value.
Example from `SectionPrinter`:
```go
func TestSectionPrinter_WithStyle(t *testing.T) {
p := SectionPrinter{}
s := NewStyle(FgRed, BgRed, Bold)
p2 := p.WithStyle(s)
assert.Equal(t, s, p2.Style)
assert.Empty(t, p.Style)
}
func TestSectionPrinter_WithTopPadding(t *testing.T) {
p := SectionPrinter{}
p2 := p.WithTopPadding(1337)
assert.Equal(t, 1337, p2.TopPadding)
assert.Empty(t, p.TopPadding)
}
```
### `TextPrinter` Tests Template
```go
func TestTemplatePrinterPrintMethods(t *testing.T) { // TODO: Replace "Template" with actual printer name.
p := DefaultTemplate // TODO: Replace "Template" with actual printer name.
t.Run("Print", func(t *testing.T) {
testPrintContains(t, func(w io.Writer, a interface{}) {
p.Print(a)
})
})
t.Run("Printf", func(t *testing.T) {
testPrintfContains(t, func(w io.Writer, format string, a interface{}) {
p.Printf(format, a)
})
})
t.Run("Println", func(t *testing.T) {
testPrintlnContains(t, func(w io.Writer, a interface{}) {
p.Println(a)
})
})
t.Run("Sprint", func(t *testing.T) {
testSprintContains(t, func(a interface{}) string {
return p.Sprint(a)
})
})
t.Run("Sprintf", func(t *testing.T) {
testSprintfContains(t, func(format string, a interface{}) string {
return p.Sprintf(format, a)
})
})
t.Run("Sprintln", func(t *testing.T) {
testSprintlnContains(t, func(a interface{}) string {
return p.Sprintln(a)
})
})
}
```

21
vendor/github.com/pterm/pterm/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2020 pterm
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.

1827
vendor/github.com/pterm/pterm/README.md generated vendored Normal file

File diff suppressed because it is too large Load Diff

130
vendor/github.com/pterm/pterm/area_printer.go generated vendored Normal file
View File

@@ -0,0 +1,130 @@
package pterm
import (
"strings"
"github.com/atomicgo/cursor"
"github.com/pterm/pterm/internal"
)
// DefaultArea is the default area printer.
var DefaultArea = AreaPrinter{}
// AreaPrinter prints an area which can be updated easily.
// use this printer for live output like charts, algorithm visualizations, simulations and even games.
type AreaPrinter struct {
RemoveWhenDone bool
Fullscreen bool
Center bool
content string
isActive bool
area *cursor.Area
}
// GetContent returns the current area content.
func (p *AreaPrinter) GetContent() string {
return p.content
}
// WithRemoveWhenDone removes the AreaPrinter content after it is stopped.
func (p AreaPrinter) WithRemoveWhenDone(b ...bool) *AreaPrinter {
p.RemoveWhenDone = internal.WithBoolean(b)
return &p
}
// WithFullscreen sets the AreaPrinter height the same height as the terminal, making it fullscreen.
func (p AreaPrinter) WithFullscreen(b ...bool) *AreaPrinter {
p.Fullscreen = internal.WithBoolean(b)
return &p
}
// WithCenter centers the AreaPrinter content to the terminal.
func (p AreaPrinter) WithCenter(b ...bool) *AreaPrinter {
p.Center = internal.WithBoolean(b)
return &p
}
// Update overwrites the content of the AreaPrinter.
// Can be used live.
func (p *AreaPrinter) Update(text ...interface{}) {
if p.area == nil {
newArea := cursor.NewArea()
p.area = &newArea
}
str := Sprint(text...)
p.content = str
if p.Center {
str = DefaultCenter.Sprint(str)
}
if p.Fullscreen {
str = strings.TrimRight(str, "\n")
height := GetTerminalHeight()
contentHeight := strings.Count(str, "\n")
topPadding := 0
bottomPadding := height - contentHeight - 2
if p.Center {
topPadding = (bottomPadding / 2) + 1
bottomPadding /= 2
}
if height > contentHeight {
str = strings.Repeat("\n", topPadding) + str
str += strings.Repeat("\n", bottomPadding)
}
}
p.area.Update(str)
}
// Start the AreaPrinter.
func (p *AreaPrinter) Start(text ...interface{}) (*AreaPrinter, error) {
p.isActive = true
str := Sprint(text...)
newArea := cursor.NewArea()
p.area = &newArea
p.Update(str)
return p, nil
}
// Stop terminates the AreaPrinter immediately.
// The AreaPrinter will not resolve into anything.
func (p *AreaPrinter) Stop() error {
p.isActive = false
if p.RemoveWhenDone {
p.Clear()
}
return nil
}
// GenericStart runs Start, but returns a LivePrinter.
// This is used for the interface LivePrinter.
// You most likely want to use Start instead of this in your program.
func (p *AreaPrinter) GenericStart() (*LivePrinter, error) {
_, _ = p.Start()
lp := LivePrinter(p)
return &lp, nil
}
// GenericStop runs Stop, but returns a LivePrinter.
// This is used for the interface LivePrinter.
// You most likely want to use Stop instead of this in your program.
func (p *AreaPrinter) GenericStop() (*LivePrinter, error) {
_ = p.Stop()
lp := LivePrinter(p)
return &lp, nil
}
// Wrapper function that clears the content of the Area.
// Moves the cursor to the bottom of the terminal, clears n lines upwards from
// the current position and moves the cursor again.
func (p *AreaPrinter) Clear() {
p.area.Clear()
}

36
vendor/github.com/pterm/pterm/atoms.go generated vendored Normal file
View File

@@ -0,0 +1,36 @@
package pterm
// Bars is used to display multiple Bar.
type Bars []Bar
// Bar is used in bar charts.
type Bar struct {
Label string
Value int
Style *Style
LabelStyle *Style
}
// WithLabel returns a new Bar with a specific option.
func (p Bar) WithLabel(s string) *Bar {
p.Label = s
return &p
}
// WithLabelStyle returns a new Bar with a specific option.
func (p Bar) WithLabelStyle(style *Style) *Bar {
p.LabelStyle = style
return &p
}
// WithValue returns a new Bar with a specific option.
func (p Bar) WithValue(value int) *Bar {
p.Value = value
return &p
}
// WithStyle returns a new Bar with a specific option.
func (p Bar) WithStyle(style *Style) *Bar {
p.Style = style
return &p
}

416
vendor/github.com/pterm/pterm/barchart.go generated vendored Normal file
View File

@@ -0,0 +1,416 @@
package pterm
import (
"strconv"
"strings"
"github.com/mattn/go-runewidth"
"github.com/pterm/pterm/internal"
)
// BarChartPrinter is used to print bar charts.
type BarChartPrinter struct {
Bars Bars
Horizontal bool
ShowValue bool
// Height sets the maximum height of a vertical bar chart.
// The default is calculated to fit into the terminal.
// Ignored if Horizontal is set to true.
Height int
// Width sets the maximum width of a horizontal bar chart.
// The default is calculated to fit into the terminal.
// Ignored if Horizontal is set to false.
Width int
VerticalBarCharacter string
HorizontalBarCharacter string
}
var (
// DefaultBarChart is the default BarChartPrinter.
DefaultBarChart = BarChartPrinter{
Horizontal: false,
VerticalBarCharacter: "██",
HorizontalBarCharacter: "█",
// keep in sync with RecalculateTerminalSize()
Height: GetTerminalHeight() * 2 / 3,
Width: GetTerminalWidth() * 2 / 3,
}
)
// WithBars returns a new BarChartPrinter with a specific option.
func (p BarChartPrinter) WithBars(bars Bars) *BarChartPrinter {
p.Bars = bars
return &p
}
// WithVerticalBarCharacter returns a new BarChartPrinter with a specific option.
func (p BarChartPrinter) WithVerticalBarCharacter(char string) *BarChartPrinter {
p.VerticalBarCharacter = char
return &p
}
// WithHorizontalBarCharacter returns a new BarChartPrinter with a specific option.
func (p BarChartPrinter) WithHorizontalBarCharacter(char string) *BarChartPrinter {
p.HorizontalBarCharacter = char
return &p
}
// WithHorizontal returns a new BarChartPrinter with a specific option.
func (p BarChartPrinter) WithHorizontal(b ...bool) *BarChartPrinter {
b2 := internal.WithBoolean(b)
p.Horizontal = b2
return &p
}
// WithHeight returns a new BarChartPrinter with a specific option.
func (p BarChartPrinter) WithHeight(value int) *BarChartPrinter {
p.Height = value
return &p
}
// WithWidth returns a new BarChartPrinter with a specific option.
func (p BarChartPrinter) WithWidth(value int) *BarChartPrinter {
p.Width = value
return &p
}
// WithShowValue returns a new BarChartPrinter with a specific option.
func (p BarChartPrinter) WithShowValue(b ...bool) *BarChartPrinter {
p.ShowValue = internal.WithBoolean(b)
return &p
}
func (p BarChartPrinter) getRawOutput() string {
var ret string
for _, bar := range p.Bars {
ret += Sprintfln("%s: %d", bar.Label, bar.Value)
}
return ret
}
// Srender renders the BarChart as a string.
func (p BarChartPrinter) Srender() (string, error) {
maxAbsValue := func(value1 int, value2 int) int {
min := value1
max := value2
if value1 > value2 {
min = value2
max = value1
}
maxAbs := max
if min < 0 && -min > max { // This is to avoid something like "int(math.Abs(float64(minBarValue)))"
maxAbs = -min // (--) == (+)
}
return maxAbs
}
abs := func(value int) int {
if value < 0 {
return -value
}
return value
}
// =================================== VERTICAL BARS RENDERER ======================================================
type renderParams struct {
repeatCount int
bar Bar
positiveChartPartHeight int
negativeChartPartHeight int
positiveChartPartWidth int
negativeChartPartWidth int
indent string
showValue bool
moveUp bool
moveRight bool
}
renderPositiveVerticalBar := func(renderedBarRef *string, rParams renderParams) {
if rParams.showValue {
*renderedBarRef += Sprint(rParams.indent + strconv.Itoa(rParams.bar.Value) + rParams.indent + "\n")
}
for i := rParams.positiveChartPartHeight; i > 0; i-- {
if i > rParams.repeatCount {
*renderedBarRef += rParams.indent + " " + rParams.indent + " \n"
} else {
*renderedBarRef += rParams.indent + rParams.bar.Style.Sprint(p.VerticalBarCharacter) + rParams.indent + " \n"
}
}
// Used when we draw diagram with both POSITIVE and NEGATIVE values.
// In such case we separately draw top and bottom half of chart.
// And we need MOVE UP positive part to top part of chart,
// technically by adding empty pillars with height == height of chart's bottom part.
if rParams.moveUp {
for i := 0; i <= rParams.negativeChartPartHeight; i++ {
*renderedBarRef += rParams.indent + " " + rParams.indent + " \n"
}
}
}
renderNegativeVerticalBar := func(renderedBarRef *string, rParams renderParams) {
for i := 0; i > -rParams.negativeChartPartHeight; i-- {
if i > rParams.repeatCount {
*renderedBarRef += rParams.indent + rParams.bar.Style.Sprint(p.VerticalBarCharacter) + rParams.indent + " \n"
} else {
*renderedBarRef += rParams.indent + " " + rParams.indent + " \n"
}
}
if rParams.showValue {
*renderedBarRef += Sprint(rParams.indent + strconv.Itoa(rParams.bar.Value) + rParams.indent + "\n")
}
}
// =================================== HORIZONTAL BARS RENDERER ====================================================
renderPositiveHorizontalBar := func(renderedBarRef *string, rParams renderParams) {
if rParams.moveRight {
for i := 0; i < rParams.negativeChartPartWidth; i++ {
*renderedBarRef += " "
}
}
for i := 0; i < rParams.positiveChartPartWidth; i++ {
if i < rParams.repeatCount {
*renderedBarRef += rParams.bar.Style.Sprint(p.HorizontalBarCharacter)
} else {
*renderedBarRef += " "
}
}
if rParams.showValue {
// For positive horizontal bars we add one more space before adding value,
// so they will be well aligned with negative values, which have "-" sign before them
*renderedBarRef += " "
*renderedBarRef += " " + strconv.Itoa(rParams.bar.Value)
}
}
renderNegativeHorizontalBar := func(renderedBarRef *string, rParams renderParams) {
for i := -rParams.negativeChartPartWidth; i < 0; i++ {
if i < rParams.repeatCount {
*renderedBarRef += " "
} else {
*renderedBarRef += rParams.bar.Style.Sprint(p.HorizontalBarCharacter)
}
}
// In order to print values well-aligned (in case when we have both - positive and negative part of chart),
// we should insert an indent with width == width of positive chart part
if rParams.positiveChartPartWidth > 0 {
for i := 0; i < rParams.positiveChartPartWidth; i++ {
*renderedBarRef += " "
}
}
if rParams.showValue {
/*
This is in order to achieve this effect:
0
-15
0
-19
INSTEAD OF THIS:
0
-15
0
-19
*/
if rParams.repeatCount == 0 {
*renderedBarRef += " "
}
*renderedBarRef += " " + strconv.Itoa(rParams.bar.Value)
}
}
// =================================================================================================================
if RawOutput {
return p.getRawOutput(), nil
}
for i, bar := range p.Bars {
if bar.Style == nil {
p.Bars[i].Style = &ThemeDefault.BarStyle
}
if bar.LabelStyle == nil {
p.Bars[i].LabelStyle = &ThemeDefault.BarLabelStyle
}
p.Bars[i].Label = p.Bars[i].LabelStyle.Sprint(bar.Label)
}
var ret string
var maxLabelHeight int
var maxBarValue int
var minBarValue int
var maxAbsBarValue int
var rParams renderParams
for _, bar := range p.Bars {
if bar.Value > maxBarValue {
maxBarValue = bar.Value
}
if bar.Value < minBarValue {
minBarValue = bar.Value
}
labelHeight := len(strings.Split(bar.Label, "\n"))
if labelHeight > maxLabelHeight {
maxLabelHeight = labelHeight
}
}
maxAbsBarValue = maxAbsValue(maxBarValue, minBarValue)
if p.Horizontal {
panels := Panels{[]Panel{{}, {}}}
rParams.showValue = p.ShowValue
rParams.positiveChartPartWidth = p.Width
rParams.negativeChartPartWidth = p.Width
// If chart will consist of two parts - positive and negative - we should recalculate max bars WIDTH in LEFT and RIGHT parts
if minBarValue < 0 && maxBarValue > 0 {
rParams.positiveChartPartWidth = abs(internal.MapRangeToRange(-float32(maxAbsBarValue), float32(maxAbsBarValue), -float32(p.Width)/2, float32(p.Width)/2, float32(maxBarValue)))
rParams.negativeChartPartWidth = abs(internal.MapRangeToRange(-float32(maxAbsBarValue), float32(maxAbsBarValue), -float32(p.Width)/2, float32(p.Width)/2, float32(minBarValue)))
}
for _, bar := range p.Bars {
rParams.bar = bar
panels[0][0].Data += "\n" + bar.Label
panels[0][1].Data += "\n"
if minBarValue >= 0 {
// As we don't have negative values, draw only positive (right) part of the chart:
rParams.repeatCount = internal.MapRangeToRange(0, float32(maxAbsBarValue), 0, float32(p.Width), float32(bar.Value))
rParams.moveRight = false
renderPositiveHorizontalBar(&panels[0][1].Data, rParams)
} else if maxBarValue <= 0 {
// As we have only negative values, draw only negative (left) part of the chart:
rParams.repeatCount = internal.MapRangeToRange(-float32(maxAbsBarValue), 0, -float32(p.Width), 0, float32(bar.Value))
rParams.positiveChartPartWidth = 0
renderNegativeHorizontalBar(&panels[0][1].Data, rParams)
} else {
// We have positive and negative values, so draw both (left+right) parts of the chart:
rParams.repeatCount = internal.MapRangeToRange(-float32(maxAbsBarValue), float32(maxAbsBarValue), -float32(p.Width)/2, float32(p.Width)/2, float32(bar.Value))
if bar.Value >= 0 {
rParams.moveRight = true
renderPositiveHorizontalBar(&panels[0][1].Data, rParams)
}
if bar.Value < 0 {
renderNegativeHorizontalBar(&panels[0][1].Data, rParams)
}
}
}
ret, _ = DefaultPanel.WithPanels(panels).Srender()
return ret, nil
} else {
renderedBars := make([]string, len(p.Bars))
rParams.showValue = p.ShowValue
rParams.positiveChartPartHeight = p.Height
rParams.negativeChartPartHeight = p.Height
// If chart will consist of two parts - positive and negative - we should recalculate max bars height in top and bottom parts
if minBarValue < 0 && maxBarValue > 0 {
rParams.positiveChartPartHeight = abs(internal.MapRangeToRange(-float32(maxAbsBarValue), float32(maxAbsBarValue), -float32(p.Height)/2, float32(p.Height)/2, float32(maxBarValue)))
rParams.negativeChartPartHeight = abs(internal.MapRangeToRange(-float32(maxAbsBarValue), float32(maxAbsBarValue), -float32(p.Height)/2, float32(p.Height)/2, float32(minBarValue)))
}
for i, bar := range p.Bars {
var renderedBar string
rParams.bar = bar
rParams.indent = strings.Repeat(" ", internal.GetStringMaxWidth(RemoveColorFromString(bar.Label))/2)
if minBarValue >= 0 {
// As we don't have negative values, draw only positive (top) part of the chart:
rParams.repeatCount = internal.MapRangeToRange(0, float32(maxAbsBarValue), 0, float32(p.Height), float32(bar.Value))
rParams.moveUp = false // Don't MOVE UP as we have ONLY positive part of chart.
renderPositiveVerticalBar(&renderedBar, rParams)
} else if maxBarValue <= 0 {
// As we have only negative values, draw only negative (bottom) part of the chart:
rParams.repeatCount = internal.MapRangeToRange(-float32(maxAbsBarValue), 0, -float32(p.Height), 0, float32(bar.Value))
renderNegativeVerticalBar(&renderedBar, rParams)
} else {
// We have positive and negative values, so draw both (top+bottom) parts of the chart:
rParams.repeatCount = internal.MapRangeToRange(-float32(maxAbsBarValue), float32(maxAbsBarValue), -float32(p.Height)/2, float32(p.Height)/2, float32(bar.Value))
if bar.Value >= 0 {
rParams.moveUp = true // MOVE UP positive part, because we have both positive and negative parts of chart.
renderPositiveVerticalBar(&renderedBar, rParams)
}
if bar.Value < 0 {
renderNegativeVerticalBar(&renderedBar, rParams)
}
}
labelHeight := len(strings.Split(bar.Label, "\n"))
renderedBars[i] = renderedBar + bar.Label + strings.Repeat("\n", maxLabelHeight-labelHeight) + " "
}
var maxBarHeight int
for _, bar := range renderedBars {
totalBarHeight := len(strings.Split(bar, "\n"))
if totalBarHeight > maxBarHeight {
maxBarHeight = totalBarHeight
}
}
for i, bar := range renderedBars {
totalBarHeight := len(strings.Split(bar, "\n"))
if totalBarHeight < maxBarHeight {
renderedBars[i] = strings.Repeat("\n", maxBarHeight-totalBarHeight) + renderedBars[i]
}
}
for i := 0; i <= maxBarHeight; i++ {
for _, barString := range renderedBars {
var barLine string
letterLines := strings.Split(barString, "\n")
maxBarWidth := internal.GetStringMaxWidth(RemoveColorFromString(barString))
if len(letterLines) > i {
barLine = letterLines[i]
}
letterLineLength := runewidth.StringWidth(RemoveColorFromString(barLine))
if letterLineLength < maxBarWidth {
barLine += strings.Repeat(" ", maxBarWidth-letterLineLength)
}
ret += barLine
}
ret += "\n"
}
}
return ret, nil
}
// Render prints the Template to the terminal.
func (p BarChartPrinter) Render() error {
s, _ := p.Srender()
Println(s)
return nil
}

114
vendor/github.com/pterm/pterm/basic_text_printer.go generated vendored Normal file
View File

@@ -0,0 +1,114 @@
package pterm
import "fmt"
var (
// DefaultBasicText returns a default BasicTextPrinter, which can be used to print text as is.
// No default style is present for BasicTextPrinter.
DefaultBasicText = BasicTextPrinter{}
)
// BasicTextPrinter is the printer used to print the input as-is or as specified by user formatting.
type BasicTextPrinter struct {
Style *Style
}
// WithStyle adds a style to the printer.
func (p BasicTextPrinter) WithStyle(style *Style) *BasicTextPrinter {
p.Style = style
return &p
}
// Sprint formats using the default formats for its operands and returns the resulting string.
// Spaces are added between operands when neither is a string.
func (p BasicTextPrinter) Sprint(a ...interface{}) string {
if p.Style == nil {
p.Style = NewStyle()
}
return p.Style.Sprint(a...)
}
// Sprintln formats using the default formats for its operands and returns the resulting string.
// Spaces are always added between operands and a newline is appended.
func (p BasicTextPrinter) Sprintln(a ...interface{}) string {
str := fmt.Sprintln(a...)
return Sprintln(p.Sprint(str))
}
// Sprintf formats according to a format specifier and returns the resulting string.
func (p BasicTextPrinter) Sprintf(format string, a ...interface{}) string {
return p.Sprint(Sprintf(format, a...))
}
// Sprintfln formats according to a format specifier and returns the resulting string.
// Spaces are always added between operands and a newline is appended.
func (p BasicTextPrinter) Sprintfln(format string, a ...interface{}) string {
return p.Sprintf(format, a...) + "\n"
}
// Print formats using the default formats for its operands and writes to standard output.
// Spaces are added between operands when neither is a string.
// It returns the number of bytes written and any write error encountered.
func (p *BasicTextPrinter) Print(a ...interface{}) *TextPrinter {
Print(p.Sprint(a...))
tp := TextPrinter(p)
return &tp
}
// Println formats using the default formats for its operands and writes to standard output.
// Spaces are always added between operands and a newline is appended.
// It returns the number of bytes written and any write error encountered.
func (p *BasicTextPrinter) Println(a ...interface{}) *TextPrinter {
Print(p.Sprintln(a...))
tp := TextPrinter(p)
return &tp
}
// Printf formats according to a format specifier and writes to standard output.
// It returns the number of bytes written and any write error encountered.
func (p *BasicTextPrinter) Printf(format string, a ...interface{}) *TextPrinter {
Print(p.Sprintf(format, a...))
tp := TextPrinter(p)
return &tp
}
// Printfln formats according to a format specifier and writes to standard output.
// Spaces are always added between operands and a newline is appended.
// It returns the number of bytes written and any write error encountered.
func (p *BasicTextPrinter) Printfln(format string, a ...interface{}) *TextPrinter {
Print(p.Sprintfln(format, a...))
tp := TextPrinter(p)
return &tp
}
// PrintOnError prints every error which is not nil.
// If every error is nil, nothing will be printed.
// This can be used for simple error checking.
func (p *BasicTextPrinter) PrintOnError(a ...interface{}) *TextPrinter {
for _, arg := range a {
if err, ok := arg.(error); ok {
if err != nil {
p.Println(err)
}
}
}
tp := TextPrinter(p)
return &tp
}
// PrintOnErrorf wraps every error which is not nil and prints it.
// If every error is nil, nothing will be printed.
// This can be used for simple error checking.
func (p *BasicTextPrinter) PrintOnErrorf(format string, a ...interface{}) *TextPrinter {
for _, arg := range a {
if err, ok := arg.(error); ok {
if err != nil {
p.Println(fmt.Errorf(format, err))
}
}
}
tp := TextPrinter(p)
return &tp
}

549
vendor/github.com/pterm/pterm/bigtext_printer.go generated vendored Normal file
View File

@@ -0,0 +1,549 @@
package pterm
import (
"strings"
"github.com/mattn/go-runewidth"
"github.com/pterm/pterm/internal"
)
// Letters is a slice of Letter.
type Letters []Letter
// NewLettersFromString creates a Letters object from a string, which is prefilled with the LetterStyle from ThemeDefault.
// You can override the ThemeDefault LetterStyle if you want to.
func NewLettersFromString(text string) Letters {
return NewLettersFromStringWithStyle(text, &ThemeDefault.LetterStyle)
}
// NewLettersFromStringWithStyle creates a Letters object from a string and applies a Style to it.
func NewLettersFromStringWithStyle(text string, style *Style) Letters {
s := strings.Split(text, "")
l := Letters{}
for _, s2 := range s {
l = append(l, Letter{
String: s2,
Style: style,
})
}
return l
}
// Letter is an object, which holds a string and a specific Style for it.
type Letter struct {
String string
Style *Style
}
// WithStyle returns a new Letter with a specific Style.
func (l Letter) WithStyle(style *Style) *Letter {
l.Style = style
return &l
}
// WithString returns a new Letter with a specific String.
func (l Letter) WithString(s string) *Letter {
l.String = s
return &l
}
// BigTextPrinter renders big text.
// You can use this as title screen for your application.
type BigTextPrinter struct {
// BigCharacters holds the map from a normal character to it's big version.
BigCharacters map[string]string
Letters Letters
}
// WithBigCharacters returns a new BigTextPrinter with specific BigCharacters.
func (p BigTextPrinter) WithBigCharacters(chars map[string]string) *BigTextPrinter {
p.BigCharacters = chars
return &p
}
// WithLetters returns a new BigTextPrinter with specific Letters
func (p BigTextPrinter) WithLetters(letters ...Letters) *BigTextPrinter {
l := Letters{}
for _, letter := range letters {
l = append(l, letter...)
}
p.Letters = l
return &p
}
// Srender renders the BigText as a string.
func (p BigTextPrinter) Srender() (string, error) {
var ret string
if RawOutput {
for _, letter := range p.Letters {
ret += letter.String
}
return ret, nil
}
var bigLetters Letters
for _, l := range p.Letters {
if val, ok := p.BigCharacters[l.String]; ok {
bigLetters = append(bigLetters, Letter{
String: val,
Style: l.Style,
})
}
}
var maxHeight int
for _, l := range bigLetters {
h := strings.Count(l.String, "\n")
if h > maxHeight {
maxHeight = h
}
}
for i := 0; i <= maxHeight; i++ {
for _, letter := range bigLetters {
var letterLine string
letterLines := strings.Split(letter.String, "\n")
maxLetterWidth := internal.GetStringMaxWidth(letter.String)
if len(letterLines) > i {
letterLine = letterLines[i]
}
letterLineLength := runewidth.StringWidth(letterLine)
if letterLineLength < maxLetterWidth {
letterLine += strings.Repeat(" ", maxLetterWidth-letterLineLength)
}
ret += letter.Style.Sprint(letterLine)
}
ret += "\n"
}
return ret, nil
}
// Render prints the BigText to the terminal.
func (p BigTextPrinter) Render() error {
s, _ := p.Srender()
Println(s)
return nil
}
// DefaultBigText contains default values for BigTextPrinter.
var DefaultBigText = BigTextPrinter{
BigCharacters: map[string]string{
"a": ` █████
██ ██
███████
██ ██
██ ██ `,
"A": ` █████
██ ██
███████
██ ██
██ ██ `,
"b": `██████
██ ██
██████
██ ██
██████`,
"B": `██████
██ ██
██████
██ ██
██████`,
"c": ` ██████
██
██
██
██████`,
"C": ` ██████
██
██
██
██████`,
"d": `██████
██ ██
██ ██
██ ██
██████ `,
"D": `██████
██ ██
██ ██
██ ██
██████ `,
"e": `███████
██
█████
██
███████`,
"E": `███████
██
█████
██
███████`,
"f": `███████
██
█████
██
██ `,
"F": `███████
██
█████
██
██ `,
"g": ` ██████
██
██ ███
██ ██
██████ `,
"G": ` ██████
██
██ ███
██ ██
██████ `,
"h": `██ ██
██ ██
███████
██ ██
██ ██ `,
"H": `██ ██
██ ██
███████
██ ██
██ ██ `,
"i": `██
██
██
██
██`,
"I": `██
██
██
██
██`,
"j": ` ██
██
██
██ ██
█████ `,
"J": ` ██
██
██
██ ██
█████ `,
"k": `██ ██
██ ██
█████
██ ██
██ ██`,
"K": `██ ██
██ ██
█████
██ ██
██ ██`,
"l": `██
██
██
██
███████ `,
"L": `██
██
██
██
███████ `,
"m": `███ ███
████ ████
██ ████ ██
██ ██ ██
██ ██`,
"M": `███ ███
████ ████
██ ████ ██
██ ██ ██
██ ██`,
"n": `███ ██
████ ██
██ ██ ██
██ ██ ██
██ ████`,
"N": `███ ██
████ ██
██ ██ ██
██ ██ ██
██ ████`,
"o": ` ██████
██ ██
██ ██
██ ██
██████ `,
"O": ` ██████
██ ██
██ ██
██ ██
██████ `,
"p": `██████
██ ██
██████
██
██ `,
"P": `██████
██ ██
██████
██
██ `,
"q": ` ██████
██ ██
██ ██
██ ▄▄ ██
██████
▀▀ `,
"Q": ` ██████
██ ██
██ ██
██ ▄▄ ██
██████
▀▀ `,
"r": `██████
██ ██
██████
██ ██
██ ██`,
"R": `██████
██ ██
██████
██ ██
██ ██`,
"s": `███████
██
███████
██
███████`,
"S": `███████
██
███████
██
███████`,
"t": `████████
██
██
██
██ `,
"T": `████████
██
██
██
██ `,
"u": `██ ██
██ ██
██ ██
██ ██
██████ `,
"U": `██ ██
██ ██
██ ██
██ ██
██████ `,
"v": `██ ██
██ ██
██ ██
██ ██
████ `,
"V": `██ ██
██ ██
██ ██
██ ██
████ `,
"w": `██ ██
██ ██
██ █ ██
██ ███ ██
███ ███ `,
"W": `██ ██
██ ██
██ █ ██
██ ███ ██
███ ███ `,
"x": `██ ██
██ ██
███
██ ██
██ ██ `,
"X": `██ ██
██ ██
███
██ ██
██ ██ `,
"y": `██ ██
██ ██
████
██
██ `,
"Y": `██ ██
██ ██
████
██
██ `,
"z": `███████
███
███
███
███████`,
"Z": `███████
███
███
███
███████`,
"0": ` ██████
██ ████
██ ██ ██
████ ██
██████ `,
"1": ` ██
███
██
██
██ `,
"2": `██████
██
█████
██
███████ `,
"3": `██████
██
█████
██
██████ `,
"4": `██ ██
██ ██
███████
██
██ `,
"5": `███████
██
███████
██
███████`,
"6": ` ██████
██
███████
██ ██
██████ `,
"7": `███████
██
██
██
██`,
"8": ` █████
██ ██
█████
██ ██
█████ `,
"9": ` █████
██ ██
██████
██
█████ `,
" ": " ",
"!": `██
██
██
██ `,
"$": `▄▄███▄▄·
██
███████
██
███████
▀▀▀ `,
"%": `██ ██
██
██
██
██ ██`,
"/": ` ██
██
██
██
██ `,
"(": ` ██
██
██
██
██ `,
")": `██
██
██
██
██ `,
"?": `██████
██
▄███
▀▀
██ `,
"[": `███
██
██
██
███`,
"]": `███
██
██
██
███ `,
".": `
██`,
",": `
▄█`,
"-": `
█████
`,
"<": ` ██
██
██
██
██ `,
">": `██
██
██
██
██ `,
"*": `
▄ ██ ▄
████
▀ ██ ▀
`,
"#": ` ██ ██
████████
██ ██
████████
██ ██ `,
"_": `
███████ `,
":": `
██
██ `,
"°": ` ████
██ ██
████
`,
},
}

363
vendor/github.com/pterm/pterm/box_printer.go generated vendored Normal file
View File

@@ -0,0 +1,363 @@
package pterm
import (
"fmt"
"strings"
"github.com/mattn/go-runewidth"
"github.com/pterm/pterm/internal"
)
// BoxPrinter is able to render a box around printables.
type BoxPrinter struct {
Title string
TitleTopLeft bool
TitleTopRight bool
TitleTopCenter bool
TitleBottomLeft bool
TitleBottomRight bool
TitleBottomCenter bool
TextStyle *Style
VerticalString string
BoxStyle *Style
HorizontalString string
TopRightCornerString string
TopLeftCornerString string
BottomLeftCornerString string
BottomRightCornerString string
TopPadding int
BottomPadding int
RightPadding int
LeftPadding int
}
// DefaultBox is the default BoxPrinter.
var DefaultBox = BoxPrinter{
VerticalString: "|",
TopRightCornerString: "└",
TopLeftCornerString: "┘",
BottomLeftCornerString: "┐",
BottomRightCornerString: "┌",
HorizontalString: "─",
BoxStyle: &ThemeDefault.BoxStyle,
TextStyle: &ThemeDefault.BoxTextStyle,
RightPadding: 1,
LeftPadding: 1,
TopPadding: 0,
BottomPadding: 0,
TitleTopLeft: true,
}
// WithTitle returns a new box with a specific Title.
func (p BoxPrinter) WithTitle(str string) *BoxPrinter {
p.Title = str
return &p
}
// WithTitleTopLeft returns a new box with a specific Title alignment.
func (p BoxPrinter) WithTitleTopLeft(b ...bool) *BoxPrinter {
b2 := internal.WithBoolean(b)
p.TitleTopLeft = b2
p.TitleTopRight = false
p.TitleTopCenter = false
p.TitleBottomLeft = false
p.TitleBottomRight = false
p.TitleBottomCenter = false
return &p
}
// WithTitleTopRight returns a new box with a specific Title alignment.
func (p BoxPrinter) WithTitleTopRight(b ...bool) *BoxPrinter {
b2 := internal.WithBoolean(b)
p.TitleTopLeft = false
p.TitleTopRight = b2
p.TitleTopCenter = false
p.TitleBottomLeft = false
p.TitleBottomRight = false
p.TitleBottomCenter = false
return &p
}
// WithTitleTopCenter returns a new box with a specific Title alignment.
func (p BoxPrinter) WithTitleTopCenter(b ...bool) *BoxPrinter {
b2 := internal.WithBoolean(b)
p.TitleTopLeft = false
p.TitleTopRight = false
p.TitleTopCenter = b2
p.TitleBottomLeft = false
p.TitleBottomRight = false
p.TitleBottomCenter = false
return &p
}
// WithTitleBottomLeft returns a new box with a specific Title alignment.
func (p BoxPrinter) WithTitleBottomLeft(b ...bool) *BoxPrinter {
b2 := internal.WithBoolean(b)
p.TitleTopLeft = false
p.TitleTopRight = false
p.TitleTopCenter = false
p.TitleBottomLeft = b2
p.TitleBottomRight = false
p.TitleBottomCenter = false
return &p
}
// WithTitleBottomRight returns a new box with a specific Title alignment.
func (p BoxPrinter) WithTitleBottomRight(b ...bool) *BoxPrinter {
b2 := internal.WithBoolean(b)
p.TitleTopLeft = false
p.TitleTopRight = false
p.TitleTopCenter = false
p.TitleBottomLeft = false
p.TitleBottomRight = b2
p.TitleBottomCenter = false
return &p
}
// WithTitleBottomCenter returns a new box with a specific Title alignment.
func (p BoxPrinter) WithTitleBottomCenter(b ...bool) *BoxPrinter {
b2 := internal.WithBoolean(b)
p.TitleTopLeft = false
p.TitleTopRight = false
p.TitleTopCenter = false
p.TitleBottomLeft = false
p.TitleBottomRight = false
p.TitleBottomCenter = b2
return &p
}
// WithBoxStyle returns a new box with a specific box Style.
func (p BoxPrinter) WithBoxStyle(style *Style) *BoxPrinter {
p.BoxStyle = style
return &p
}
// WithTextStyle returns a new box with a specific text Style.
func (p BoxPrinter) WithTextStyle(style *Style) *BoxPrinter {
p.TextStyle = style
return &p
}
// WithTopRightCornerString returns a new box with a specific TopRightCornerString.
func (p BoxPrinter) WithTopRightCornerString(str string) *BoxPrinter {
p.TopRightCornerString = str
return &p
}
// WithTopLeftCornerString returns a new box with a specific TopLeftCornerString.
func (p BoxPrinter) WithTopLeftCornerString(str string) *BoxPrinter {
p.TopLeftCornerString = str
return &p
}
// WithBottomRightCornerString returns a new box with a specific BottomRightCornerString.
func (p BoxPrinter) WithBottomRightCornerString(str string) *BoxPrinter {
p.BottomRightCornerString = str
return &p
}
// WithBottomLeftCornerString returns a new box with a specific BottomLeftCornerString.
func (p BoxPrinter) WithBottomLeftCornerString(str string) *BoxPrinter {
p.BottomLeftCornerString = str
return &p
}
// WithVerticalString returns a new box with a specific VerticalString.
func (p BoxPrinter) WithVerticalString(str string) *BoxPrinter {
p.VerticalString = str
return &p
}
// WithHorizontalString returns a new box with a specific HorizontalString.
func (p BoxPrinter) WithHorizontalString(str string) *BoxPrinter {
p.HorizontalString = str
return &p
}
// WithTopPadding returns a new box with a specific TopPadding.
func (p BoxPrinter) WithTopPadding(padding int) *BoxPrinter {
if padding < 0 {
padding = 0
}
p.TopPadding = padding
return &p
}
// WithBottomPadding returns a new box with a specific BottomPadding.
func (p BoxPrinter) WithBottomPadding(padding int) *BoxPrinter {
if padding < 0 {
padding = 0
}
p.BottomPadding = padding
return &p
}
// WithRightPadding returns a new box with a specific RightPadding.
func (p BoxPrinter) WithRightPadding(padding int) *BoxPrinter {
if padding < 0 {
padding = 0
}
p.RightPadding = padding
return &p
}
// WithLeftPadding returns a new box with a specific LeftPadding.
func (p BoxPrinter) WithLeftPadding(padding int) *BoxPrinter {
if padding < 0 {
padding = 0
}
p.LeftPadding = padding
return &p
}
// Sprint formats using the default formats for its operands and returns the resulting string.
// Spaces are added between operands when neither is a string.
func (p BoxPrinter) Sprint(a ...interface{}) string {
if p.BoxStyle == nil {
p.BoxStyle = &ThemeDefault.BoxStyle
}
if p.TextStyle == nil {
p.TextStyle = &ThemeDefault.BoxTextStyle
}
maxWidth := internal.GetStringMaxWidth(Sprint(a...))
var topLine string
var bottomLine string
if p.Title == "" {
topLine = p.BoxStyle.Sprint(p.BottomRightCornerString) + strings.Repeat(p.BoxStyle.Sprint(p.HorizontalString),
maxWidth+p.LeftPadding+p.RightPadding) + p.BoxStyle.Sprint(p.BottomLeftCornerString)
bottomLine = p.BoxStyle.Sprint(p.TopRightCornerString) + strings.Repeat(p.BoxStyle.Sprint(p.HorizontalString),
maxWidth+p.LeftPadding+p.RightPadding) + p.BoxStyle.Sprint(p.TopLeftCornerString)
} else {
p.Title = strings.ReplaceAll(p.Title, "\n", " ")
if (maxWidth + p.RightPadding + p.LeftPadding - 4) < len(RemoveColorFromString(p.Title)) {
p.RightPadding = len(RemoveColorFromString(p.Title)) - (maxWidth + p.RightPadding + p.LeftPadding - 5)
}
if p.TitleTopLeft {
topLine = p.BoxStyle.Sprint(p.BottomRightCornerString) + internal.AddTitleToLine(p.Title, p.BoxStyle.Sprint(p.HorizontalString), maxWidth+p.LeftPadding+p.RightPadding, true) + p.BoxStyle.Sprint(p.BottomLeftCornerString)
bottomLine = p.BoxStyle.Sprint(p.TopRightCornerString) + strings.Repeat(p.BoxStyle.Sprint(p.HorizontalString),
maxWidth+p.LeftPadding+p.RightPadding) + p.BoxStyle.Sprint(p.TopLeftCornerString)
} else if p.TitleTopRight {
topLine = p.BoxStyle.Sprint(p.BottomRightCornerString) + internal.AddTitleToLine(p.Title, p.BoxStyle.Sprint(p.HorizontalString), maxWidth+p.LeftPadding+p.RightPadding, false) + p.BoxStyle.Sprint(p.BottomLeftCornerString)
bottomLine = p.BoxStyle.Sprint(p.TopRightCornerString) + strings.Repeat(p.BoxStyle.Sprint(p.HorizontalString),
maxWidth+p.LeftPadding+p.RightPadding) + p.BoxStyle.Sprint(p.TopLeftCornerString)
} else if p.TitleTopCenter {
topLine = p.BoxStyle.Sprint(p.BottomRightCornerString) + internal.AddTitleToLineCenter(p.Title, p.BoxStyle.Sprint(p.HorizontalString), maxWidth+p.LeftPadding+p.RightPadding) + p.BoxStyle.Sprint(p.BottomLeftCornerString)
bottomLine = p.BoxStyle.Sprint(p.TopRightCornerString) + strings.Repeat(p.BoxStyle.Sprint(p.HorizontalString),
maxWidth+p.LeftPadding+p.RightPadding) + p.BoxStyle.Sprint(p.TopLeftCornerString)
} else if p.TitleBottomLeft {
topLine = p.BoxStyle.Sprint(p.BottomRightCornerString) + strings.Repeat(p.BoxStyle.Sprint(p.HorizontalString),
maxWidth+p.LeftPadding+p.RightPadding) + p.BoxStyle.Sprint(p.BottomLeftCornerString)
bottomLine = p.BoxStyle.Sprint(p.TopRightCornerString) + internal.AddTitleToLine(p.Title, p.BoxStyle.Sprint(p.HorizontalString), maxWidth+p.LeftPadding+p.RightPadding, true) + p.BoxStyle.Sprint(p.TopLeftCornerString)
} else if p.TitleBottomRight {
topLine = p.BoxStyle.Sprint(p.BottomRightCornerString) + strings.Repeat(p.BoxStyle.Sprint(p.HorizontalString),
maxWidth+p.LeftPadding+p.RightPadding) + p.BoxStyle.Sprint(p.BottomLeftCornerString)
bottomLine = p.BoxStyle.Sprint(p.TopRightCornerString) + internal.AddTitleToLine(p.Title, p.BoxStyle.Sprint(p.HorizontalString), maxWidth+p.LeftPadding+p.RightPadding, false) + p.BoxStyle.Sprint(p.TopLeftCornerString)
} else if p.TitleBottomCenter {
topLine = p.BoxStyle.Sprint(p.BottomRightCornerString) + strings.Repeat(p.BoxStyle.Sprint(p.HorizontalString),
maxWidth+p.LeftPadding+p.RightPadding) + p.BoxStyle.Sprint(p.BottomLeftCornerString)
bottomLine = p.BoxStyle.Sprint(p.TopRightCornerString) + internal.AddTitleToLineCenter(p.Title, p.BoxStyle.Sprint(p.HorizontalString), maxWidth+p.LeftPadding+p.RightPadding) + p.BoxStyle.Sprint(p.TopLeftCornerString)
}
}
boxString := strings.Repeat("\n", p.TopPadding) + Sprint(a...) + strings.Repeat("\n", p.BottomPadding)
ss := strings.Split(boxString, "\n")
for i, s2 := range ss {
if runewidth.StringWidth(RemoveColorFromString(s2)) < maxWidth {
ss[i] = p.BoxStyle.Sprint(p.VerticalString) + strings.Repeat(" ", p.LeftPadding) + p.TextStyle.Sprint(s2) +
strings.Repeat(" ", maxWidth-runewidth.StringWidth(RemoveColorFromString(s2))+p.RightPadding) +
p.BoxStyle.Sprint(p.VerticalString)
} else {
ss[i] = p.BoxStyle.Sprint(p.VerticalString) + strings.Repeat(" ", p.LeftPadding) + p.TextStyle.Sprint(s2) +
strings.Repeat(" ", p.RightPadding) + p.BoxStyle.Sprint(p.VerticalString)
}
}
return topLine + "\n" + strings.Join(ss, "\n") + "\n" + bottomLine
}
// Sprintln formats using the default formats for its operands and returns the resulting string.
// Spaces are always added between operands and a newline is appended.
func (p BoxPrinter) Sprintln(a ...interface{}) string {
return p.Sprint(strings.TrimSuffix(Sprintln(a...), "\n")) + "\n"
}
// Sprintf formats according to a format specifier and returns the resulting string.
func (p BoxPrinter) Sprintf(format string, a ...interface{}) string {
return p.Sprint(Sprintf(format, a...))
}
// Sprintfln formats according to a format specifier and returns the resulting string.
// Spaces are always added between operands and a newline is appended.
func (p BoxPrinter) Sprintfln(format string, a ...interface{}) string {
return p.Sprintf(format, a...) + "\n"
}
// Print formats using the default formats for its operands and writes to standard output.
// Spaces are added between operands when neither is a string.
// It returns the number of bytes written and any write error encountered.
func (p BoxPrinter) Print(a ...interface{}) *TextPrinter {
Print(p.Sprint(a...))
tp := TextPrinter(p)
return &tp
}
// Println formats using the default formats for its operands and writes to standard output.
// Spaces are always added between operands and a newline is appended.
// It returns the number of bytes written and any write error encountered.
func (p BoxPrinter) Println(a ...interface{}) *TextPrinter {
Print(p.Sprintln(a...))
tp := TextPrinter(p)
return &tp
}
// Printf formats according to a format specifier and writes to standard output.
// It returns the number of bytes written and any write error encountered.
func (p BoxPrinter) Printf(format string, a ...interface{}) *TextPrinter {
Print(p.Sprintf(format, a...))
tp := TextPrinter(p)
return &tp
}
// Printfln formats according to a format specifier and writes to standard output.
// Spaces are always added between operands and a newline is appended.
// It returns the number of bytes written and any write error encountered.
func (p BoxPrinter) Printfln(format string, a ...interface{}) *TextPrinter {
Print(p.Sprintfln(format, a...))
tp := TextPrinter(p)
return &tp
}
// PrintOnError prints every error which is not nil.
// If every error is nil, nothing will be printed.
// This can be used for simple error checking.
func (p BoxPrinter) PrintOnError(a ...interface{}) *TextPrinter {
for _, arg := range a {
if err, ok := arg.(error); ok {
if err != nil {
p.Println(err)
}
}
}
tp := TextPrinter(p)
return &tp
}
// PrintOnErrorf wraps every error which is not nil and prints it.
// If every error is nil, nothing will be printed.
// This can be used for simple error checking.
func (p BoxPrinter) PrintOnErrorf(format string, a ...interface{}) *TextPrinter {
for _, arg := range a {
if err, ok := arg.(error); ok {
if err != nil {
p.Println(fmt.Errorf(format, err))
}
}
}
tp := TextPrinter(p)
return &tp
}

143
vendor/github.com/pterm/pterm/bulletlist_printer.go generated vendored Normal file
View File

@@ -0,0 +1,143 @@
package pterm
import (
"strings"
"github.com/pterm/pterm/internal"
)
// NewBulletListFromStrings returns a BulletListPrinter with Text using the NewTreeListItemFromString method.
func NewBulletListFromStrings(s []string, padding string) BulletListPrinter {
var lis []BulletListItem
for _, line := range s {
lis = append(lis, NewBulletListItemFromString(line, padding))
}
return *DefaultBulletList.WithItems(lis)
}
// NewBulletListItemFromString returns a BulletListItem with a Text. The padding is counted in the Text to define the Level of the ListItem.
func NewBulletListItemFromString(text string, padding string) BulletListItem {
s, l := internal.RemoveAndCountPrefix(text, padding)
return BulletListItem{
Level: l,
Text: s,
}
}
// BulletListItem is able to render a ListItem.
type BulletListItem struct {
Level int
Text string
TextStyle *Style
Bullet string
BulletStyle *Style
}
// WithLevel returns a new BulletListItem with a specific Level.
func (p BulletListItem) WithLevel(level int) *BulletListItem {
p.Level = level
return &p
}
// WithText returns a new BulletListItem with a specific Text.
func (p BulletListItem) WithText(text string) *BulletListItem {
p.Text = text
return &p
}
// WithTextStyle returns a new BulletListItem with a specific TextStyle.
func (p BulletListItem) WithTextStyle(style *Style) *BulletListItem {
p.TextStyle = style
return &p
}
// WithBullet returns a new BulletListItem with a specific Prefix.
func (p BulletListItem) WithBullet(bullet string) *BulletListItem {
p.Bullet = bullet
return &p
}
// WithBulletStyle returns a new BulletListItem with a specific BulletStyle.
func (p BulletListItem) WithBulletStyle(style *Style) *BulletListItem {
p.BulletStyle = style
return &p
}
// NewBulletListFromString returns a BulletListPrinter with Text using the NewTreeListItemFromString method, splitting after return (\n).
func NewBulletListFromString(s string, padding string) BulletListPrinter {
return NewBulletListFromStrings(strings.Split(s, "\n"), padding)
}
// DefaultBulletList contains standards, which can be used to print a BulletListPrinter.
var DefaultBulletList = BulletListPrinter{
Bullet: "•",
TextStyle: &ThemeDefault.BulletListTextStyle,
BulletStyle: &ThemeDefault.BulletListBulletStyle,
}
// BulletListPrinter is able to render a list.
type BulletListPrinter struct {
Items []BulletListItem
TextStyle *Style
Bullet string
BulletStyle *Style
}
// WithItems returns a new list with specific Items.
func (l BulletListPrinter) WithItems(items []BulletListItem) *BulletListPrinter {
l.Items = append(l.Items, items...)
return &l
}
// WithTextStyle returns a new list with a specific text style.
func (l BulletListPrinter) WithTextStyle(style *Style) *BulletListPrinter {
l.TextStyle = style
return &l
}
// WithBullet returns a new list with a specific bullet.
func (l BulletListPrinter) WithBullet(bullet string) *BulletListPrinter {
l.Bullet = bullet
return &l
}
// WithBulletStyle returns a new list with a specific bullet style.
func (l BulletListPrinter) WithBulletStyle(style *Style) *BulletListPrinter {
l.BulletStyle = style
return &l
}
// Render prints the list to the terminal.
func (l BulletListPrinter) Render() error {
s, _ := l.Srender()
Println(s)
return nil
}
// Srender renders the list as a string.
func (l BulletListPrinter) Srender() (string, error) {
var ret string
for _, item := range l.Items {
if item.TextStyle == nil {
if l.TextStyle == nil {
item.TextStyle = &ThemeDefault.BulletListTextStyle
} else {
item.TextStyle = l.TextStyle
}
}
if item.BulletStyle == nil {
if l.BulletStyle == nil {
item.BulletStyle = &ThemeDefault.BulletListBulletStyle
} else {
item.BulletStyle = l.BulletStyle
}
}
if item.Bullet == "" {
ret += strings.Repeat(" ", item.Level) + item.BulletStyle.Sprint(l.Bullet) + " " + item.TextStyle.Sprint(item.Text) + "\n"
} else {
ret += strings.Repeat(" ", item.Level) + item.BulletStyle.Sprint(item.Bullet) + " " + item.TextStyle.Sprint(item.Text) + "\n"
}
}
return ret, nil
}

160
vendor/github.com/pterm/pterm/center_printer.go generated vendored Normal file
View File

@@ -0,0 +1,160 @@
package pterm
import (
"fmt"
"strings"
"github.com/mattn/go-runewidth"
"github.com/pterm/pterm/internal"
)
// DefaultCenter is the default CenterPrinter.
var DefaultCenter = CenterPrinter{
CenterEachLineSeparately: false,
}
// CenterPrinter prints centered text.
type CenterPrinter struct {
CenterEachLineSeparately bool
}
// WithCenterEachLineSeparately centers each line separately.
func (p CenterPrinter) WithCenterEachLineSeparately(b ...bool) *CenterPrinter {
bt := internal.WithBoolean(b)
p.CenterEachLineSeparately = bt
return &p
}
// Sprint formats using the default formats for its operands and returns the resulting string.
// Spaces are added between operands when neither is a string.
func (p CenterPrinter) Sprint(a ...interface{}) string {
if RawOutput {
return Sprint(a...)
}
lines := strings.Split(Sprint(a...), "\n")
var ret string
if p.CenterEachLineSeparately {
for _, line := range lines {
margin := (GetTerminalWidth() - runewidth.StringWidth(RemoveColorFromString(line))) / 2
if margin < 1 {
ret += line + "\n"
} else {
ret += strings.Repeat(" ", margin) + line + "\n"
}
}
return ret
}
var maxLineWidth int
for _, line := range lines {
lineLength := runewidth.StringWidth(RemoveColorFromString(line))
if maxLineWidth < lineLength {
maxLineWidth = lineLength
}
}
indent := GetTerminalWidth() - maxLineWidth
if indent/2 < 1 {
for _, line := range lines {
ret += line + "\n"
}
return ret
}
for _, line := range lines {
ret += strings.Repeat(" ", indent/2) + line + "\n"
}
return ret
}
// Sprintln formats using the default formats for its operands and returns the resulting string.
// Spaces are always added between operands and a newline is appended.
func (p CenterPrinter) Sprintln(a ...interface{}) string {
return p.Sprint(Sprintln(a...))
}
// Sprintf formats according to a format specifier and returns the resulting string.
func (p CenterPrinter) Sprintf(format string, a ...interface{}) string {
return p.Sprint(Sprintf(format, a...))
}
// Sprintfln formats according to a format specifier and returns the resulting string.
// Spaces are always added between operands and a newline is appended.
func (p CenterPrinter) Sprintfln(format string, a ...interface{}) string {
return p.Sprintf(format, a...) + "\n"
}
// Print formats using the default formats for its operands and writes to standard output.
// Spaces are added between operands when neither is a string.
// It returns the number of bytes written and any write error encountered.
func (p CenterPrinter) Print(a ...interface{}) *TextPrinter {
Print(p.Sprint(a...))
tp := TextPrinter(p)
return &tp
}
// Println formats using the default formats for its operands and writes to standard output.
// Spaces are always added between operands and a newline is appended.
// It returns the number of bytes written and any write error encountered.
func (p CenterPrinter) Println(a ...interface{}) *TextPrinter {
Print(p.Sprintln(a...))
tp := TextPrinter(p)
return &tp
}
// Printf formats according to a format specifier and writes to standard output.
// It returns the number of bytes written and any write error encountered.
func (p CenterPrinter) Printf(format string, a ...interface{}) *TextPrinter {
Print(p.Sprintf(format, a...))
tp := TextPrinter(p)
return &tp
}
// Printfln formats according to a format specifier and writes to standard output.
// Spaces are always added between operands and a newline is appended.
// It returns the number of bytes written and any write error encountered.
func (p CenterPrinter) Printfln(format string, a ...interface{}) *TextPrinter {
Print(p.Sprintfln(format, a...))
tp := TextPrinter(p)
return &tp
}
// PrintOnError prints every error which is not nil.
// If every error is nil, nothing will be printed.
// This can be used for simple error checking.
func (p CenterPrinter) PrintOnError(a ...interface{}) *TextPrinter {
for _, arg := range a {
if err, ok := arg.(error); ok {
if err != nil {
p.Println(err)
}
}
}
tp := TextPrinter(p)
return &tp
}
// PrintOnErrorf wraps every error which is not nil and prints it.
// If every error is nil, nothing will be printed.
// This can be used for simple error checking.
func (p CenterPrinter) PrintOnErrorf(format string, a ...interface{}) *TextPrinter {
for _, arg := range a {
if err, ok := arg.(error); ok {
if err != nil {
p.Println(fmt.Errorf(format, err))
}
}
}
tp := TextPrinter(p)
return &tp
}

361
vendor/github.com/pterm/pterm/color.go generated vendored Normal file
View File

@@ -0,0 +1,361 @@
package pterm
import (
"fmt"
"strings"
"github.com/gookit/color"
)
// PrintColor is false if PTerm should not print colored output.
var PrintColor = true
// EnableColor enables colors.
func EnableColor() {
color.Enable = true
PrintColor = true
}
// DisableColor disables colors.
func DisableColor() {
color.Enable = false
PrintColor = false
}
// Foreground colors. basic foreground colors 30 - 37.
const (
FgBlack Color = iota + 30
FgRed
FgGreen
FgYellow
FgBlue
FgMagenta
FgCyan
FgWhite
// FgDefault revert default FG.
FgDefault Color = 39
)
// Extra foreground color 90 - 97.
const (
FgDarkGray Color = iota + 90
FgLightRed
FgLightGreen
FgLightYellow
FgLightBlue
FgLightMagenta
FgLightCyan
FgLightWhite
// FgGray is an alias of FgDarkGray.
FgGray Color = 90
)
// Background colors. basic background colors 40 - 47.
const (
BgBlack Color = iota + 40
BgRed
BgGreen
BgYellow // BgBrown like yellow
BgBlue
BgMagenta
BgCyan
BgWhite
// BgDefault reverts to the default background.
BgDefault Color = 49
)
// Extra background color 100 - 107.
const (
BgDarkGray Color = iota + 100
BgLightRed
BgLightGreen
BgLightYellow
BgLightBlue
BgLightMagenta
BgLightCyan
BgLightWhite
// BgGray is an alias of BgDarkGray.
BgGray Color = 100
)
// Option settings.
const (
Reset Color = iota
Bold
Fuzzy
Italic
Underscore
Blink
FastBlink
Reverse
Concealed
Strikethrough
)
var (
// Red is an alias for FgRed.Sprint.
Red = FgRed.Sprint
// Cyan is an alias for FgCyan.Sprint.
Cyan = FgCyan.Sprint
// Gray is an alias for FgGray.Sprint.
Gray = FgGray.Sprint
// Blue is an alias for FgBlue.Sprint.
Blue = FgBlue.Sprint
// Black is an alias for FgBlack.Sprint.
Black = FgBlack.Sprint
// Green is an alias for FgGreen.Sprint.
Green = FgGreen.Sprint
// White is an alias for FgWhite.Sprint.
White = FgWhite.Sprint
// Yellow is an alias for FgYellow.Sprint.
Yellow = FgYellow.Sprint
// Magenta is an alias for FgMagenta.Sprint.
Magenta = FgMagenta.Sprint
// Normal is an alias for FgDefault.Sprint.
Normal = FgDefault.Sprint
// extra light.
// LightRed is a shortcut for FgLightRed.Sprint.
LightRed = FgLightRed.Sprint
// LightCyan is a shortcut for FgLightCyan.Sprint.
LightCyan = FgLightCyan.Sprint
// LightBlue is a shortcut for FgLightBlue.Sprint.
LightBlue = FgLightBlue.Sprint
// LightGreen is a shortcut for FgLightGreen.Sprint.
LightGreen = FgLightGreen.Sprint
// LightWhite is a shortcut for FgLightWhite.Sprint.
LightWhite = FgLightWhite.Sprint
// LightYellow is a shortcut for FgLightYellow.Sprint.
LightYellow = FgLightYellow.Sprint
// LightMagenta is a shortcut for FgLightMagenta.Sprint.
LightMagenta = FgLightMagenta.Sprint
)
// Color is a number which will be used to color strings in the terminal.
type Color uint8
// Sprintln formats using the default formats for its operands and returns the resulting string.
// Spaces are always added between operands and a newline is appended.
// Input will be colored with the parent Color.
func (c Color) Sprintln(a ...interface{}) string {
str := fmt.Sprintln(a...)
return c.Sprint(str)
}
// Sprint formats using the default formats for its operands and returns the resulting string.
// Spaces are added between operands when neither is a string.
// Input will be colored with the parent Color.
func (c Color) Sprint(a ...interface{}) string {
message := Sprint(a...)
messageLines := strings.Split(message, "\n")
for i, line := range messageLines {
messageLines[i] = color.RenderCode(c.String(), strings.ReplaceAll(line, color.ResetSet, Sprintf("\x1b[0m\u001B[%sm", c.String())))
}
message = strings.Join(messageLines, "\n")
return message
}
// Sprintf formats according to a format specifier and returns the resulting string.
// Input will be colored with the parent Color.
func (c Color) Sprintf(format string, a ...interface{}) string {
return c.Sprint(Sprintf(format, a...))
}
// Sprintfln formats according to a format specifier and returns the resulting string.
// Spaces are always added between operands and a newline is appended.
// Input will be colored with the parent Color.
func (c Color) Sprintfln(format string, a ...interface{}) string {
return c.Sprint(Sprintf(format, a...) + "\n")
}
// Println formats using the default formats for its operands and writes to standard output.
// Spaces are always added between operands and a newline is appended.
// It returns the number of bytes written and any write error encountered.
// Input will be colored with the parent Color.
func (c Color) Println(a ...interface{}) *TextPrinter {
Print(c.Sprintln(a...))
tc := TextPrinter(c)
return &tc
}
// Print formats using the default formats for its operands and writes to standard output.
// Spaces are added between operands when neither is a string.
// It returns the number of bytes written and any write error encountered.
// Input will be colored with the parent Color.
func (c Color) Print(a ...interface{}) *TextPrinter {
Print(c.Sprint(a...))
tc := TextPrinter(c)
return &tc
}
// Printf formats according to a format specifier and writes to standard output.
// It returns the number of bytes written and any write error encountered.
// Input will be colored with the parent Color.
func (c Color) Printf(format string, a ...interface{}) *TextPrinter {
Print(c.Sprintf(format, a...))
tc := TextPrinter(c)
return &tc
}
// Printfln formats according to a format specifier and writes to standard output.
// Spaces are always added between operands and a newline is appended.
// It returns the number of bytes written and any write error encountered.
// Input will be colored with the parent Color.
func (c Color) Printfln(format string, a ...interface{}) *TextPrinter {
Print(c.Sprintfln(format, a...))
tp := TextPrinter(c)
return &tp
}
// PrintOnError prints every error which is not nil.
// If every error is nil, nothing will be printed.
// This can be used for simple error checking.
func (p Color) PrintOnError(a ...interface{}) *TextPrinter {
for _, arg := range a {
if err, ok := arg.(error); ok {
if err != nil {
p.Println(err)
}
}
}
tp := TextPrinter(p)
return &tp
}
// PrintOnErrorf wraps every error which is not nil and prints it.
// If every error is nil, nothing will be printed.
// This can be used for simple error checking.
func (p Color) PrintOnErrorf(format string, a ...interface{}) *TextPrinter {
for _, arg := range a {
if err, ok := arg.(error); ok {
if err != nil {
p.Println(fmt.Errorf(format, err))
}
}
}
tp := TextPrinter(p)
return &tp
}
// String converts the color to a string. eg "35".
func (c Color) String() string {
return fmt.Sprintf("%d", c)
}
// Style is a collection of colors.
// Can include foreground, background and styling (eg. Bold, Underscore, etc.) colors.
type Style []Color
// NewStyle returns a new Style.
// Accepts multiple colors.
func NewStyle(colors ...Color) *Style {
ret := Style{}
for _, c := range colors {
ret = append(ret, c)
}
return &ret
}
// Add styles to the current Style.
func (s Style) Add(styles ...Style) Style {
ret := s
for _, st := range styles {
ret = append(ret, st...)
}
return ret
}
// Sprint formats using the default formats for its operands and returns the resulting string.
// Spaces are added between operands when neither is a string.
// Input will be colored with the parent Style.
func (s Style) Sprint(a ...interface{}) string {
message := Sprint(a...)
messageLines := strings.Split(message, "\n")
for i, line := range messageLines {
messageLines[i] = color.RenderCode(s.String(), strings.ReplaceAll(line, color.ResetSet, Sprintf("\x1b[0m\u001B[%sm", s.String())))
}
message = strings.Join(messageLines, "\n")
return color.RenderCode(s.String(), message)
}
// Sprintln formats using the default formats for its operands and returns the resulting string.
// Spaces are always added between operands and a newline is appended.
// Input will be colored with the parent Style.
func (s Style) Sprintln(a ...interface{}) string {
return s.Sprint(a...) + "\n"
}
// Sprintf formats according to a format specifier and returns the resulting string.
// Input will be colored with the parent Style.
func (s Style) Sprintf(format string, a ...interface{}) string {
return s.Sprint(Sprintf(format, a...))
}
// Sprintfln formats according to a format specifier and returns the resulting string.
// Spaces are always added between operands and a newline is appended.
// Input will be colored with the parent Style.
func (s Style) Sprintfln(format string, a ...interface{}) string {
return s.Sprint(Sprintf(format, a...) + "\n")
}
// Print formats using the default formats for its operands and writes to standard output.
// Spaces are added between operands when neither is a string.
// It returns the number of bytes written and any write error encountered.
// Input will be colored with the parent Style.
func (s Style) Print(a ...interface{}) {
Print(s.Sprint(a...))
}
// Println formats using the default formats for its operands and writes to standard output.
// Spaces are always added between operands and a newline is appended.
// It returns the number of bytes written and any write error encountered.
// Input will be colored with the parent Style.
func (s Style) Println(a ...interface{}) {
Println(s.Sprint(a...))
}
// Printf formats according to a format specifier and writes to standard output.
// It returns the number of bytes written and any write error encountered.
// Input will be colored with the parent Style.
func (s Style) Printf(format string, a ...interface{}) {
Print(s.Sprintf(format, a...))
}
// Printfln formats according to a format specifier and writes to standard output.
// Spaces are always added between operands and a newline is appended.
// It returns the number of bytes written and any write error encountered.
// Input will be colored with the parent Style.
func (s Style) Printfln(format string, a ...interface{}) {
Print(s.Sprintfln(format, a...))
}
// Code convert to code string. returns like "32;45;3".
func (s Style) Code() string {
return s.String()
}
// String convert to code string. returns like "32;45;3".
func (s Style) String() string {
return colors2code(s...)
}
// Converts colors to code.
// Return format: "32;45;3".
func colors2code(colors ...Color) string {
if len(colors) == 0 {
return ""
}
var codes []string
for _, c := range colors {
codes = append(codes, c.String())
}
return strings.Join(codes, ";")
}

61
vendor/github.com/pterm/pterm/conventionalcommit.json generated vendored Normal file
View File

@@ -0,0 +1,61 @@
{
"types": {
"refactor": {
"description": "Changes which neither fix a bug nor add a feature",
},
"fix": {
"description": "Changes which patch a bug"
},
"feat": {
"description": "Changes which introduce a new feature"
},
"build": {
"description": "Changes which affect the build system or external dependencies (example scopes: gulp, broccoli, npm)"
},
"chore": {
"description": "Changes which arent user-facing"
},
"style": {
"description": "Changes which don't affect code logic.\nWhite-spaces, formatting, missing semi-colons, etc"
},
"test": {
"description": "Changes which add missing tests or correct existing tests"
},
"docs": {
"description": "Changes which affect documentation",
"scopes": {
"pterm-sh": {},
"examples": {},
"readme": {},
"contributing": {}
}
},
"perf": {
"description": "Changes which improve performance"
},
"ci": {
"description": "Changes which affect CI configuration files and scripts (example scopes: travis, circle, browser-stack, sauce-labs)"
},
"revert": {
"description": "Changes which revert a previous commit"
}
},
"footerTypes": [
{
"name": "BREAKING CHANGE",
"description": "The commit introduces breaking API changes"
},
{
"name": "Closes",
"description": "The commit closes issues or pull requests"
},
{
"name": "Implements",
"description": "The commit implements features"
},
{
"name": "Co-authored-by",
"description": "The commit is co-authored by another person (for multiple people use one line each)"
}
]
}

11
vendor/github.com/pterm/pterm/errors.go generated vendored Normal file
View File

@@ -0,0 +1,11 @@
package pterm
import "errors"
var (
// ErrTerminalSizeNotDetectable - the terminal size can not be detected and the fallback values are used.
ErrTerminalSizeNotDetectable = errors.New("terminal size could not be detected - using fallback value")
// ErrHexCodeIsInvalid - the given HEX code is invalid.
ErrHexCodeIsInvalid = errors.New("hex code is not valid")
)

11
vendor/github.com/pterm/pterm/go.mod generated vendored Normal file
View File

@@ -0,0 +1,11 @@
module github.com/pterm/pterm
go 1.15
require (
github.com/MarvinJWendt/testza v0.2.12
github.com/atomicgo/cursor v0.0.1
github.com/gookit/color v1.4.2
github.com/mattn/go-runewidth v0.0.13
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211
)

46
vendor/github.com/pterm/pterm/go.sum generated vendored Normal file
View File

@@ -0,0 +1,46 @@
github.com/MarvinJWendt/testza v0.1.0/go.mod h1:7AxNvlfeHP7Z/hDQ5JtE3OKYT3XFUeLCDE2DQninSqs=
github.com/MarvinJWendt/testza v0.2.1/go.mod h1:God7bhG8n6uQxwdScay+gjm9/LnO4D3kkcZX4hv9Rp8=
github.com/MarvinJWendt/testza v0.2.8/go.mod h1:nwIcjmr0Zz+Rcwfh3/4UhBp7ePKVhuBExvZqnKYWlII=
github.com/MarvinJWendt/testza v0.2.10/go.mod h1:pd+VWsoGUiFtq+hRKSU1Bktnn+DMCSrDrXDpX2bG66k=
github.com/MarvinJWendt/testza v0.2.12 h1:/PRp/BF+27t2ZxynTiqj0nyND5PbOtfJS0SuTuxmgeg=
github.com/MarvinJWendt/testza v0.2.12/go.mod h1:JOIegYyV7rX+7VZ9r77L/eH6CfJHHzXjB69adAhzZkI=
github.com/atomicgo/cursor v0.0.1 h1:xdogsqa6YYlLfM+GyClC/Lchf7aiMerFiZQn7soTOoU=
github.com/atomicgo/cursor v0.0.1/go.mod h1:cBON2QmmrysudxNBFthvMtN32r3jxVRIvzkUiF/RuIk=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gookit/color v1.4.2 h1:tXy44JFSFkKnELV6WaMo/lLfu/meqITX3iAV52do7lk=
github.com/gookit/color v1.4.2/go.mod h1:fqRyamkC1W8uxl+lxCQxOT09l/vYfZ+QeiX3rKQHCoQ=
github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4=
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pterm/pterm v0.12.27/go.mod h1:PhQ89w4i95rhgE+xedAoqous6K9X+r6aSOI2eFF7DZI=
github.com/pterm/pterm v0.12.29/go.mod h1:WI3qxgvoQFFGKGjGnJR849gU0TsEOvKn5Q8LlY1U7lg=
github.com/pterm/pterm v0.12.30/go.mod h1:MOqLIyMOgmTDz9yorcYbcw+HsgoZo3BQfg2wtl3HEFE=
github.com/pterm/pterm v0.12.31/go.mod h1:32ZAWZVXD7ZfG0s8qqHXePte42kdz8ECtRyEejaWgXU=
github.com/pterm/pterm v0.12.33/go.mod h1:x+h2uL+n7CP/rel9+bImHD5lF3nM9vJj80k9ybiiTTE=
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 h1:QldyIu/L63oPpyvQmHgvgickp1Yw510KJOqX7H24mg8=
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1zIOPMxZ5EncGwgmMJsa+9ucAQZXxsObs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211013075003-97ac67df715c h1:taxlMj0D/1sOAuv/CbSD+MMDof2vbyPTqz5FNYKpXt8=
golang.org/x/sys v0.0.0-20211013075003-97ac67df715c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

228
vendor/github.com/pterm/pterm/header_printer.go generated vendored Normal file
View File

@@ -0,0 +1,228 @@
package pterm
import (
"fmt"
"strings"
"github.com/mattn/go-runewidth"
"github.com/pterm/pterm/internal"
)
var (
// DefaultHeader returns the printer for a default header text.
// Defaults to LightWhite, Bold Text and a Gray DefaultHeader background.
DefaultHeader = HeaderPrinter{
TextStyle: &ThemeDefault.HeaderTextStyle,
BackgroundStyle: &ThemeDefault.HeaderBackgroundStyle,
Margin: 5,
}
)
// HeaderPrinter contains the data used to craft a header.
// A header is printed as a big box with text in it.
// Can be used as title screens or section separator.
type HeaderPrinter struct {
TextStyle *Style
BackgroundStyle *Style
Margin int
FullWidth bool
}
// WithTextStyle returns a new HeaderPrinter with changed
func (p HeaderPrinter) WithTextStyle(style *Style) *HeaderPrinter {
p.TextStyle = style
return &p
}
// WithBackgroundStyle changes the background styling of the header.
func (p HeaderPrinter) WithBackgroundStyle(style *Style) *HeaderPrinter {
p.BackgroundStyle = style
return &p
}
// WithMargin changes the background styling of the header.
func (p HeaderPrinter) WithMargin(margin int) *HeaderPrinter {
p.Margin = margin
return &p
}
// WithFullWidth enables full width on a HeaderPrinter.
func (p HeaderPrinter) WithFullWidth(b ...bool) *HeaderPrinter {
p.FullWidth = internal.WithBoolean(b)
return &p
}
// Sprint formats using the default formats for its operands and returns the resulting string.
// Spaces are added between operands when neither is a string.
func (p HeaderPrinter) Sprint(a ...interface{}) string {
if RawOutput {
return Sprint(a...)
}
if p.TextStyle == nil {
p.TextStyle = NewStyle()
}
if p.BackgroundStyle == nil {
p.BackgroundStyle = NewStyle()
}
text := Sprint(a...)
var blankLine string
longestLine := internal.ReturnLongestLine(text, "\n")
longestLineLen := runewidth.StringWidth(RemoveColorFromString(longestLine)) + p.Margin*2
if p.FullWidth {
text = splitText(text, GetTerminalWidth()-p.Margin*2)
blankLine = strings.Repeat(" ", GetTerminalWidth())
} else {
if longestLineLen > GetTerminalWidth() {
text = splitText(text, GetTerminalWidth()-p.Margin*2)
blankLine = strings.Repeat(" ", GetTerminalWidth())
} else {
text = splitText(text, longestLineLen-p.Margin*2)
blankLine = strings.Repeat(" ", longestLineLen)
}
}
var marginString string
var ret string
if p.FullWidth {
longestLineLen = runewidth.StringWidth(RemoveColorFromString(internal.ReturnLongestLine(text, "\n")))
marginString = strings.Repeat(" ", (GetTerminalWidth()-longestLineLen)/2)
} else {
marginString = strings.Repeat(" ", p.Margin)
}
ret += p.BackgroundStyle.Sprint(blankLine) + "\n"
for _, line := range strings.Split(text, "\n") {
line = strings.ReplaceAll(line, "\n", "")
line = marginString + line + marginString
if runewidth.StringWidth(line) < runewidth.StringWidth(blankLine) {
line += strings.Repeat(" ", runewidth.StringWidth(blankLine)-runewidth.StringWidth(line))
}
ret += p.BackgroundStyle.Sprint(p.TextStyle.Sprint(line)) + "\n"
}
ret += p.BackgroundStyle.Sprint(blankLine) + "\n"
return ret
}
func splitText(text string, width int) string {
var lines []string
linesTmp := strings.Split(text, "\n")
for _, line := range linesTmp {
if runewidth.StringWidth(RemoveColorFromString(line)) > width {
extraLines := []string{""}
extraLinesCounter := 0
for i, letter := range line {
if i%width == 0 && i != 0 {
extraLinesCounter++
extraLines = append(extraLines, "")
}
extraLines[extraLinesCounter] += string(letter)
}
for _, extraLine := range extraLines {
extraLine += "\n"
lines = append(lines, extraLine)
}
} else {
line += "\n"
lines = append(lines, line)
}
}
var line string
for _, s := range lines {
line += s
}
return strings.TrimSuffix(line, "\n")
}
// Sprintln formats using the default formats for its operands and returns the resulting string.
// Spaces are always added between operands and a newline is appended.
func (p HeaderPrinter) Sprintln(a ...interface{}) string {
return p.Sprint(strings.TrimSuffix(Sprintln(a...), "\n"))
}
// Sprintf formats according to a format specifier and returns the resulting string.
func (p HeaderPrinter) Sprintf(format string, a ...interface{}) string {
return p.Sprint(Sprintf(format, a...))
}
// Sprintfln formats according to a format specifier and returns the resulting string.
// Spaces are always added between operands and a newline is appended.
func (p HeaderPrinter) Sprintfln(format string, a ...interface{}) string {
return p.Sprintf(format, a...) + "\n"
}
// Print formats using the default formats for its operands and writes to standard output.
// Spaces are added between operands when neither is a string.
// It returns the number of bytes written and any write error encountered.
func (p *HeaderPrinter) Print(a ...interface{}) *TextPrinter {
Print(p.Sprint(a...))
tp := TextPrinter(p)
return &tp
}
// Println formats using the default formats for its operands and writes to standard output.
// Spaces are always added between operands and a newline is appended.
// It returns the number of bytes written and any write error encountered.
func (p *HeaderPrinter) Println(a ...interface{}) *TextPrinter {
Print(p.Sprintln(a...))
tp := TextPrinter(p)
return &tp
}
// Printf formats according to a format specifier and writes to standard output.
// It returns the number of bytes written and any write error encountered.
func (p *HeaderPrinter) Printf(format string, a ...interface{}) *TextPrinter {
Print(p.Sprintf(format, a...))
tp := TextPrinter(p)
return &tp
}
// Printfln formats according to a format specifier and writes to standard output.
// Spaces are always added between operands and a newline is appended.
// It returns the number of bytes written and any write error encountered.
func (p *HeaderPrinter) Printfln(format string, a ...interface{}) *TextPrinter {
Print(p.Sprintfln(format, a...))
tp := TextPrinter(p)
return &tp
}
// PrintOnError prints every error which is not nil.
// If every error is nil, nothing will be printed.
// This can be used for simple error checking.
func (p *HeaderPrinter) PrintOnError(a ...interface{}) *TextPrinter {
for _, arg := range a {
if err, ok := arg.(error); ok {
if err != nil {
p.Println(err)
}
}
}
tp := TextPrinter(p)
return &tp
}
// PrintOnErrorf wraps every error which is not nil and prints it.
// If every error is nil, nothing will be printed.
// This can be used for simple error checking.
func (p *HeaderPrinter) PrintOnErrorf(format string, a ...interface{}) *TextPrinter {
for _, arg := range a {
if err, ok := arg.(error); ok {
if err != nil {
p.Println(fmt.Errorf(format, err))
}
}
}
tp := TextPrinter(p)
return &tp
}

View File

@@ -0,0 +1,14 @@
package pterm
// LivePrinter is a printer which can update it's output live.
type LivePrinter interface {
// GenericStart runs Start, but returns a LivePrinter.
// This is used for the interface LivePrinter.
// You most likely want to use Start instead of this in your program.
GenericStart() (*LivePrinter, error)
// GenericStop runs Stop, but returns a LivePrinter.
// This is used for the interface LivePrinter.
// You most likely want to use Stop instead of this in your program.
GenericStop() (*LivePrinter, error)
}

View File

@@ -0,0 +1,11 @@
package pterm
// RenderPrinter is used to display renderable content.
// Example for renderable content is a Table.
type RenderPrinter interface {
// Render the XXX to the terminal.
Render() error
// Srender returns the rendered string of XXX.
Srender() (string, error)
}

View File

@@ -0,0 +1,48 @@
package pterm
// TextPrinter contains methods to print formatted text to the console or return it as a string.
type TextPrinter interface {
// Sprint formats using the default formats for its operands and returns the resulting string.
// Spaces are added between operands when neither is a string.
Sprint(a ...interface{}) string
// Sprintln formats using the default formats for its operands and returns the resulting string.
// Spaces are always added between operands and a newline is appended.
Sprintln(a ...interface{}) string
// Sprintf formats according to a format specifier and returns the resulting string.
Sprintf(format string, a ...interface{}) string
// Sprintfln formats according to a format specifier and returns the resulting string.
// Spaces are always added between operands and a newline is appended.
Sprintfln(format string, a ...interface{}) string
// Print formats using the default formats for its operands and writes to standard output.
// Spaces are added between operands when neither is a string.
// It returns the number of bytes written and any write error encountered.
Print(a ...interface{}) *TextPrinter
// Println formats using the default formats for its operands and writes to standard output.
// Spaces are always added between operands and a newline is appended.
// It returns the number of bytes written and any write error encountered.
Println(a ...interface{}) *TextPrinter
// Printf formats according to a format specifier and writes to standard output.
// It returns the number of bytes written and any write error encountered.
Printf(format string, a ...interface{}) *TextPrinter
// Printfln formats according to a format specifier and writes to standard output.
// Spaces are always added between operands and a newline is appended.
// It returns the number of bytes written and any write error encountered.
Printfln(format string, a ...interface{}) *TextPrinter
// PrintOnError prints every error which is not nil.
// If every error is nil, nothing will be printed.
// This can be used for simple error checking.
PrintOnError(a ...interface{}) *TextPrinter
// PrintOnErrorf wraps every error which is not nil and prints it.
// If every error is nil, nothing will be printed.
// This can be used for simple error checking.
PrintOnErrorf(format string, a ...interface{}) *TextPrinter
}

42
vendor/github.com/pterm/pterm/internal/center_text.go generated vendored Normal file
View File

@@ -0,0 +1,42 @@
package internal
import (
"strings"
"github.com/gookit/color"
)
// CenterText returns a centered string with a padding left and right
func CenterText(text string, width int) string {
var lines []string
linesTmp := strings.Split(text, "\n")
for _, line := range linesTmp {
if len(color.ClearCode(line)) > width {
extraLines := []string{""}
extraLinesCounter := 0
for i, letter := range line {
if i%width == 0 && i != 0 {
extraLinesCounter++
extraLines = append(extraLines, "")
}
extraLines[extraLinesCounter] += string(letter)
}
for _, extraLine := range extraLines {
padding := width - len(color.ClearCode(extraLine))
extraLine = strings.Repeat(" ", padding/2) + extraLine + strings.Repeat(" ", padding/2) + "\n"
lines = append(lines, extraLine)
}
} else {
padding := width - len(color.ClearCode(line))
line = strings.Repeat(" ", padding/2) + line + strings.Repeat(" ", padding/2) + "\n"
lines = append(lines, line)
}
}
var line string
for _, s := range lines {
line += s
}
return strings.TrimSuffix(line, "\n")
}

7
vendor/github.com/pterm/pterm/internal/collection.go generated vendored Normal file
View File

@@ -0,0 +1,7 @@
package internal
// RandomStrings contains a list of random strings to use while testing.
var RandomStrings = []string{
"hello world", "²³14234!`§=)$-.€@_&", "This is a sentence.", "This\nstring\nhas\nmultiple\nlines",
"windows\r\nline\r\nendings", "\rtext",
}

21
vendor/github.com/pterm/pterm/internal/longest_line.go generated vendored Normal file
View File

@@ -0,0 +1,21 @@
package internal
import (
"strings"
"github.com/gookit/color"
"github.com/mattn/go-runewidth"
)
// ReturnLongestLine returns the longest line with a given separator
func ReturnLongestLine(text, sep string) string {
lines := strings.Split(text, sep)
var longest string
for _, line := range lines {
if runewidth.StringWidth(color.ClearCode(line)) > runewidth.StringWidth(color.ClearCode(longest)) {
longest = line
}
}
return longest
}

View File

@@ -0,0 +1,8 @@
package internal
func MapRangeToRange(fromMin, fromMax, toMin, toMax, current float32) int {
if fromMax-fromMin == 0 {
return 0
}
return int(toMin + ((toMax-toMin)/(fromMax-fromMin))*(current-fromMin))
}

View File

@@ -0,0 +1,20 @@
package internal
import (
"strings"
"github.com/gookit/color"
"github.com/mattn/go-runewidth"
)
// GetStringMaxWidth returns the maximum width of a string with multiple lines.
func GetStringMaxWidth(s string) int {
var max int
ss := strings.Split(s, "\n")
for _, s2 := range ss {
if runewidth.StringWidth(color.ClearCode(s2)) > max {
max = runewidth.StringWidth(color.ClearCode(s2))
}
}
return max
}

13
vendor/github.com/pterm/pterm/internal/percentage.go generated vendored Normal file
View File

@@ -0,0 +1,13 @@
package internal
import "math"
// Percentage calculates percentage.
func Percentage(total, current float64) float64 {
return (current / total) * 100
}
// PercentageRound returns a rounded Percentage.
func PercentageRound(total, current float64) float64 {
return math.Round(Percentage(total, current))
}

View File

@@ -0,0 +1,11 @@
package internal
import (
"strings"
)
func RemoveAndCountPrefix(input, subString string) (string, int) {
inputLength := len(input)
input = strings.TrimLeft(input, subString)
return input, inputLength - len(input)
}

View File

@@ -0,0 +1,30 @@
package internal
import (
"strings"
"github.com/gookit/color"
)
// AddTitleToLine adds a title to a site of a line ex: "─ This is the title ──────"
func AddTitleToLine(title, line string, length int, left bool) string {
var ret string
if left {
ret += line + " " + title + " " + line + strings.Repeat(line, length-(4+len(color.ClearCode(title))))
} else {
ret += strings.Repeat(line, length-(4+len(color.ClearCode(title)))) + line + " " + title + " " + line
}
return ret
}
// AddTitleToLineCenter adds a title to the center of a line ex: "─ This is the title ──────"
func AddTitleToLineCenter(title, line string, length int) string {
var ret string
repeatString := length - (4 + len(color.ClearCode(title)))
unevenRepeatString := repeatString % 2
ret += strings.Repeat(line, repeatString/2) + line + " " + title + " " + line + strings.Repeat(line, repeatString/2+unevenRepeatString)
return ret
}

View File

@@ -0,0 +1,9 @@
package internal
// WithBoolean helps an option setter (WithXXX(b ...bool) to return true, if no boolean is set, but false if it's explicitly set to false.
func WithBoolean(b []bool) bool {
if len(b) == 0 {
b = append(b, true)
}
return b[0]
}

182
vendor/github.com/pterm/pterm/panel_printer.go generated vendored Normal file
View File

@@ -0,0 +1,182 @@
package pterm
import (
"strings"
"github.com/mattn/go-runewidth"
"github.com/pterm/pterm/internal"
)
// Panel contains the data, which should be printed inside a PanelPrinter.
type Panel struct {
Data string
}
// Panels is a two dimensional coordinate system for Panel.
type Panels [][]Panel
// DefaultPanel is the default PanelPrinter.
var DefaultPanel = PanelPrinter{
Padding: 1,
}
// PanelPrinter prints content in boxes.
type PanelPrinter struct {
Panels Panels
Padding int
BottomPadding int
SameColumnWidth bool
BoxPrinter BoxPrinter
}
// WithPanels returns a new PanelPrinter with specific options.
func (p PanelPrinter) WithPanels(panels Panels) *PanelPrinter {
p.Panels = panels
return &p
}
// WithPadding returns a new PanelPrinter with specific options.
func (p PanelPrinter) WithPadding(padding int) *PanelPrinter {
if padding < 0 {
padding = 0
}
p.Padding = padding
return &p
}
// WithBottomPadding returns a new PanelPrinter with specific options.
func (p PanelPrinter) WithBottomPadding(bottomPadding int) *PanelPrinter {
if bottomPadding < 0 {
bottomPadding = 0
}
p.BottomPadding = bottomPadding
return &p
}
// WithSameColumnWidth returns a new PanelPrinter with specific options.
func (p PanelPrinter) WithSameColumnWidth(b ...bool) *PanelPrinter {
b2 := internal.WithBoolean(b)
p.SameColumnWidth = b2
return &p
}
// WithBoxPrinter returns a new PanelPrinter with specific options.
func (p PanelPrinter) WithBoxPrinter(boxPrinter BoxPrinter) *PanelPrinter {
p.BoxPrinter = boxPrinter
return &p
}
func (p PanelPrinter) getRawOutput() string {
var ret string
for _, panel := range p.Panels {
for _, panel2 := range panel {
ret += panel2.Data + "\n\n"
}
ret += "\n"
}
return ret
}
// Srender renders the Template as a string.
func (p PanelPrinter) Srender() (string, error) {
var ret string
if RawOutput {
return p.getRawOutput(), nil
}
for i := range p.Panels {
for i2 := range p.Panels[i] {
p.Panels[i][i2].Data = strings.TrimSuffix(p.Panels[i][i2].Data, "\n")
}
}
if p.BoxPrinter != (BoxPrinter{}) {
for i := range p.Panels {
for i2 := range p.Panels[i] {
p.Panels[i][i2].Data = p.BoxPrinter.Sprint(p.Panels[i][i2].Data)
}
}
}
for i := range p.Panels {
if len(p.Panels)-1 != i {
for i2 := range p.Panels[i] {
p.Panels[i][i2].Data += strings.Repeat("\n", p.BottomPadding)
}
}
}
columnMaxHeightMap := make(map[int]int)
if p.SameColumnWidth {
for _, panel := range p.Panels {
for i, p2 := range panel {
if columnMaxHeightMap[i] < internal.GetStringMaxWidth(p2.Data) {
columnMaxHeightMap[i] = internal.GetStringMaxWidth(p2.Data)
}
}
}
}
for _, boxLine := range p.Panels {
var maxHeight int
var renderedPanels []string
for _, box := range boxLine {
renderedPanels = append(renderedPanels, box.Data)
}
for i, panel := range renderedPanels {
renderedPanels[i] = strings.ReplaceAll(panel, "\n", Reset.Sprint()+"\n")
}
for _, box := range renderedPanels {
height := len(strings.Split(box, "\n"))
if height > maxHeight {
maxHeight = height
}
}
for i := 0; i < maxHeight; i++ {
if maxHeight != i {
for j, letter := range renderedPanels {
var letterLine string
letterLines := strings.Split(letter, "\n")
var maxLetterWidth int
if !p.SameColumnWidth {
maxLetterWidth = internal.GetStringMaxWidth(letter)
}
if len(letterLines) > i {
letterLine = letterLines[i]
}
letterLineLength := runewidth.StringWidth(RemoveColorFromString(letterLine))
if !p.SameColumnWidth {
if letterLineLength < maxLetterWidth {
letterLine += strings.Repeat(" ", maxLetterWidth-letterLineLength)
}
} else {
if letterLineLength < columnMaxHeightMap[j] {
letterLine += strings.Repeat(" ", columnMaxHeightMap[j]-letterLineLength)
}
}
letterLine += strings.Repeat(" ", p.Padding)
ret += letterLine
}
ret += "\n"
}
}
}
return ret, nil
}
// Render prints the Template to the terminal.
func (p PanelPrinter) Render() error {
s, _ := p.Srender()
Println(s)
return nil
}

134
vendor/github.com/pterm/pterm/paragraph_printer.go generated vendored Normal file
View File

@@ -0,0 +1,134 @@
package pterm
import (
"fmt"
"strings"
)
// DefaultParagraph contains the default values for a ParagraphPrinter.
var DefaultParagraph = ParagraphPrinter{
MaxWidth: GetTerminalWidth(),
}
// ParagraphPrinter can print paragraphs to a fixed line width.
// The text will split between words, so that words will stick together.
// It's like in a book.
type ParagraphPrinter struct {
MaxWidth int
}
// WithMaxWidth returns a new ParagraphPrinter with a specific MaxWidth
func (p ParagraphPrinter) WithMaxWidth(width int) *ParagraphPrinter {
p.MaxWidth = width
return &p
}
// Sprint formats using the default formats for its operands and returns the resulting string.
// Spaces are added between operands when neither is a string.
func (p ParagraphPrinter) Sprint(a ...interface{}) string {
if RawOutput {
return Sprint(a...)
}
words := strings.Fields(strings.TrimSpace(Sprint(a...)))
if len(words) == 0 {
return ""
}
wrapped := words[0]
spaceLeft := p.MaxWidth - len(wrapped)
for _, word := range words[1:] {
if len(word)+1 > spaceLeft {
wrapped += "\n" + word
spaceLeft = p.MaxWidth - len(word)
} else {
wrapped += " " + word
spaceLeft -= 1 + len(word)
}
}
return wrapped
}
// Sprintln formats using the default formats for its operands and returns the resulting string.
// Spaces are always added between operands and a newline is appended.
func (p ParagraphPrinter) Sprintln(a ...interface{}) string {
return p.Sprint(Sprintln(a...)) + "\n"
}
// Sprintf formats according to a format specifier and returns the resulting string.
func (p ParagraphPrinter) Sprintf(format string, a ...interface{}) string {
return p.Sprint(Sprintf(format, a...))
}
// Sprintfln formats according to a format specifier and returns the resulting string.
// Spaces are always added between operands and a newline is appended.
func (p ParagraphPrinter) Sprintfln(format string, a ...interface{}) string {
return p.Sprintf(format, a...) + "\n"
}
// Print formats using the default formats for its operands and writes to standard output.
// Spaces are added between operands when neither is a string.
// It returns the number of bytes written and any write error encountered.
func (p *ParagraphPrinter) Print(a ...interface{}) *TextPrinter {
Print(p.Sprint(a...))
tp := TextPrinter(p)
return &tp
}
// Println formats using the default formats for its operands and writes to standard output.
// Spaces are always added between operands and a newline is appended.
// It returns the number of bytes written and any write error encountered.
func (p *ParagraphPrinter) Println(a ...interface{}) *TextPrinter {
Print(p.Sprintln(a...))
tp := TextPrinter(p)
return &tp
}
// Printf formats according to a format specifier and writes to standard output.
// It returns the number of bytes written and any write error encountered.
func (p *ParagraphPrinter) Printf(format string, a ...interface{}) *TextPrinter {
Print(p.Sprintf(format, a...))
tp := TextPrinter(p)
return &tp
}
// Printfln formats according to a format specifier and writes to standard output.
// Spaces are always added between operands and a newline is appended.
// It returns the number of bytes written and any write error encountered.
func (p *ParagraphPrinter) Printfln(format string, a ...interface{}) *TextPrinter {
Print(p.Sprintfln(format, a...))
tp := TextPrinter(p)
return &tp
}
// PrintOnError prints every error which is not nil.
// If every error is nil, nothing will be printed.
// This can be used for simple error checking.
func (p *ParagraphPrinter) PrintOnError(a ...interface{}) *TextPrinter {
for _, arg := range a {
if err, ok := arg.(error); ok {
if err != nil {
p.Println(err)
}
}
}
tp := TextPrinter(p)
return &tp
}
// PrintOnErrorf wraps every error which is not nil and prints it.
// If every error is nil, nothing will be printed.
// This can be used for simple error checking.
func (p *ParagraphPrinter) PrintOnErrorf(format string, a ...interface{}) *TextPrinter {
for _, arg := range a {
if err, ok := arg.(error); ok {
if err != nil {
p.Println(fmt.Errorf(format, err))
}
}
}
tp := TextPrinter(p)
return &tp
}

342
vendor/github.com/pterm/pterm/prefix_printer.go generated vendored Normal file
View File

@@ -0,0 +1,342 @@
package pterm
import (
"fmt"
"runtime"
"strings"
"github.com/pterm/pterm/internal"
)
var (
// GrayBoxStyle wraps text in a gray box.
GrayBoxStyle = NewStyle(BgGray, FgLightWhite)
)
var (
// Info returns a PrefixPrinter, which can be used to print text with an "info" Prefix.
Info = PrefixPrinter{
MessageStyle: &ThemeDefault.InfoMessageStyle,
Prefix: Prefix{
Style: &ThemeDefault.InfoPrefixStyle,
Text: "INFO",
},
}
// Warning returns a PrefixPrinter, which can be used to print text with a "warning" Prefix.
Warning = PrefixPrinter{
MessageStyle: &ThemeDefault.WarningMessageStyle,
Prefix: Prefix{
Style: &ThemeDefault.WarningPrefixStyle,
Text: "WARNING",
},
}
// Success returns a PrefixPrinter, which can be used to print text with a "success" Prefix.
Success = PrefixPrinter{
MessageStyle: &ThemeDefault.SuccessMessageStyle,
Prefix: Prefix{
Style: &ThemeDefault.SuccessPrefixStyle,
Text: "SUCCESS",
},
}
// Error returns a PrefixPrinter, which can be used to print text with an "error" Prefix.
Error = PrefixPrinter{
MessageStyle: &ThemeDefault.ErrorMessageStyle,
Prefix: Prefix{
Style: &ThemeDefault.ErrorPrefixStyle,
Text: " ERROR ",
},
}
// Fatal returns a PrefixPrinter, which can be used to print text with an "fatal" Prefix.
// NOTICE: Fatal terminates the application immediately!
Fatal = PrefixPrinter{
MessageStyle: &ThemeDefault.FatalMessageStyle,
Prefix: Prefix{
Style: &ThemeDefault.FatalPrefixStyle,
Text: " FATAL ",
},
Fatal: true,
}
// Debug Prints debug messages. By default it will only print if PrintDebugMessages is true.
// You can change PrintDebugMessages with EnableDebugMessages and DisableDebugMessages, or by setting the variable itself.
Debug = PrefixPrinter{
MessageStyle: &ThemeDefault.DebugMessageStyle,
Prefix: Prefix{
Text: " DEBUG ",
Style: &ThemeDefault.DebugPrefixStyle,
},
Debugger: true,
}
// Description returns a PrefixPrinter, which can be used to print text with a "description" Prefix.
Description = PrefixPrinter{
MessageStyle: &ThemeDefault.DescriptionMessageStyle,
Prefix: Prefix{
Style: &ThemeDefault.DescriptionPrefixStyle,
Text: "Description",
},
}
)
// PrefixPrinter is the printer used to print a Prefix.
type PrefixPrinter struct {
Prefix Prefix
Scope Scope
MessageStyle *Style
Fatal bool
ShowLineNumber bool
LineNumberOffset int
// If Debugger is true, the printer will only print if PrintDebugMessages is set to true.
// You can change PrintDebugMessages with EnableDebugMessages and DisableDebugMessages, or by setting the variable itself.
Debugger bool
}
// WithPrefix adds a custom prefix to the printer.
func (p PrefixPrinter) WithPrefix(prefix Prefix) *PrefixPrinter {
p.Prefix = prefix
return &p
}
// WithScope adds a scope to the Prefix.
func (p PrefixPrinter) WithScope(scope Scope) *PrefixPrinter {
p.Scope = scope
return &p
}
// WithMessageStyle adds a custom prefix to the printer.
func (p PrefixPrinter) WithMessageStyle(style *Style) *PrefixPrinter {
p.MessageStyle = style
return &p
}
// WithFatal sets if the printer should panic after printing.
// NOTE:
// The printer will only panic if either PrefixPrinter.Println, PrefixPrinter.Print
// or PrefixPrinter.Printf is called.
func (p PrefixPrinter) WithFatal(b ...bool) *PrefixPrinter {
p.Fatal = internal.WithBoolean(b)
return &p
}
// WithShowLineNumber sets if the printer should print the line number from where it's called in a go file.
func (p PrefixPrinter) WithShowLineNumber(b ...bool) *PrefixPrinter {
p.ShowLineNumber = internal.WithBoolean(b)
return &p
}
// WithDebugger returns a new Printer with specific Debugger value.
// If Debugger is true, the printer will only print if PrintDebugMessages is set to true.
// You can change PrintDebugMessages with EnableDebugMessages and DisableDebugMessages, or by setting the variable itself.
func (p PrefixPrinter) WithDebugger(b ...bool) *PrefixPrinter {
p.Debugger = internal.WithBoolean(b)
return &p
}
// WithLineNumberOffset can be used to exclude a specific amount of calls in the call stack.
// If you make a wrapper function for example, you can set this to one.
// The printed line number will then be the line number where your wrapper function is called.
func (p PrefixPrinter) WithLineNumberOffset(offset int) *PrefixPrinter {
p.LineNumberOffset = offset
return &p
}
// Sprint formats using the default formats for its operands and returns the resulting string.
// Spaces are added between operands when neither is a string.
func (p *PrefixPrinter) Sprint(a ...interface{}) string {
m := Sprint(a...)
if p.Debugger && !PrintDebugMessages {
return ""
}
if RawOutput {
if p.Prefix.Text != "" {
return Sprintf("%s: %s", strings.TrimSpace(p.Prefix.Text), Sprint(a...))
} else {
return Sprint(a...)
}
}
if p.Prefix.Style == nil {
p.Prefix.Style = NewStyle()
}
if p.Scope.Style == nil {
p.Scope.Style = NewStyle()
}
if p.MessageStyle == nil {
p.MessageStyle = NewStyle()
}
var ret string
var newLine bool
if strings.HasSuffix(m, "\n") {
m = strings.TrimRight(m, "\n")
newLine = true
}
messageLines := strings.Split(m, "\n")
for i, m := range messageLines {
if i == 0 {
ret += p.GetFormattedPrefix() + " "
if p.Scope.Text != "" {
ret += NewStyle(*p.Scope.Style...).Sprint(" (" + p.Scope.Text + ") ")
}
ret += p.MessageStyle.Sprint(m)
} else {
ret += "\n" + p.Prefix.Style.Sprint(strings.Repeat(" ", len(p.Prefix.Text)+2)) + " " + p.MessageStyle.Sprint(m)
}
}
_, fileName, line, _ := runtime.Caller(3 + p.LineNumberOffset)
if p.ShowLineNumber {
ret += FgGray.Sprint("\n└ " + fmt.Sprintf("(%s:%d)\n", fileName, line))
newLine = false
}
if newLine {
ret += "\n"
}
return Sprint(ret)
}
// Sprintln formats using the default formats for its operands and returns the resulting string.
// Spaces are always added between operands and a newline is appended.
func (p PrefixPrinter) Sprintln(a ...interface{}) string {
if p.Debugger && !PrintDebugMessages {
return ""
}
str := fmt.Sprintln(a...)
return p.Sprint(str)
}
// Sprintf formats according to a format specifier and returns the resulting string.
func (p PrefixPrinter) Sprintf(format string, a ...interface{}) string {
if p.Debugger && !PrintDebugMessages {
return ""
}
return p.Sprint(Sprintf(format, a...))
}
// Sprintfln formats according to a format specifier and returns the resulting string.
// Spaces are always added between operands and a newline is appended.
func (p PrefixPrinter) Sprintfln(format string, a ...interface{}) string {
if p.Debugger && !PrintDebugMessages {
return ""
}
return p.Sprintf(format, a...) + "\n"
}
// Print formats using the default formats for its operands and writes to standard output.
// Spaces are added between operands when neither is a string.
// It returns the number of bytes written and any write error encountered.
func (p *PrefixPrinter) Print(a ...interface{}) *TextPrinter {
tp := TextPrinter(p)
if p.Debugger && !PrintDebugMessages {
return &tp
}
Print(p.Sprint(a...))
checkFatal(p)
return &tp
}
// Println formats using the default formats for its operands and writes to standard output.
// Spaces are always added between operands and a newline is appended.
// It returns the number of bytes written and any write error encountered.
func (p *PrefixPrinter) Println(a ...interface{}) *TextPrinter {
tp := TextPrinter(p)
if p.Debugger && !PrintDebugMessages {
return &tp
}
Print(p.Sprintln(a...))
checkFatal(p)
return &tp
}
// Printf formats according to a format specifier and writes to standard output.
// It returns the number of bytes written and any write error encountered.
func (p *PrefixPrinter) Printf(format string, a ...interface{}) *TextPrinter {
tp := TextPrinter(p)
if p.Debugger && !PrintDebugMessages {
return &tp
}
Print(p.Sprintf(format, a...))
checkFatal(p)
return &tp
}
// Printfln formats according to a format specifier and writes to standard output.
// Spaces are always added between operands and a newline is appended.
// It returns the number of bytes written and any write error encountered.
func (p *PrefixPrinter) Printfln(format string, a ...interface{}) *TextPrinter {
tp := TextPrinter(p)
if p.Debugger && !PrintDebugMessages {
return &tp
}
Print(p.Sprintfln(format, a...))
checkFatal(p)
return &tp
}
// PrintOnError prints every error which is not nil.
// If every error is nil, nothing will be printed.
// This can be used for simple error checking.
//
// Note: Use WithFatal(true) or Fatal to panic after first non nil error.
func (p *PrefixPrinter) PrintOnError(a ...interface{}) *TextPrinter {
for _, arg := range a {
if err, ok := arg.(error); ok {
if err != nil {
p.Println(err)
}
}
}
tp := TextPrinter(p)
return &tp
}
// PrintOnErrorf wraps every error which is not nil and prints it.
// If every error is nil, nothing will be printed.
// This can be used for simple error checking.
func (p *PrefixPrinter) PrintOnErrorf(format string, a ...interface{}) *TextPrinter {
for _, arg := range a {
if err, ok := arg.(error); ok {
if err != nil {
p.Println(fmt.Errorf(format, err))
}
}
}
tp := TextPrinter(p)
return &tp
}
// GetFormattedPrefix returns the Prefix as a styled text string.
func (p PrefixPrinter) GetFormattedPrefix() string {
return p.Prefix.Style.Sprint(" " + p.Prefix.Text + " ")
}
// Prefix contains the data used as the beginning of a printed text via a PrefixPrinter.
type Prefix struct {
Text string
Style *Style
}
// Scope contains the data of the optional scope of a prefix.
// If it has a text, it will be printed after the Prefix in brackets.
type Scope struct {
Text string
Style *Style
}
func checkFatal(p *PrefixPrinter) {
if p.Fatal {
panic("")
}
}

179
vendor/github.com/pterm/pterm/print.go generated vendored Normal file
View File

@@ -0,0 +1,179 @@
package pterm
import (
"fmt"
"io"
"strings"
"github.com/gookit/color"
)
// SetDefaultOutput sets the default output of pterm.
func SetDefaultOutput(w io.Writer) {
color.SetOutput(w)
}
// Sprint formats using the default formats for its operands and returns the resulting string.
// Spaces are added between operands when neither is a string.
func Sprint(a ...interface{}) string {
return color.Sprint(a...)
}
// Sprintf formats according to a format specifier and returns the resulting string.
func Sprintf(format string, a ...interface{}) string {
return color.Sprintf(format, a...)
}
// Sprintfln formats according to a format specifier and returns the resulting string.
// Spaces are always added between operands and a newline is appended.
func Sprintfln(format string, a ...interface{}) string {
return color.Sprintf(format, a...) + "\n"
}
// Sprintln returns what Println would print to the terminal.
func Sprintln(a ...interface{}) string {
str := fmt.Sprintln(a...)
return Sprint(str)
}
// Sprinto returns what Printo would print.
func Sprinto(a ...interface{}) string {
return "\r" + Sprint(a...)
}
// Print formats using the default formats for its operands and writes to standard output.
// Spaces are added between operands when neither is a string.
// It returns the number of bytes written and any write error encountered.
func Print(a ...interface{}) {
if !Output {
return
}
var ret string
var printed bool
for _, bar := range ActiveProgressBarPrinters {
if bar.IsActive {
ret += sClearLine()
ret += Sprinto(a...)
printed = true
}
}
for _, spinner := range activeSpinnerPrinters {
if spinner.IsActive {
ret += sClearLine()
ret += Sprinto(a...)
printed = true
}
}
if !printed {
ret = color.Sprint(Sprint(a...))
}
color.Print(Sprint(ret))
// Refresh all progressbars in case they were overwritten previously. Reference: #302
for _, bar := range ActiveProgressBarPrinters {
if bar.IsActive {
bar.UpdateTitle(bar.Title)
}
}
}
// Println formats using the default formats for its operands and writes to standard output.
// Spaces are always added between operands and a newline is appended.
// It returns the number of bytes written and any write error encountered.
func Println(a ...interface{}) {
Print(Sprintln(a...))
}
// Printf formats according to a format specifier and writes to standard output.
// It returns the number of bytes written and any write error encountered.
func Printf(format string, a ...interface{}) {
Print(Sprintf(format, a...))
}
// Printfln formats according to a format specifier and writes to standard output.
// Spaces are always added between operands and a newline is appended.
// It returns the number of bytes written and any write error encountered.
func Printfln(format string, a ...interface{}) {
Print(Sprintfln(format, a...))
}
// PrintOnError prints every error which is not nil.
// If every error is nil, nothing will be printed.
// This can be used for simple error checking.
func PrintOnError(a ...interface{}) {
for _, arg := range a {
if err, ok := arg.(error); ok {
if err != nil {
Println(err)
}
}
}
}
// PrintOnErrorf wraps every error which is not nil and prints it.
// If every error is nil, nothing will be printed.
// This can be used for simple error checking.
func PrintOnErrorf(format string, a ...interface{}) {
for _, arg := range a {
if err, ok := arg.(error); ok {
if err != nil {
Println(fmt.Errorf(format, err))
}
}
}
}
// Fprint formats using the default formats for its operands and writes to w.
// Spaces are added between operands when neither is a string.
// It returns the number of bytes written and any write error encountered.
func Fprint(writer io.Writer, a ...interface{}) {
if !Output {
return
}
color.Fprint(writer, Sprint(a...))
}
// Fprintln formats using the default formats for its operands 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.
func Fprintln(writer io.Writer, a ...interface{}) {
Fprint(writer, Sprint(a...)+"\n")
}
// Printo overrides the current line in a terminal.
// If the current line is empty, the text will be printed like with pterm.Print.
// Example:
// pterm.Printo("Hello, World")
// time.Sleep(time.Second)
// pterm.Printo("Hello, Earth!")
func Printo(a ...interface{}) {
if !Output {
return
}
color.Print("\r" + Sprint(a...))
}
// Fprinto prints Printo to a custom writer.
func Fprinto(w io.Writer, a ...interface{}) {
Fprint(w, "\r", Sprint(a...))
}
// RemoveColorFromString removes color codes from a string.
func RemoveColorFromString(a ...interface{}) string {
return color.ClearCode(Sprint(a...))
}
func clearLine() {
Printo(strings.Repeat(" ", GetTerminalWidth()))
}
func sClearLine() string {
return Sprinto(strings.Repeat(" ", GetTerminalWidth()))
}

271
vendor/github.com/pterm/pterm/progressbar_printer.go generated vendored Normal file
View File

@@ -0,0 +1,271 @@
package pterm
import (
"strconv"
"strings"
"time"
"github.com/gookit/color"
"github.com/pterm/pterm/internal"
)
// ActiveProgressBarPrinters contains all running ProgressbarPrinters.
// Generally, there should only be one active ProgressbarPrinter at a time.
var ActiveProgressBarPrinters []*ProgressbarPrinter
var (
// DefaultProgressbar is the default ProgressbarPrinter.
DefaultProgressbar = ProgressbarPrinter{
Total: 100,
BarCharacter: "█",
LastCharacter: "█",
ElapsedTimeRoundingFactor: time.Second,
BarStyle: &ThemeDefault.ProgressbarBarStyle,
TitleStyle: &ThemeDefault.ProgressbarTitleStyle,
ShowTitle: true,
ShowCount: true,
ShowPercentage: true,
ShowElapsedTime: true,
BarFiller: " ",
}
)
// ProgressbarPrinter shows a progress animation in the terminal.
type ProgressbarPrinter struct {
Title string
Total int
Current int
BarCharacter string
LastCharacter string
ElapsedTimeRoundingFactor time.Duration
BarFiller string
ShowElapsedTime bool
ShowCount bool
ShowTitle bool
ShowPercentage bool
RemoveWhenDone bool
TitleStyle *Style
BarStyle *Style
IsActive bool
startedAt time.Time
}
// WithTitle sets the name of the ProgressbarPrinter.
func (p ProgressbarPrinter) WithTitle(name string) *ProgressbarPrinter {
p.Title = name
return &p
}
// WithTotal sets the total value of the ProgressbarPrinter.
func (p ProgressbarPrinter) WithTotal(total int) *ProgressbarPrinter {
p.Total = total
return &p
}
// WithCurrent sets the current value of the ProgressbarPrinter.
func (p ProgressbarPrinter) WithCurrent(current int) *ProgressbarPrinter {
p.Current = current
return &p
}
// WithBarCharacter sets the bar character of the ProgressbarPrinter.
func (p ProgressbarPrinter) WithBarCharacter(char string) *ProgressbarPrinter {
p.BarCharacter = char
return &p
}
// WithLastCharacter sets the last character of the ProgressbarPrinter.
func (p ProgressbarPrinter) WithLastCharacter(char string) *ProgressbarPrinter {
p.LastCharacter = char
return &p
}
// WithElapsedTimeRoundingFactor sets the rounding factor of the elapsed time.
func (p ProgressbarPrinter) WithElapsedTimeRoundingFactor(duration time.Duration) *ProgressbarPrinter {
p.ElapsedTimeRoundingFactor = duration
return &p
}
// WithShowElapsedTime sets if the elapsed time should be displayed in the ProgressbarPrinter.
func (p ProgressbarPrinter) WithShowElapsedTime(b ...bool) *ProgressbarPrinter {
p.ShowElapsedTime = internal.WithBoolean(b)
return &p
}
// WithShowCount sets if the total and current count should be displayed in the ProgressbarPrinter.
func (p ProgressbarPrinter) WithShowCount(b ...bool) *ProgressbarPrinter {
p.ShowCount = internal.WithBoolean(b)
return &p
}
// WithShowTitle sets if the title should be displayed in the ProgressbarPrinter.
func (p ProgressbarPrinter) WithShowTitle(b ...bool) *ProgressbarPrinter {
p.ShowTitle = internal.WithBoolean(b)
return &p
}
// WithShowPercentage sets if the completed percentage should be displayed in the ProgressbarPrinter.
func (p ProgressbarPrinter) WithShowPercentage(b ...bool) *ProgressbarPrinter {
p.ShowPercentage = internal.WithBoolean(b)
return &p
}
// WithTitleStyle sets the style of the title.
func (p ProgressbarPrinter) WithTitleStyle(style *Style) *ProgressbarPrinter {
p.TitleStyle = style
return &p
}
// WithBarStyle sets the style of the bar.
func (p ProgressbarPrinter) WithBarStyle(style *Style) *ProgressbarPrinter {
p.BarStyle = style
return &p
}
// WithRemoveWhenDone sets if the ProgressbarPrinter should be removed when it is done.
func (p ProgressbarPrinter) WithRemoveWhenDone(b ...bool) *ProgressbarPrinter {
p.RemoveWhenDone = internal.WithBoolean(b)
return &p
}
// Increment current value by one.
func (p *ProgressbarPrinter) Increment() *ProgressbarPrinter {
p.Add(1)
return p
}
// This method changed the title and re-renders the progressbar
func (p *ProgressbarPrinter) UpdateTitle(title string) *ProgressbarPrinter {
p.Title = title
p.updateProgress()
return p
}
// This is the update logic, renders the progressbar
func (p *ProgressbarPrinter) updateProgress() *ProgressbarPrinter {
if p.TitleStyle == nil {
p.TitleStyle = NewStyle()
}
if p.BarStyle == nil {
p.BarStyle = NewStyle()
}
if p.Total == 0 {
return nil
}
var before string
var after string
width := GetTerminalWidth()
currentPercentage := int(internal.PercentageRound(float64(int64(p.Total)), float64(int64(p.Current))))
decoratorCount := Gray("[") + LightWhite(p.Current) + Gray("/") + LightWhite(p.Total) + Gray("]")
decoratorCurrentPercentage := color.RGB(NewRGB(255, 0, 0).Fade(0, float32(p.Total), float32(p.Current), NewRGB(0, 255, 0)).GetValues()).
Sprint(strconv.Itoa(currentPercentage) + "%")
decoratorTitle := p.TitleStyle.Sprint(p.Title)
if p.ShowTitle {
before += decoratorTitle + " "
}
if p.ShowCount {
before += decoratorCount + " "
}
after += " "
if p.ShowPercentage {
after += decoratorCurrentPercentage + " "
}
if p.ShowElapsedTime {
after += "| " + p.parseElapsedTime()
}
barMaxLength := width - len(RemoveColorFromString(before)) - len(RemoveColorFromString(after)) - 1
barCurrentLength := (p.Current * barMaxLength) / p.Total
barFiller := strings.Repeat(p.BarFiller, barMaxLength-barCurrentLength)
bar := p.BarStyle.Sprint(strings.Repeat(p.BarCharacter, barCurrentLength)+p.LastCharacter) + barFiller
if !RawOutput {
Printo(before + bar + after)
}
return p
}
// Add to current value.
func (p *ProgressbarPrinter) Add(count int) *ProgressbarPrinter {
if p.Total == 0 {
return nil
}
p.Current += count
p.updateProgress()
if p.Current == p.Total {
p.Stop()
}
return p
}
// Start the ProgressbarPrinter.
func (p ProgressbarPrinter) Start() (*ProgressbarPrinter, error) {
if RawOutput && p.ShowTitle {
Println(p.Title)
}
p.IsActive = true
ActiveProgressBarPrinters = append(ActiveProgressBarPrinters, &p)
p.startedAt = time.Now()
p.updateProgress()
return &p, nil
}
// Stop the ProgressbarPrinter.
func (p *ProgressbarPrinter) Stop() (*ProgressbarPrinter, error) {
if !p.IsActive {
return p, nil
}
p.IsActive = false
if p.RemoveWhenDone {
clearLine()
Printo()
} else {
Println()
}
return p, nil
}
// GenericStart runs Start, but returns a LivePrinter.
// This is used for the interface LivePrinter.
// You most likely want to use Start instead of this in your program.
func (p ProgressbarPrinter) GenericStart() (*LivePrinter, error) {
p2, _ := p.Start()
lp := LivePrinter(p2)
return &lp, nil
}
// GenericStop runs Stop, but returns a LivePrinter.
// This is used for the interface LivePrinter.
// You most likely want to use Stop instead of this in your program.
func (p ProgressbarPrinter) GenericStop() (*LivePrinter, error) {
p2, _ := p.Stop()
lp := LivePrinter(p2)
return &lp, nil
}
// GetElapsedTime returns the elapsed time, since the ProgressbarPrinter was started.
func (p *ProgressbarPrinter) GetElapsedTime() time.Duration {
return time.Since(p.startedAt)
}
func (p *ProgressbarPrinter) parseElapsedTime() string {
s := p.GetElapsedTime().Round(p.ElapsedTimeRoundingFactor).String()
return s
}

67
vendor/github.com/pterm/pterm/pterm.go generated vendored Normal file
View File

@@ -0,0 +1,67 @@
// Package pterm is a modern go module to beautify console output.
// It can be used without configuration, but if desired, everything can be customized down to the smallest detail.
// View the animated examples here: https://github.com/pterm/pterm#-examples
package pterm
import "github.com/gookit/color"
var (
// Output completely disables output from pterm if set to false. Can be used in CLI application quiet mode.
Output = true
// PrintDebugMessages sets if messages printed by the DebugPrinter should be printed.
PrintDebugMessages = false
// RawOutput is set to true if pterm.DisableStyling() was called.
// The variable indicates that PTerm will not add additional styling to text.
// Use pterm.DisableStyling() or pterm.EnableStyling() to change this variable.
// Changing this variable directly, will disable or enable the output of colored text.
RawOutput = false
)
func init() {
color.ForceColor()
}
// EnableOutput enables the output of PTerm.
func EnableOutput() {
Output = true
}
// DisableOutput disables the output of PTerm.
func DisableOutput() {
Output = false
}
// EnableDebugMessages enables the output of debug printers.
func EnableDebugMessages() {
PrintDebugMessages = true
}
// DisableDebugMessages disables the output of debug printers.
func DisableDebugMessages() {
PrintDebugMessages = false
}
// EnableStyling enables the default PTerm styling.
// This also calls EnableColor.
func EnableStyling() {
RawOutput = false
EnableColor()
}
// DisableStyling sets PTerm to RawOutput mode and disables all of PTerms styling.
// You can use this to print to text files etc.
// This also calls DisableColor.
func DisableStyling() {
RawOutput = true
DisableColor()
}
// RecalculateTerminalSize updates already initialized terminal dimensions. Has to be called after a termina resize to guarantee proper rendering. Applies only to new instances.
func RecalculateTerminalSize() {
// keep in sync with DefaultBarChart
DefaultBarChart.Width = GetTerminalWidth() * 2 / 3
DefaultBarChart.Height = GetTerminalHeight() * 2 / 3
DefaultParagraph.MaxWidth = GetTerminalWidth()
}

176
vendor/github.com/pterm/pterm/rgb.go generated vendored Normal file
View File

@@ -0,0 +1,176 @@
package pterm
import (
"fmt"
"strconv"
"strings"
"github.com/gookit/color"
"github.com/pterm/pterm/internal"
)
// RGB color model is an additive color model in which red, green, and blue light are added together in various ways to reproduce a broad array of colors.
// The name of the model comes from the initials of the three additive primary colors, red, green, and blue.
// https://en.wikipedia.org/wiki/RGB_color_model
type RGB struct {
R uint8
G uint8
B uint8
}
// GetValues returns the RGB values separately.
func (p RGB) GetValues() (r, g, b uint8) {
return p.R, p.G, p.B
}
// NewRGB returns a new RGB.
func NewRGB(r, g, b uint8) RGB {
return RGB{R: r, G: g, B: b}
}
// NewRGBFromHEX converts a HEX and returns a new RGB.
func NewRGBFromHEX(hex string) (RGB, error) {
hex = strings.ToLower(hex)
hex = strings.ReplaceAll(hex, "#", "")
hex = strings.ReplaceAll(hex, "0x", "")
if len(hex) == 3 {
hex = string([]byte{hex[0], hex[0], hex[1], hex[1], hex[2], hex[2]})
}
if len(hex) != 6 {
return RGB{}, ErrHexCodeIsInvalid
}
i64, err := strconv.ParseInt(hex, 16, 32)
if err != nil {
return RGB{}, err
}
c := int(i64)
return RGB{
R: uint8(c >> 16),
G: uint8((c & 0x00FF00) >> 8),
B: uint8(c & 0x0000FF),
}, nil
}
// Fade fades one RGB value (over other RGB values) to another RGB value, by giving the function a minimum, maximum and current value.
func (p RGB) Fade(min, max, current float32, end ...RGB) RGB {
if min < 0 {
max -= min
current -= min
min = 0
}
if len(end) == 1 {
return RGB{
R: uint8(internal.MapRangeToRange(min, max, float32(p.R), float32(end[0].R), current)),
G: uint8(internal.MapRangeToRange(min, max, float32(p.G), float32(end[0].G), current)),
B: uint8(internal.MapRangeToRange(min, max, float32(p.B), float32(end[0].B), current)),
}
} else if len(end) > 1 {
f := (max - min) / float32(len(end))
tempCurrent := current
if f > current {
return p.Fade(min, f, current, end[0])
} else {
for i := 0; i < len(end)-1; i++ {
tempCurrent -= f
if f > tempCurrent {
return end[i].Fade(min, min+f, tempCurrent, end[i+1])
}
}
}
}
return p
}
// Sprint formats using the default formats for its operands and returns the resulting string.
// Spaces are added between operands when neither is a string.
func (p RGB) Sprint(a ...interface{}) string {
return color.RGB(p.R, p.G, p.B).Sprint(a...)
}
// Sprintln formats using the default formats for its operands and returns the resulting string.
// Spaces are always added between operands and a newline is appended.
func (p RGB) Sprintln(a ...interface{}) string {
return p.Sprint(Sprintln(a...))
}
// Sprintf formats according to a format specifier and returns the resulting string.
func (p RGB) Sprintf(format string, a ...interface{}) string {
return p.Sprint(Sprintf(format, a...))
}
// Sprintfln formats according to a format specifier and returns the resulting string.
// Spaces are always added between operands and a newline is appended.
func (p RGB) Sprintfln(format string, a ...interface{}) string {
return p.Sprintf(format, a...) + "\n"
}
// Print formats using the default formats for its operands and writes to standard output.
// Spaces are added between operands when neither is a string.
// It returns the number of bytes written and any write error encountered.
func (p RGB) Print(a ...interface{}) *TextPrinter {
Print(p.Sprint(a...))
tp := TextPrinter(p)
return &tp
}
// Println formats using the default formats for its operands and writes to standard output.
// Spaces are always added between operands and a newline is appended.
// It returns the number of bytes written and any write error encountered.
func (p RGB) Println(a ...interface{}) *TextPrinter {
Print(p.Sprintln(a...))
tp := TextPrinter(p)
return &tp
}
// Printf formats according to a format specifier and writes to standard output.
// It returns the number of bytes written and any write error encountered.
func (p RGB) Printf(format string, a ...interface{}) *TextPrinter {
Print(p.Sprintf(format, a...))
tp := TextPrinter(p)
return &tp
}
// Printfln formats according to a format specifier and writes to standard output.
// Spaces are always added between operands and a newline is appended.
// It returns the number of bytes written and any write error encountered.
func (p RGB) Printfln(format string, a ...interface{}) *TextPrinter {
Print(p.Sprintfln(format, a...))
tp := TextPrinter(p)
return &tp
}
// PrintOnError prints every error which is not nil.
// If every error is nil, nothing will be printed.
// This can be used for simple error checking.
func (p RGB) PrintOnError(a ...interface{}) *TextPrinter {
for _, arg := range a {
if err, ok := arg.(error); ok {
if err != nil {
p.Println(err)
}
}
}
tp := TextPrinter(p)
return &tp
}
// PrintOnErrorf wraps every error which is not nil and prints it.
// If every error is nil, nothing will be printed.
// This can be used for simple error checking.
func (p RGB) PrintOnErrorf(format string, a ...interface{}) *TextPrinter {
for _, arg := range a {
if err, ok := arg.(error); ok {
if err != nil {
p.Println(fmt.Errorf(format, err))
}
}
}
tp := TextPrinter(p)
return &tp
}

166
vendor/github.com/pterm/pterm/section_printer.go generated vendored Normal file
View File

@@ -0,0 +1,166 @@
package pterm
import (
"fmt"
"strings"
)
// DefaultSection is the default section printer.
var DefaultSection = SectionPrinter{
Style: &ThemeDefault.SectionStyle,
Level: 1,
TopPadding: 1,
BottomPadding: 1,
IndentCharacter: "#",
}
// SectionPrinter prints a new section title.
// It can be used to structure longer text, or different chapters of your program.
type SectionPrinter struct {
Style *Style
Level int
IndentCharacter string
TopPadding int
BottomPadding int
}
// WithStyle returns a new SectionPrinter with a specific style.
func (p SectionPrinter) WithStyle(style *Style) *SectionPrinter {
p.Style = style
return &p
}
// WithLevel returns a new SectionPrinter with a specific level.
func (p SectionPrinter) WithLevel(level int) *SectionPrinter {
p.Level = level
return &p
}
// WithIndentCharacter returns a new SectionPrinter with a specific IndentCharacter.
func (p SectionPrinter) WithIndentCharacter(char string) *SectionPrinter {
p.IndentCharacter = char
return &p
}
// WithTopPadding returns a new SectionPrinter with a specific top padding.
func (p SectionPrinter) WithTopPadding(padding int) *SectionPrinter {
p.TopPadding = padding
return &p
}
// WithBottomPadding returns a new SectionPrinter with a specific top padding.
func (p SectionPrinter) WithBottomPadding(padding int) *SectionPrinter {
p.BottomPadding = padding
return &p
}
// Sprint formats using the default formats for its operands and returns the resulting string.
// Spaces are added between operands when neither is a string.
func (p SectionPrinter) Sprint(a ...interface{}) string {
if p.Style == nil {
p.Style = NewStyle()
}
var ret string
for i := 0; i < p.TopPadding; i++ {
ret += "\n"
}
if p.Level > 0 {
ret += strings.Repeat(p.IndentCharacter, p.Level) + " "
}
ret += p.Style.Sprint(a...)
for i := 0; i < p.BottomPadding; i++ {
ret += "\n"
}
return ret
}
// Sprintln formats using the default formats for its operands and returns the resulting string.
// Spaces are always added between operands and a newline is appended.
func (p SectionPrinter) Sprintln(a ...interface{}) string {
str := fmt.Sprintln(a...)
return Sprint(p.Sprint(str))
}
// Sprintf formats according to a format specifier and returns the resulting string.
func (p SectionPrinter) Sprintf(format string, a ...interface{}) string {
return p.Sprint(Sprintf(format, a...))
}
// Sprintfln formats according to a format specifier and returns the resulting string.
// Spaces are always added between operands and a newline is appended.
func (p SectionPrinter) Sprintfln(format string, a ...interface{}) string {
return p.Sprintf(format, a...) + "\n"
}
// Print formats using the default formats for its operands and writes to standard output.
// Spaces are added between operands when neither is a string.
// It returns the number of bytes written and any write error encountered.
func (p *SectionPrinter) Print(a ...interface{}) *TextPrinter {
Print(p.Sprint(a...))
tp := TextPrinter(p)
return &tp
}
// Println formats using the default formats for its operands and writes to standard output.
// Spaces are always added between operands and a newline is appended.
// It returns the number of bytes written and any write error encountered.
func (p *SectionPrinter) Println(a ...interface{}) *TextPrinter {
Print(p.Sprintln(a...))
tp := TextPrinter(p)
return &tp
}
// Printf formats according to a format specifier and writes to standard output.
// It returns the number of bytes written and any write error encountered.
func (p *SectionPrinter) Printf(format string, a ...interface{}) *TextPrinter {
Print(p.Sprintf(format, a...))
tp := TextPrinter(p)
return &tp
}
// Printfln formats according to a format specifier and writes to standard output.
// Spaces are always added between operands and a newline is appended.
// It returns the number of bytes written and any write error encountered.
func (p *SectionPrinter) Printfln(format string, a ...interface{}) *TextPrinter {
Print(p.Sprintfln(format, a...))
tp := TextPrinter(p)
return &tp
}
// PrintOnError prints every error which is not nil.
// If every error is nil, nothing will be printed.
// This can be used for simple error checking.
func (p *SectionPrinter) PrintOnError(a ...interface{}) *TextPrinter {
for _, arg := range a {
if err, ok := arg.(error); ok {
if err != nil {
p.Println(err)
}
}
}
tp := TextPrinter(p)
return &tp
}
// PrintOnErrorf wraps every error which is not nil and prints it.
// If every error is nil, nothing will be printed.
// This can be used for simple error checking.
func (p *SectionPrinter) PrintOnErrorf(format string, a ...interface{}) *TextPrinter {
for _, arg := range a {
if err, ok := arg.(error); ok {
if err != nil {
p.Println(fmt.Errorf(format, err))
}
}
}
tp := TextPrinter(p)
return &tp
}

223
vendor/github.com/pterm/pterm/spinner_printer.go generated vendored Normal file
View File

@@ -0,0 +1,223 @@
package pterm
import (
"time"
"github.com/pterm/pterm/internal"
)
var activeSpinnerPrinters []*SpinnerPrinter
// DefaultSpinner is the default SpinnerPrinter.
var DefaultSpinner = SpinnerPrinter{
Sequence: []string{"▀ ", " ▀", " ▄", "▄ "},
Style: &ThemeDefault.SpinnerStyle,
Delay: time.Millisecond * 200,
ShowTimer: true,
TimerRoundingFactor: time.Second,
TimerStyle: &ThemeDefault.TimerStyle,
MessageStyle: &ThemeDefault.SpinnerTextStyle,
SuccessPrinter: &Success,
FailPrinter: &Error,
WarningPrinter: &Warning,
}
// SpinnerPrinter is a loading animation, which can be used if the progress is unknown.
// It's an animation loop, which can have a text and supports throwing errors or warnings.
// A TextPrinter is used to display all outputs, after the SpinnerPrinter is done.
type SpinnerPrinter struct {
Text string
Sequence []string
Style *Style
Delay time.Duration
MessageStyle *Style
SuccessPrinter TextPrinter
FailPrinter TextPrinter
WarningPrinter TextPrinter
RemoveWhenDone bool
ShowTimer bool
TimerRoundingFactor time.Duration
TimerStyle *Style
IsActive bool
startedAt time.Time
currentSequence string
}
// WithText adds a text to the SpinnerPrinter.
func (s SpinnerPrinter) WithText(text string) *SpinnerPrinter {
s.Text = text
return &s
}
// WithSequence adds a sequence to the SpinnerPrinter.
func (s SpinnerPrinter) WithSequence(sequence ...string) *SpinnerPrinter {
s.Sequence = sequence
return &s
}
// WithStyle adds a style to the SpinnerPrinter.
func (s SpinnerPrinter) WithStyle(style *Style) *SpinnerPrinter {
s.Style = style
return &s
}
// WithDelay adds a delay to the SpinnerPrinter.
func (s SpinnerPrinter) WithDelay(delay time.Duration) *SpinnerPrinter {
s.Delay = delay
return &s
}
// WithMessageStyle adds a style to the SpinnerPrinter message.
func (s SpinnerPrinter) WithMessageStyle(style *Style) *SpinnerPrinter {
s.MessageStyle = style
return &s
}
// WithRemoveWhenDone removes the SpinnerPrinter after it is done.
func (s SpinnerPrinter) WithRemoveWhenDone(b ...bool) *SpinnerPrinter {
s.RemoveWhenDone = internal.WithBoolean(b)
return &s
}
// WithShowTimer shows how long the spinner is running.
func (s SpinnerPrinter) WithShowTimer(b ...bool) *SpinnerPrinter {
s.ShowTimer = internal.WithBoolean(b)
return &s
}
// WithTimerRoundingFactor sets the rounding factor for the timer.
func (s SpinnerPrinter) WithTimerRoundingFactor(factor time.Duration) *SpinnerPrinter {
s.TimerRoundingFactor = factor
return &s
}
// WithTimerStyle adds a style to the SpinnerPrinter timer.
func (s SpinnerPrinter) WithTimerStyle(style *Style) *SpinnerPrinter {
s.TimerStyle = style
return &s
}
// UpdateText updates the message of the active SpinnerPrinter.
// Can be used live.
func (s *SpinnerPrinter) UpdateText(text string) {
s.Text = text
if !RawOutput {
clearLine()
Printo(s.Style.Sprint(s.currentSequence) + " " + s.MessageStyle.Sprint(s.Text))
}
if RawOutput {
Println(s.Text)
}
}
// Start the SpinnerPrinter.
func (s SpinnerPrinter) Start(text ...interface{}) (*SpinnerPrinter, error) {
s.IsActive = true
s.startedAt = time.Now()
activeSpinnerPrinters = append(activeSpinnerPrinters, &s)
if len(text) != 0 {
s.Text = Sprint(text...)
}
if RawOutput {
Println(s.Text)
}
go func() {
for s.IsActive {
for _, seq := range s.Sequence {
if !s.IsActive || RawOutput {
continue
}
var timer string
if s.ShowTimer {
timer = " (" + time.Since(s.startedAt).Round(s.TimerRoundingFactor).String() + ")"
}
Printo(s.Style.Sprint(seq) + " " + s.MessageStyle.Sprint(s.Text) + s.TimerStyle.Sprint(timer))
s.currentSequence = seq
time.Sleep(s.Delay)
}
}
}()
return &s, nil
}
// Stop terminates the SpinnerPrinter immediately.
// The SpinnerPrinter will not resolve into anything.
func (s *SpinnerPrinter) Stop() error {
s.IsActive = false
if s.RemoveWhenDone {
clearLine()
Printo()
} else {
Println()
}
return nil
}
// GenericStart runs Start, but returns a LivePrinter.
// This is used for the interface LivePrinter.
// You most likely want to use Start instead of this in your program.
func (s *SpinnerPrinter) GenericStart() (*LivePrinter, error) {
_, _ = s.Start()
lp := LivePrinter(s)
return &lp, nil
}
// GenericStop runs Stop, but returns a LivePrinter.
// This is used for the interface LivePrinter.
// You most likely want to use Stop instead of this in your program.
func (s *SpinnerPrinter) GenericStop() (*LivePrinter, error) {
_ = s.Stop()
lp := LivePrinter(s)
return &lp, nil
}
// Success displays the success printer.
// If no message is given, the text of the SpinnerPrinter will be reused as the default message.
func (s *SpinnerPrinter) Success(message ...interface{}) {
if s.SuccessPrinter == nil {
s.SuccessPrinter = &Success
}
if len(message) == 0 {
message = []interface{}{s.Text}
}
clearLine()
Printo(s.SuccessPrinter.Sprint(message...))
_ = s.Stop()
}
// Fail displays the fail printer.
// If no message is given, the text of the SpinnerPrinter will be reused as the default message.
func (s *SpinnerPrinter) Fail(message ...interface{}) {
if s.FailPrinter == nil {
s.FailPrinter = &Error
}
if len(message) == 0 {
message = []interface{}{s.Text}
}
clearLine()
Printo(s.FailPrinter.Sprint(message...))
_ = s.Stop()
}
// Warning displays the warning printer.
// If no message is given, the text of the SpinnerPrinter will be reused as the default message.
func (s *SpinnerPrinter) Warning(message ...interface{}) {
if s.WarningPrinter == nil {
s.WarningPrinter = &Warning
}
if len(message) == 0 {
message = []interface{}{s.Text}
}
clearLine()
Printo(s.WarningPrinter.Sprint(message...))
_ = s.Stop()
}

168
vendor/github.com/pterm/pterm/table_printer.go generated vendored Normal file
View File

@@ -0,0 +1,168 @@
package pterm
import (
"encoding/csv"
"strings"
"unicode/utf8"
"github.com/pterm/pterm/internal"
)
// DefaultTable contains standards, which can be used to print a TablePrinter.
var DefaultTable = TablePrinter{
Style: &ThemeDefault.TableStyle,
HeaderStyle: &ThemeDefault.TableHeaderStyle,
Separator: " | ",
SeparatorStyle: &ThemeDefault.TableSeparatorStyle,
LeftAlignment: true,
RightAlignment: false,
}
// TableData is the type that contains the data of a TablePrinter.
type TableData [][]string
// TablePrinter is able to render tables.
type TablePrinter struct {
Style *Style
HasHeader bool
HeaderStyle *Style
Separator string
SeparatorStyle *Style
Data TableData
Boxed bool
LeftAlignment bool
RightAlignment bool
}
// WithStyle returns a new TablePrinter with a specific Style.
func (p TablePrinter) WithStyle(style *Style) *TablePrinter {
p.Style = style
return &p
}
// WithHasHeader returns a new TablePrinter, where the first line is marked as a header.
func (p TablePrinter) WithHasHeader(b ...bool) *TablePrinter {
p.HasHeader = internal.WithBoolean(b)
return &p
}
// WithHeaderStyle returns a new TablePrinter with a specific HeaderStyle.
func (p TablePrinter) WithHeaderStyle(style *Style) *TablePrinter {
p.HeaderStyle = style
return &p
}
// WithSeparator returns a new TablePrinter with a specific separator.
func (p TablePrinter) WithSeparator(separator string) *TablePrinter {
p.Separator = separator
return &p
}
// WithSeparatorStyle returns a new TablePrinter with a specific SeparatorStyle.
func (p TablePrinter) WithSeparatorStyle(style *Style) *TablePrinter {
p.SeparatorStyle = style
return &p
}
// WithData returns a new TablePrinter with specific Data.
func (p TablePrinter) WithData(data [][]string) *TablePrinter {
p.Data = data
return &p
}
// WithCSVReader return a new TablePrinter with specified Data extracted from CSV.
func (p TablePrinter) WithCSVReader(reader *csv.Reader) *TablePrinter {
if records, err := reader.ReadAll(); err == nil {
p.Data = records
}
return &p
}
// WithBoxed returns a new TablePrinter with a box around the table.
func (p TablePrinter) WithBoxed(b ...bool) *TablePrinter {
p.Boxed = internal.WithBoolean(b)
return &p
}
// WithLeftAlignment returns a new TablePrinter with left alignment.
func (p TablePrinter) WithLeftAlignment(b ...bool) *TablePrinter {
b2 := internal.WithBoolean(b)
p.LeftAlignment = b2
p.RightAlignment = false
return &p
}
// WithRightAlignment returns a new TablePrinter with right alignment.
func (p TablePrinter) WithRightAlignment(b ...bool) *TablePrinter {
b2 := internal.WithBoolean(b)
p.LeftAlignment = false
p.RightAlignment = b2
return &p
}
// Srender renders the TablePrinter as a string.
func (p TablePrinter) Srender() (string, error) {
if p.Style == nil {
p.Style = NewStyle()
}
if p.SeparatorStyle == nil {
p.SeparatorStyle = NewStyle()
}
if p.HeaderStyle == nil {
p.HeaderStyle = NewStyle()
}
var ret string
maxColumnWidth := make(map[int]int)
for _, row := range p.Data {
for ci, column := range row {
columnLength := utf8.RuneCountInString(RemoveColorFromString(column))
if columnLength > maxColumnWidth[ci] {
maxColumnWidth[ci] = columnLength
}
}
}
for ri, row := range p.Data {
for ci, column := range row {
columnString := p.createColumnString(column, maxColumnWidth[ci])
if ci != len(row) && ci != 0 {
ret += p.Style.Sprint(p.SeparatorStyle.Sprint(p.Separator))
}
if p.HasHeader && ri == 0 {
ret += p.Style.Sprint(p.HeaderStyle.Sprint(columnString))
} else {
ret += p.Style.Sprint(columnString)
}
}
ret += "\n"
}
ret = strings.TrimSuffix(ret, "\n")
if p.Boxed {
ret = DefaultBox.Sprint(ret)
}
return ret, nil
}
func (p TablePrinter) createColumnString(data string, maxColumnWidth int) string {
columnLength := utf8.RuneCountInString(RemoveColorFromString(data))
if p.RightAlignment {
return strings.Repeat(" ", maxColumnWidth-columnLength) + data
}
return data + strings.Repeat(" ", maxColumnWidth-columnLength)
}
// Render prints the TablePrinter to the terminal.
func (p TablePrinter) Render() error {
s, _ := p.Srender()
Println(s)
return nil
}

64
vendor/github.com/pterm/pterm/terminal.go generated vendored Normal file
View File

@@ -0,0 +1,64 @@
package pterm
import (
"os"
"golang.org/x/term"
)
// FallbackTerminalWidth is the value used for GetTerminalWidth, if the actual width can not be detected
// You can override that value if necessary.
var FallbackTerminalWidth = 80
// FallbackTerminalHeight is the value used for GetTerminalHeight, if the actual height can not be detected
// You can override that value if necessary.
var FallbackTerminalHeight = 10
// forcedTerminalWidth, when set along with forcedTerminalHeight, forces the terminal width value.
var forcedTerminalWidth int = 0
// forcedTerminalHeight, when set along with forcedTerminalWidth, forces the terminal height value.
var forcedTerminalHeight int = 0
// GetTerminalWidth returns the terminal width of the active terminal.
func GetTerminalWidth() int {
if forcedTerminalWidth > 0 {
return forcedTerminalWidth
}
width, _, _ := GetTerminalSize()
return width
}
// GetTerminalHeight returns the terminal height of the active terminal.
func GetTerminalHeight() int {
if forcedTerminalHeight > 0 {
return forcedTerminalHeight
}
_, height, _ := GetTerminalSize()
return height
}
// GetTerminalSize returns the width and the height of the active terminal.
func GetTerminalSize() (width, height int, err error) {
if forcedTerminalWidth > 0 && forcedTerminalHeight > 0 {
return forcedTerminalWidth, forcedTerminalHeight, nil
}
w, h, err := term.GetSize(int(os.Stdout.Fd()))
if w <= 0 {
w = FallbackTerminalWidth
}
if h <= 0 {
h = FallbackTerminalHeight
}
if err != nil {
err = ErrTerminalSizeNotDetectable
}
return w, h, err
}
// setForcedTerminalSize turns off terminal size autodetection. Usuful for unified tests.
func SetForcedTerminalSize(width int, height int) {
forcedTerminalWidth = width
forcedTerminalHeight = height
RecalculateTerminalSize()
}

246
vendor/github.com/pterm/pterm/theme.go generated vendored Normal file
View File

@@ -0,0 +1,246 @@
package pterm
var (
// ThemeDefault is the default theme used by PTerm.
// If this variable is overwritten, the new value is used as default theme.
ThemeDefault = Theme{
PrimaryStyle: Style{FgCyan},
SecondaryStyle: Style{FgLightMagenta},
HighlightStyle: Style{Bold, FgYellow},
InfoMessageStyle: Style{FgLightCyan},
InfoPrefixStyle: Style{FgBlack, BgCyan},
SuccessMessageStyle: Style{FgGreen},
SuccessPrefixStyle: Style{FgBlack, BgGreen},
WarningMessageStyle: Style{FgYellow},
WarningPrefixStyle: Style{FgBlack, BgYellow},
ErrorMessageStyle: Style{FgLightRed},
ErrorPrefixStyle: Style{FgBlack, BgLightRed},
FatalMessageStyle: Style{FgLightRed},
FatalPrefixStyle: Style{FgBlack, BgLightRed},
DescriptionMessageStyle: Style{FgDefault},
DescriptionPrefixStyle: Style{FgLightWhite, BgDarkGray},
ScopeStyle: Style{FgGray},
ProgressbarBarStyle: Style{FgCyan},
ProgressbarTitleStyle: Style{FgLightCyan},
HeaderTextStyle: Style{FgLightWhite, Bold},
HeaderBackgroundStyle: Style{BgGray},
SpinnerStyle: Style{FgLightCyan},
SpinnerTextStyle: Style{FgLightWhite},
TableStyle: Style{FgDefault},
TableHeaderStyle: Style{FgLightCyan},
TableSeparatorStyle: Style{FgGray},
SectionStyle: Style{Bold, FgYellow},
BulletListTextStyle: Style{FgDefault},
BulletListBulletStyle: Style{FgGray},
TreeStyle: Style{FgGray},
TreeTextStyle: Style{FgDefault},
LetterStyle: Style{FgDefault},
DebugMessageStyle: Style{FgGray},
DebugPrefixStyle: Style{FgBlack, BgGray},
BoxStyle: Style{FgDefault},
BoxTextStyle: Style{FgDefault},
BarLabelStyle: Style{FgLightCyan},
BarStyle: Style{FgCyan},
TimerStyle: Style{FgGray},
}
)
// Theme for PTerm.
// Theme contains every Style used in PTerm. You can create own themes for your application or use one
// of the existing themes.
type Theme struct {
PrimaryStyle Style
SecondaryStyle Style
HighlightStyle Style
InfoMessageStyle Style
InfoPrefixStyle Style
SuccessMessageStyle Style
SuccessPrefixStyle Style
WarningMessageStyle Style
WarningPrefixStyle Style
ErrorMessageStyle Style
ErrorPrefixStyle Style
FatalMessageStyle Style
FatalPrefixStyle Style
DescriptionMessageStyle Style
DescriptionPrefixStyle Style
ScopeStyle Style
ProgressbarBarStyle Style
ProgressbarTitleStyle Style
HeaderTextStyle Style
HeaderBackgroundStyle Style
SpinnerStyle Style
SpinnerTextStyle Style
TimerStyle Style
TableStyle Style
TableHeaderStyle Style
TableSeparatorStyle Style
SectionStyle Style
BulletListTextStyle Style
BulletListBulletStyle Style
TreeStyle Style
TreeTextStyle Style
LetterStyle Style
DebugMessageStyle Style
DebugPrefixStyle Style
BoxStyle Style
BoxTextStyle Style
BarLabelStyle Style
BarStyle Style
}
// WithPrimaryStyle returns a new theme with overridden value.
func (t Theme) WithPrimaryStyle(style Style) Theme {
t.PrimaryStyle = style
return t
}
// WithSecondaryStyle returns a new theme with overridden value.
func (t Theme) WithSecondaryStyle(style Style) Theme {
t.SecondaryStyle = style
return t
}
// WithHighlightStyle returns a new theme with overridden value.
func (t Theme) WithHighlightStyle(style Style) Theme {
t.HighlightStyle = style
return t
}
// WithInfoMessageStyle returns a new theme with overridden value.
func (t Theme) WithInfoMessageStyle(style Style) Theme {
t.InfoMessageStyle = style
return t
}
// WithInfoPrefixStyle returns a new theme with overridden value.
func (t Theme) WithInfoPrefixStyle(style Style) Theme {
t.InfoPrefixStyle = style
return t
}
// WithSuccessMessageStyle returns a new theme with overridden value.
func (t Theme) WithSuccessMessageStyle(style Style) Theme {
t.SuccessMessageStyle = style
return t
}
// WithSuccessPrefixStyle returns a new theme with overridden value.
func (t Theme) WithSuccessPrefixStyle(style Style) Theme {
t.SuccessPrefixStyle = style
return t
}
// WithWarningMessageStyle returns a new theme with overridden value.
func (t Theme) WithWarningMessageStyle(style Style) Theme {
t.WarningMessageStyle = style
return t
}
// WithWarningPrefixStyle returns a new theme with overridden value.
func (t Theme) WithWarningPrefixStyle(style Style) Theme {
t.WarningPrefixStyle = style
return t
}
// WithErrorMessageStyle returns a new theme with overridden value.
func (t Theme) WithErrorMessageStyle(style Style) Theme {
t.ErrorMessageStyle = style
return t
}
// WithErrorPrefixStyle returns a new theme with overridden value.
func (t Theme) WithErrorPrefixStyle(style Style) Theme {
t.ErrorPrefixStyle = style
return t
}
// WithFatalMessageStyle returns a new theme with overridden value.
func (t Theme) WithFatalMessageStyle(style Style) Theme {
t.FatalMessageStyle = style
return t
}
// WithFatalPrefixStyle returns a new theme with overridden value.
func (t Theme) WithFatalPrefixStyle(style Style) Theme {
t.FatalPrefixStyle = style
return t
}
// WithDescriptionMessageStyle returns a new theme with overridden value.
func (t Theme) WithDescriptionMessageStyle(style Style) Theme {
t.DescriptionMessageStyle = style
return t
}
// WithDescriptionPrefixStyle returns a new theme with overridden value.
func (t Theme) WithDescriptionPrefixStyle(style Style) Theme {
t.DescriptionPrefixStyle = style
return t
}
// WithBulletListTextStyle returns a new theme with overridden value.
func (t Theme) WithBulletListTextStyle(style Style) Theme {
t.BulletListTextStyle = style
return t
}
// WithBulletListBulletStyle returns a new theme with overridden value.
func (t Theme) WithBulletListBulletStyle(style Style) Theme {
t.BulletListBulletStyle = style
return t
}
// WithLetterStyle returns a new theme with overridden value.
func (t Theme) WithLetterStyle(style Style) Theme {
t.LetterStyle = style
return t
}
// WithDebugMessageStyle returns a new theme with overridden value.
func (t Theme) WithDebugMessageStyle(style Style) Theme {
t.DebugMessageStyle = style
return t
}
// WithDebugPrefixStyle returns a new theme with overridden value.
func (t Theme) WithDebugPrefixStyle(style Style) Theme {
t.DebugPrefixStyle = style
return t
}
// WithTreeStyle returns a new theme with overridden value.
func (t Theme) WithTreeStyle(style Style) Theme {
t.TreeStyle = style
return t
}
// WithTreeTextStyle returns a new theme with overridden value.
func (t Theme) WithTreeTextStyle(style Style) Theme {
t.TreeTextStyle = style
return t
}
// WithBoxStyle returns a new theme with overridden value.
func (t Theme) WithBoxStyle(style Style) Theme {
t.BoxStyle = style
return t
}
// WithBoxTextStyle returns a new theme with overridden value.
func (t Theme) WithBoxTextStyle(style Style) Theme {
t.BoxTextStyle = style
return t
}
// WithBarLabelStyle returns a new theme with overridden value.
func (t Theme) WithBarLabelStyle(style Style) Theme {
t.BarLabelStyle = style
return t
}
// WithBarStyle returns a new theme with overridden value.
func (t Theme) WithBarStyle(style Style) Theme {
t.BarStyle = style
return t
}

185
vendor/github.com/pterm/pterm/tree_printer.go generated vendored Normal file
View File

@@ -0,0 +1,185 @@
package pterm
import (
"strings"
)
// TreeNode is used as items in a TreePrinter.
type TreeNode struct {
Children []TreeNode
Text string
}
// LeveledList is a list, which contains multiple LeveledListItem.
type LeveledList []LeveledListItem
// LeveledListItem combines a text with a specific level.
// The level is the indent, which would normally be seen in a BulletListPrinter.
type LeveledListItem struct {
Level int
Text string
}
// DefaultTree contains standards, which can be used to render a TreePrinter.
var DefaultTree = TreePrinter{
TreeStyle: &ThemeDefault.TreeStyle,
TextStyle: &ThemeDefault.TreeTextStyle,
TopRightCornerString: "└",
HorizontalString: "─",
TopRightDownString: "├",
VerticalString: "│",
RightDownLeftString: "┬",
Indent: 2,
}
// TreePrinter is able to render a list.
type TreePrinter struct {
Root TreeNode
TreeStyle *Style
TextStyle *Style
TopRightCornerString string
TopRightDownString string
HorizontalString string
VerticalString string
RightDownLeftString string
Indent int
}
// WithTreeStyle returns a new list with a specific tree style.
func (p TreePrinter) WithTreeStyle(style *Style) *TreePrinter {
p.TreeStyle = style
return &p
}
// WithTextStyle returns a new list with a specific text style.
func (p TreePrinter) WithTextStyle(style *Style) *TreePrinter {
p.TextStyle = style
return &p
}
// WithTopRightCornerString returns a new list with a specific TopRightCornerString.
func (p TreePrinter) WithTopRightCornerString(s string) *TreePrinter {
p.TopRightCornerString = s
return &p
}
// WithTopRightDownStringOngoing returns a new list with a specific TopRightDownString.
func (p TreePrinter) WithTopRightDownStringOngoing(s string) *TreePrinter {
p.TopRightDownString = s
return &p
}
// WithHorizontalString returns a new list with a specific HorizontalString.
func (p TreePrinter) WithHorizontalString(s string) *TreePrinter {
p.HorizontalString = s
return &p
}
// WithVerticalString returns a new list with a specific VerticalString.
func (p TreePrinter) WithVerticalString(s string) *TreePrinter {
p.VerticalString = s
return &p
}
// WithRoot returns a new list with a specific Root.
func (p TreePrinter) WithRoot(root TreeNode) *TreePrinter {
p.Root = root
return &p
}
// WithIndent returns a new list with a specific amount of spacing between the levels.
// Indent must be at least 1.
func (p TreePrinter) WithIndent(indent int) *TreePrinter {
if indent < 1 {
indent = 1
}
p.Indent = indent
return &p
}
// Render prints the list to the terminal.
func (p TreePrinter) Render() error {
s, _ := p.Srender()
Println(s)
return nil
}
// Srender renders the list as a string.
func (p TreePrinter) Srender() (string, error) {
if p.TreeStyle == nil {
p.TreeStyle = NewStyle()
}
if p.TextStyle == nil {
p.TextStyle = NewStyle()
}
return walkOverTree(p.Root.Children, p, ""), nil
}
// walkOverTree is a recursive function,
// which analyzes a TreePrinter and connects the items with specific characters.
// Returns TreePrinter as string.
func walkOverTree(list []TreeNode, p TreePrinter, prefix string) string {
var ret string
for i, item := range list {
if len(list) > i+1 { // if not last in list
if len(item.Children) == 0 { // if there are no children
ret += prefix + p.TreeStyle.Sprint(p.TopRightDownString) + strings.Repeat(p.TreeStyle.Sprint(p.HorizontalString), p.Indent) +
p.TextStyle.Sprint(item.Text) + "\n"
} else { // if there are children
ret += prefix + p.TreeStyle.Sprint(p.TopRightDownString) + strings.Repeat(p.TreeStyle.Sprint(p.HorizontalString), p.Indent-1) +
p.TreeStyle.Sprint(p.RightDownLeftString) + p.TextStyle.Sprint(item.Text) + "\n"
ret += walkOverTree(item.Children, p, prefix+p.TreeStyle.Sprint(p.VerticalString)+strings.Repeat(" ", p.Indent-1))
}
} else if len(list) == i+1 { // if last in list
if len(item.Children) == 0 { // if there are no children
ret += prefix + p.TreeStyle.Sprint(p.TopRightCornerString) + strings.Repeat(p.TreeStyle.Sprint(p.HorizontalString), p.Indent) +
p.TextStyle.Sprint(item.Text) + "\n"
} else { // if there are children
ret += prefix + p.TreeStyle.Sprint(p.TopRightCornerString) + strings.Repeat(p.TreeStyle.Sprint(p.HorizontalString), p.Indent-1) +
p.TreeStyle.Sprint(p.RightDownLeftString) + p.TextStyle.Sprint(item.Text) + "\n"
ret += walkOverTree(item.Children, p, prefix+strings.Repeat(" ", p.Indent))
}
}
}
return ret
}
// NewTreeFromLeveledList converts a TreeItems list to a TreeNode and returns it.
func NewTreeFromLeveledList(leveledListItems LeveledList) TreeNode {
if len(leveledListItems) == 0 {
return TreeNode{}
}
root := &TreeNode{
Children: []TreeNode{},
Text: leveledListItems[0].Text,
}
for i, record := range leveledListItems {
last := root
if record.Level < 0 {
record.Level = 0
leveledListItems[i].Level = 0
}
if len(leveledListItems)-1 != i {
if leveledListItems[i+1].Level-1 > record.Level {
leveledListItems[i+1].Level = record.Level + 1
}
}
for i := 0; i < record.Level; i++ {
lastIndex := len(last.Children) - 1
last = &last.Children[lastIndex]
}
last.Children = append(last.Children, TreeNode{
Children: []TreeNode{},
Text: record.Text,
})
}
return *root
}