diff --git a/go.mod b/go.mod index b50d0df38..d87850a88 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/Scalingo/cli go 1.20 require ( - github.com/AlecAivazis/survey/v2 v2.3.6 + github.com/AlecAivazis/survey/v2 v2.3.7 github.com/Scalingo/go-scalingo/v6 v6.7.2 github.com/Scalingo/go-utils/errors/v2 v2.3.0 github.com/Scalingo/go-utils/logger v1.2.0 diff --git a/go.sum b/go.sum index c2fd1275c..97e5c4939 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -github.com/AlecAivazis/survey/v2 v2.3.6 h1:NvTuVHISgTHEHeBFqt6BHOe4Ny/NwGZr7w+F8S9ziyw= -github.com/AlecAivazis/survey/v2 v2.3.6/go.mod h1:4AuI9b7RjAR+G7v9+C4YSlX/YL3K3cWNXgWXOhllqvI= +github.com/AlecAivazis/survey/v2 v2.3.7 h1:6I/u8FvytdGsgonrYsVn2t8t4QiRnh6QSTqkkhIiSjQ= +github.com/AlecAivazis/survey/v2 v2.3.7/go.mod h1:xUTIdE4KCOIjsBAE1JYsUPoCqYdZ1reCfTwbto0Fduo= github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY= github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow= github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= @@ -186,7 +186,6 @@ golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220422013727-9388b58f7150/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -197,7 +196,6 @@ golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA= golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.0.0-20210503060354-a79de5458b56/go.mod h1:tfny5GFUkzUvx4ps4ajbZsCe5lw1metzhBm9T3x7oIY= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= @@ -207,6 +205,7 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4= diff --git a/vendor/github.com/AlecAivazis/survey/v2/confirm.go b/vendor/github.com/AlecAivazis/survey/v2/confirm.go index 9662e6cdb..1c23fb4d1 100644 --- a/vendor/github.com/AlecAivazis/survey/v2/confirm.go +++ b/vendor/github.com/AlecAivazis/survey/v2/confirm.go @@ -90,6 +90,7 @@ func (c *Confirm) getBool(showHelp bool, config *PromptConfig) (bool, error) { continue default: // we didnt get a valid answer, so print error and prompt again + //lint:ignore ST1005 it should be fine for this error message to have punctuation if err := c.Error(config, fmt.Errorf("%q is not a valid answer, please try again.", val)); err != nil { return c.Default, err } diff --git a/vendor/github.com/AlecAivazis/survey/v2/core/template.go b/vendor/github.com/AlecAivazis/survey/v2/core/template.go index 6b3d20cdc..02da879dc 100644 --- a/vendor/github.com/AlecAivazis/survey/v2/core/template.go +++ b/vendor/github.com/AlecAivazis/survey/v2/core/template.go @@ -2,6 +2,7 @@ package core import ( "bytes" + "os" "sync" "text/template" @@ -23,11 +24,22 @@ var TemplateFuncsNoColor = map[string]interface{}{ }, } -//RunTemplate returns two formatted strings given a template and -//the data it requires. The first string returned is generated for -//user-facing output and may or may not contain ANSI escape codes -//for colored output. The second string does not contain escape codes -//and can be used by the renderer for layout purposes. +// envColorDisabled returns if output colors are forbid by environment variables +func envColorDisabled() bool { + return os.Getenv("NO_COLOR") != "" || os.Getenv("CLICOLOR") == "0" +} + +// envColorForced returns if output colors are forced from environment variables +func envColorForced() bool { + val, ok := os.LookupEnv("CLICOLOR_FORCE") + return ok && val != "0" +} + +// RunTemplate returns two formatted strings given a template and +// the data it requires. The first string returned is generated for +// user-facing output and may or may not contain ANSI escape codes +// for colored output. The second string does not contain escape codes +// and can be used by the renderer for layout purposes. func RunTemplate(tmpl string, data interface{}) (string, string, error) { tPair, err := GetTemplatePair(tmpl) if err != nil { @@ -52,11 +64,11 @@ var ( memoMutex = &sync.RWMutex{} ) -//GetTemplatePair returns a pair of compiled templates where the -//first template is generated for user-facing output and the -//second is generated for use by the renderer. The second -//template does not contain any color escape codes, whereas -//the first template may or may not depending on DisableColor. +// GetTemplatePair returns a pair of compiled templates where the +// first template is generated for user-facing output and the +// second is generated for use by the renderer. The second +// template does not contain any color escape codes, whereas +// the first template may or may not depending on DisableColor. func GetTemplatePair(tmpl string) ([2]*template.Template, error) { memoMutex.RLock() if t, ok := memoizedGetTemplate[tmpl]; ok { @@ -74,7 +86,8 @@ func GetTemplatePair(tmpl string) ([2]*template.Template, error) { templatePair[1] = templateNoColor - if DisableColor { + envColorHide := envColorDisabled() && !envColorForced() + if DisableColor || envColorHide { templatePair[0] = templatePair[1] } else { templateWithColor, err := template.New("prompt").Funcs(TemplateFuncsWithColor).Parse(tmpl) diff --git a/vendor/github.com/AlecAivazis/survey/v2/core/write.go b/vendor/github.com/AlecAivazis/survey/v2/core/write.go index 94a886c36..2225e3b22 100644 --- a/vendor/github.com/AlecAivazis/survey/v2/core/write.go +++ b/vendor/github.com/AlecAivazis/survey/v2/core/write.go @@ -142,12 +142,12 @@ func (err errFieldNotMatch) Is(target error) bool { // implements the dynamic er // It returns the Question.Name that couldn't be matched with a destination field. // // Usage: -// err := survey.Ask(qs, &v); -// if err != nil { -// if name, ok := core.IsFieldNotMatch(err); ok { -// [...name is the not matched question name] -// } -// } +// +// if err := survey.Ask(qs, &v); err != nil { +// if name, ok := core.IsFieldNotMatch(err); ok { +// // name is the question name that did not match a field +// } +// } func IsFieldNotMatch(err error) (string, bool) { if err != nil { if v, ok := err.(errFieldNotMatch); ok { @@ -301,6 +301,7 @@ func copy(t reflect.Value, v reflect.Value) (err error) { case reflect.Float64: castVal, casterr = strconv.ParseFloat(vString, 64) default: + //lint:ignore ST1005 allow this error message to be capitalized return fmt.Errorf("Unable to convert from string to type %s", t.Kind()) } @@ -335,6 +336,7 @@ func copy(t reflect.Value, v reflect.Value) (err error) { } // we're copying an option answer to an incorrect type + //lint:ignore ST1005 allow this error message to be capitalized return fmt.Errorf("Unable to convert from OptionAnswer to type %s", t.Kind()) } diff --git a/vendor/github.com/AlecAivazis/survey/v2/input.go b/vendor/github.com/AlecAivazis/survey/v2/input.go index dbc7c08cd..047476386 100644 --- a/vendor/github.com/AlecAivazis/survey/v2/input.go +++ b/vendor/github.com/AlecAivazis/survey/v2/input.go @@ -127,14 +127,14 @@ func (i *Input) onRune(config *PromptConfig) terminal.OnRuneFn { ) if err == nil { - err = readLineAgain + err = errReadLineAgain } return []rune(i.typedAnswer), true, err }) } -var readLineAgain = errors.New("read line again") +var errReadLineAgain = errors.New("read line again") func (i *Input) Prompt(config *PromptConfig) (interface{}, error) { // render the template @@ -170,7 +170,7 @@ func (i *Input) Prompt(config *PromptConfig) (interface{}, error) { } line, err = rr.ReadLineWithDefault(0, line, i.onRune(config)) - if err == readLineAgain { + if err == errReadLineAgain { continue } @@ -207,20 +207,13 @@ func (i *Input) Prompt(config *PromptConfig) (interface{}, error) { } func (i *Input) Cleanup(config *PromptConfig, val interface{}) error { - // use the default answer when cleaning up the prompt if necessary - ans := i.answer - if ans == "" && i.Default != "" { - ans = i.Default - } - - // render the cleanup return i.Render( InputQuestionTemplate, InputTemplateData{ Input: *i, ShowAnswer: true, Config: config, - Answer: ans, + Answer: val.(string), }, ) } diff --git a/vendor/github.com/AlecAivazis/survey/v2/multiselect.go b/vendor/github.com/AlecAivazis/survey/v2/multiselect.go index 3eb834251..396169f3e 100644 --- a/vendor/github.com/AlecAivazis/survey/v2/multiselect.go +++ b/vendor/github.com/AlecAivazis/survey/v2/multiselect.go @@ -29,6 +29,7 @@ type MultiSelect struct { VimMode bool FilterMessage string Filter func(filter string, value string, index int) bool + Description func(value string, index int) string filter string selectedIndex int checked map[int]bool @@ -43,6 +44,7 @@ type MultiSelectTemplateData struct { Checked map[int]bool SelectedIndex int ShowHelp bool + Description func(value string, index int) string PageEntries []core.OptionAnswer Config *PromptConfig @@ -59,12 +61,19 @@ func (m MultiSelectTemplateData) IterateOption(ix int, opt core.OptionAnswer) in return copy } +func (m MultiSelectTemplateData) GetDescription(opt core.OptionAnswer) string { + if m.Description == nil { + return "" + } + return m.Description(opt.Value, opt.Index) +} + var MultiSelectQuestionTemplate = ` {{- define "option"}} {{- if eq .SelectedIndex .CurrentIndex }}{{color .Config.Icons.SelectFocus.Format }}{{ .Config.Icons.SelectFocus.Text }}{{color "reset"}}{{else}} {{end}} {{- if index .Checked .CurrentOpt.Index }}{{color .Config.Icons.MarkedOption.Format }} {{ .Config.Icons.MarkedOption.Text }} {{else}}{{color .Config.Icons.UnmarkedOption.Format }} {{ .Config.Icons.UnmarkedOption.Text }} {{end}} {{- color "reset"}} - {{- " "}}{{- .CurrentOpt.Value}} + {{- " "}}{{- .CurrentOpt.Value}}{{ if ne ($.GetDescription .CurrentOpt) "" }} - {{color "cyan"}}{{ $.GetDescription .CurrentOpt }}{{color "reset"}}{{end}} {{end}} {{- if .ShowHelp }}{{- color .Config.Icons.Help.Format }}{{ .Config.Icons.Help.Text }} {{ .Help }}{{color "reset"}}{{"\n"}}{{end}} {{- color .Config.Icons.Question.Format }}{{ .Config.Icons.Question.Text }} {{color "reset"}} @@ -179,6 +188,7 @@ func (m *MultiSelect) OnChange(key rune, config *PromptConfig) { SelectedIndex: idx, Checked: m.checked, ShowHelp: m.showingHelp, + Description: m.Description, PageEntries: opts, Config: config, } @@ -272,6 +282,7 @@ func (m *MultiSelect) Prompt(config *PromptConfig) (interface{}, error) { tmplData := MultiSelectTemplateData{ MultiSelect: *m, SelectedIndex: idx, + Description: m.Description, Checked: m.checked, PageEntries: opts, Config: config, @@ -342,6 +353,7 @@ func (m *MultiSelect) Cleanup(config *PromptConfig, val interface{}) error { Checked: m.checked, Answer: answer, ShowAnswer: true, + Description: m.Description, Config: config, }, ) diff --git a/vendor/github.com/AlecAivazis/survey/v2/password.go b/vendor/github.com/AlecAivazis/survey/v2/password.go index 877102c69..96a2ae89f 100644 --- a/vendor/github.com/AlecAivazis/survey/v2/password.go +++ b/vendor/github.com/AlecAivazis/survey/v2/password.go @@ -60,7 +60,7 @@ func (p *Password) Prompt(config *PromptConfig) (interface{}, error) { // no help msg? Just return any response if p.Help == "" { - line, err := rr.ReadLine('*') + line, err := rr.ReadLine(config.HideCharacter) return string(line), err } @@ -69,7 +69,7 @@ func (p *Password) Prompt(config *PromptConfig) (interface{}, error) { var line []rune // process answers looking for help prompt answer for { - line, err = rr.ReadLine('*') + line, err = rr.ReadLine(config.HideCharacter) if err != nil { return string(line), err } @@ -96,7 +96,7 @@ func (p *Password) Prompt(config *PromptConfig) (interface{}, error) { } lineStr := string(line) - p.AppendRenderedText(strings.Repeat("*", len(lineStr))) + p.AppendRenderedText(strings.Repeat(string(config.HideCharacter), len(lineStr))) return lineStr, err } diff --git a/vendor/github.com/AlecAivazis/survey/v2/renderer.go b/vendor/github.com/AlecAivazis/survey/v2/renderer.go index a89b061e0..a16207de0 100644 --- a/vendor/github.com/AlecAivazis/survey/v2/renderer.go +++ b/vendor/github.com/AlecAivazis/survey/v2/renderer.go @@ -3,8 +3,6 @@ package survey import ( "bytes" "fmt" - "unicode/utf8" - "github.com/AlecAivazis/survey/v2/core" "github.com/AlecAivazis/survey/v2/terminal" "golang.org/x/term" @@ -180,7 +178,8 @@ func (r *Renderer) countLines(buf bytes.Buffer) int { delim = len(bufBytes) // no new line found, read rest of text } - if lineWidth := utf8.RuneCount(bufBytes[curr:delim]); lineWidth > w { + str := string(bufBytes[curr:delim]) + if lineWidth := terminal.StringWidth(str); lineWidth > w { // account for word wrapping count += lineWidth / w if (lineWidth % w) == 0 { diff --git a/vendor/github.com/AlecAivazis/survey/v2/select.go b/vendor/github.com/AlecAivazis/survey/v2/select.go index 494f15d1b..1210122f4 100644 --- a/vendor/github.com/AlecAivazis/survey/v2/select.go +++ b/vendor/github.com/AlecAivazis/survey/v2/select.go @@ -2,6 +2,7 @@ package survey import ( "errors" + "fmt" "github.com/AlecAivazis/survey/v2/core" "github.com/AlecAivazis/survey/v2/terminal" @@ -31,7 +32,6 @@ type Select struct { Description func(value string, index int) string filter string selectedIndex int - useDefault bool showingHelp bool } @@ -103,8 +103,6 @@ func (s *Select) OnChange(key rune, config *PromptConfig) bool { // if the user pressed the up arrow or 'k' to emulate vim } else if (key == terminal.KeyArrowUp || (s.VimMode && key == 'k')) && len(options) > 0 { - s.useDefault = false - // if we are at the top of the list if s.selectedIndex == 0 { // start from the button @@ -116,7 +114,6 @@ func (s *Select) OnChange(key rune, config *PromptConfig) bool { // if the user pressed down or 'j' to emulate vim } else if (key == terminal.KeyTab || key == terminal.KeyArrowDown || (s.VimMode && key == 'j')) && len(options) > 0 { - s.useDefault = false // if we are at the bottom of the list if s.selectedIndex == len(options)-1 { // start from the top @@ -147,8 +144,6 @@ func (s *Select) OnChange(key rune, config *PromptConfig) bool { s.filter += string(key) // make sure vim mode is disabled s.VimMode = false - // make sure that we use the current value in the filtered list - s.useDefault = false } s.FilterMessage = "" @@ -207,7 +202,6 @@ func (s *Select) filterOptions(config *PromptConfig) []core.OptionAnswer { filter = config.Filter } - // for i, opt := range s.Options { // i the filter says to include the option if filter(s.filter, opt, i) { @@ -229,23 +223,29 @@ func (s *Select) Prompt(config *PromptConfig) (interface{}, error) { return "", errors.New("please provide options to select from") } - // start off with the first option selected - sel := 0 - // if there is a default - if s.Default != "" { - // find the choice - for i, opt := range s.Options { - // if the option corresponds to the default - if opt == s.Default { - // we found our initial value - sel = i - // stop looking - break + s.selectedIndex = 0 + if s.Default != nil { + switch defaultValue := s.Default.(type) { + case string: + var found bool + for i, opt := range s.Options { + if opt == defaultValue { + s.selectedIndex = i + found = true + } + } + if !found { + return "", fmt.Errorf("default value %q not found in options", defaultValue) + } + case int: + if defaultValue >= len(s.Options) { + return "", fmt.Errorf("default index %d exceeds the number of options", defaultValue) } + s.selectedIndex = defaultValue + default: + return "", errors.New("default value of select must be an int or string") } } - // save the selected index - s.selectedIndex = sel // figure out the page size pageSize := s.PageSize @@ -256,7 +256,7 @@ func (s *Select) Prompt(config *PromptConfig) (interface{}, error) { } // figure out the options and index to render - opts, idx := paginate(pageSize, core.OptionAnswerList(s.Options), sel) + opts, idx := paginate(pageSize, core.OptionAnswerList(s.Options), s.selectedIndex) cursor := s.NewCursor() cursor.Save() // for proper cursor placement during selection @@ -279,9 +279,6 @@ func (s *Select) Prompt(config *PromptConfig) (interface{}, error) { return "", err } - // by default, use the default value - s.useDefault = true - rr := s.NewRuneReader() _ = rr.SetTermMode() defer func() { @@ -304,45 +301,16 @@ func (s *Select) Prompt(config *PromptConfig) (interface{}, error) { break } } + options := s.filterOptions(config) s.filter = "" s.FilterMessage = "" - // the index to report - var val string - // if we are supposed to use the default value - if s.useDefault || s.selectedIndex >= len(options) { - // if there is a default value - if s.Default != nil { - // if the default is a string - if defaultString, ok := s.Default.(string); ok { - // use the default value - val = defaultString - // the default value could also be an interpret which is interpretted as the index - } else if defaultIndex, ok := s.Default.(int); ok { - val = s.Options[defaultIndex] - } else { - return val, errors.New("default value of select must be an int or string") - } - } else if len(options) > 0 { - // there is no default value so use the first - val = options[0].Value - } - // otherwise the selected index points to the value - } else if s.selectedIndex < len(options) { - // the - val = options[s.selectedIndex].Value - } - - // now that we have the value lets go hunt down the right index to return - idx = -1 - for i, optionValue := range s.Options { - if optionValue == val { - idx = i - } + if s.selectedIndex < len(options) { + return options[s.selectedIndex], err } - return core.OptionAnswer{Value: val, Index: idx}, err + return options[0], err } func (s *Select) Cleanup(config *PromptConfig, val interface{}) error { diff --git a/vendor/github.com/AlecAivazis/survey/v2/survey.go b/vendor/github.com/AlecAivazis/survey/v2/survey.go index 3e03b697a..aad73bbe7 100644 --- a/vendor/github.com/AlecAivazis/survey/v2/survey.go +++ b/vendor/github.com/AlecAivazis/survey/v2/survey.go @@ -60,6 +60,7 @@ func defaultAskOptions() *AskOptions { ShowCursor: false, RemoveSelectAll: false, RemoveSelectNone: false, + HideCharacter: '*', }, } } @@ -122,6 +123,7 @@ type PromptConfig struct { ShowCursor bool RemoveSelectAll bool RemoveSelectNone bool + HideCharacter rune } // Prompt is the primary interface for the objects that can take user input @@ -254,6 +256,17 @@ func WithShowCursor(ShowCursor bool) AskOpt { } } +// WithHideCharacter sets the default character shown instead of the password for password inputs +func WithHideCharacter(char rune) AskOpt { + return func(options *AskOptions) error { + // set the hide character + options.PromptConfig.HideCharacter = char + + // nothing went wrong + return nil + } +} + /* AskOne performs the prompt for a single prompt and asks for validation if required. Response types should be something that can be casted from the response type designated @@ -265,7 +278,6 @@ in the documentation. For example: } survey.AskOne(prompt, &name) - */ func AskOne(p Prompt, response interface{}, opts ...AskOpt) error { err := Ask([]*Question{{Prompt: p}}, response, opts...) diff --git a/vendor/github.com/AlecAivazis/survey/v2/terminal/display_posix.go b/vendor/github.com/AlecAivazis/survey/v2/terminal/display_posix.go index 466080875..fbd1b7947 100644 --- a/vendor/github.com/AlecAivazis/survey/v2/terminal/display_posix.go +++ b/vendor/github.com/AlecAivazis/survey/v2/terminal/display_posix.go @@ -1,3 +1,4 @@ +//go:build !windows // +build !windows package terminal diff --git a/vendor/github.com/AlecAivazis/survey/v2/terminal/error.go b/vendor/github.com/AlecAivazis/survey/v2/terminal/error.go index 710c36140..55eb66540 100644 --- a/vendor/github.com/AlecAivazis/survey/v2/terminal/error.go +++ b/vendor/github.com/AlecAivazis/survey/v2/terminal/error.go @@ -5,5 +5,6 @@ import ( ) var ( + //lint:ignore ST1012 keeping old name for backwards compatibility InterruptErr = errors.New("interrupt") ) diff --git a/vendor/github.com/AlecAivazis/survey/v2/terminal/output.go b/vendor/github.com/AlecAivazis/survey/v2/terminal/output.go index 6fe11c089..29102420c 100644 --- a/vendor/github.com/AlecAivazis/survey/v2/terminal/output.go +++ b/vendor/github.com/AlecAivazis/survey/v2/terminal/output.go @@ -1,3 +1,4 @@ +//go:build !windows // +build !windows package terminal diff --git a/vendor/github.com/AlecAivazis/survey/v2/terminal/runereader.go b/vendor/github.com/AlecAivazis/survey/v2/terminal/runereader.go index e881d7532..998e415e5 100644 --- a/vendor/github.com/AlecAivazis/survey/v2/terminal/runereader.go +++ b/vendor/github.com/AlecAivazis/survey/v2/terminal/runereader.go @@ -377,10 +377,41 @@ func (rr *RuneReader) ReadLineWithDefault(mask rune, d []rune, onRunes ...OnRune } } +// runeWidth returns the number of columns spanned by a rune when printed to the terminal func runeWidth(r rune) int { switch width.LookupRune(r).Kind() { case width.EastAsianWide, width.EastAsianFullwidth: return 2 } + + if !unicode.IsPrint(r) { + return 0 + } return 1 } + +// isAnsiMarker returns if a rune denotes the start of an ANSI sequence +func isAnsiMarker(r rune) bool { + return r == '\x1B' +} + +// isAnsiTerminator returns if a rune denotes the end of an ANSI sequence +func isAnsiTerminator(r rune) bool { + return (r >= 0x40 && r <= 0x5a) || (r == 0x5e) || (r >= 0x60 && r <= 0x7e) +} + +// StringWidth returns the visible width of a string when printed to the terminal +func StringWidth(str string) int { + w := 0 + ansi := false + + for _, r := range str { + // increase width only when outside of ANSI escape sequences + if ansi || isAnsiMarker(r) { + ansi = !isAnsiTerminator(r) + } else { + w += runeWidth(r) + } + } + return w +} diff --git a/vendor/github.com/AlecAivazis/survey/v2/terminal/runereader_bsd.go b/vendor/github.com/AlecAivazis/survey/v2/terminal/runereader_bsd.go index 6ea340923..57f101425 100644 --- a/vendor/github.com/AlecAivazis/survey/v2/terminal/runereader_bsd.go +++ b/vendor/github.com/AlecAivazis/survey/v2/terminal/runereader_bsd.go @@ -3,6 +3,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +//go:build darwin || dragonfly || freebsd || netbsd || openbsd // +build darwin dragonfly freebsd netbsd openbsd package terminal diff --git a/vendor/github.com/AlecAivazis/survey/v2/terminal/runereader_linux.go b/vendor/github.com/AlecAivazis/survey/v2/terminal/runereader_linux.go index 6dd60ea69..dc7ec670c 100644 --- a/vendor/github.com/AlecAivazis/survey/v2/terminal/runereader_linux.go +++ b/vendor/github.com/AlecAivazis/survey/v2/terminal/runereader_linux.go @@ -2,6 +2,7 @@ // Copyright 2013 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +//go:build linux && !ppc64le // +build linux,!ppc64le package terminal diff --git a/vendor/github.com/AlecAivazis/survey/v2/terminal/runereader_posix.go b/vendor/github.com/AlecAivazis/survey/v2/terminal/runereader_posix.go index 3b8460497..563a08115 100644 --- a/vendor/github.com/AlecAivazis/survey/v2/terminal/runereader_posix.go +++ b/vendor/github.com/AlecAivazis/survey/v2/terminal/runereader_posix.go @@ -1,3 +1,4 @@ +//go:build !windows // +build !windows // The terminal mode manipulation code is derived heavily from: diff --git a/vendor/github.com/AlecAivazis/survey/v2/terminal/runereader_ppc64le.go b/vendor/github.com/AlecAivazis/survey/v2/terminal/runereader_ppc64le.go index ae4eb0973..450f796c6 100644 --- a/vendor/github.com/AlecAivazis/survey/v2/terminal/runereader_ppc64le.go +++ b/vendor/github.com/AlecAivazis/survey/v2/terminal/runereader_ppc64le.go @@ -1,3 +1,4 @@ +//go:build ppc64le && linux // +build ppc64le,linux package terminal diff --git a/vendor/github.com/AlecAivazis/survey/v2/transform.go b/vendor/github.com/AlecAivazis/survey/v2/transform.go index 58d5193b0..a78ada392 100644 --- a/vendor/github.com/AlecAivazis/survey/v2/transform.go +++ b/vendor/github.com/AlecAivazis/survey/v2/transform.go @@ -3,6 +3,9 @@ package survey import ( "reflect" "strings" + + "golang.org/x/text/cases" + "golang.org/x/text/language" ) // TransformString returns a `Transformer` based on the "f" @@ -62,7 +65,7 @@ func ToLower(ans interface{}) interface{} { // return a nil value, meaning that the above answer // will not be affected by this call at all. func Title(ans interface{}) interface{} { - transformer := TransformString(strings.Title) + transformer := TransformString(cases.Title(language.English).String) return transformer(ans) } diff --git a/vendor/github.com/AlecAivazis/survey/v2/validate.go b/vendor/github.com/AlecAivazis/survey/v2/validate.go index f19614843..7f03b23ac 100644 --- a/vendor/github.com/AlecAivazis/survey/v2/validate.go +++ b/vendor/github.com/AlecAivazis/survey/v2/validate.go @@ -15,6 +15,7 @@ func Required(val interface{}) error { // if the value passed in is the zero value of the appropriate type if isZero(value) && value.Kind() != reflect.Bool { + //lint:ignore ST1005 this error message should render as capitalized return errors.New("Value is required") } return nil diff --git a/vendor/modules.txt b/vendor/modules.txt index 3c18a7943..25c029e17 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1,4 +1,4 @@ -# github.com/AlecAivazis/survey/v2 v2.3.6 +# github.com/AlecAivazis/survey/v2 v2.3.7 ## explicit; go 1.13 github.com/AlecAivazis/survey/v2 github.com/AlecAivazis/survey/v2/core