Show shows the continue prompt. Example: result, _ := pterm.DefaultInteractiveContinue.Show("Do you want to apply the changes?") pterm.Println(result)
(text ...string)
| 120 | // result, _ := pterm.DefaultInteractiveContinue.Show("Do you want to apply the changes?") |
| 121 | // pterm.Println(result) |
| 122 | func (p InteractiveContinuePrinter) Show(text ...string) (string, error) { |
| 123 | var result string |
| 124 | |
| 125 | if len(text) == 0 || text[0] == "" { |
| 126 | text = []string{p.DefaultText} |
| 127 | } |
| 128 | |
| 129 | p.TextStyle.Print(text[0] + " " + p.getSuffix() + p.Delimiter) |
| 130 | |
| 131 | err := keyboard.Listen(func(keyInfo keys.Key) (stop bool, err error) { |
| 132 | if err != nil { |
| 133 | return false, fmt.Errorf("failed to get key: %w", err) |
| 134 | } |
| 135 | key := keyInfo.Code |
| 136 | char := keyInfo.String() |
| 137 | |
| 138 | switch key { |
| 139 | case keys.RuneKey: |
| 140 | for i, c := range p.Handles { |
| 141 | if !p.ShowShortHandles { |
| 142 | c = string([]rune(c)[0]) |
| 143 | } |
| 144 | if char == c || (i == p.DefaultValueIndex && strings.EqualFold(c, char)) { |
| 145 | p.OptionsStyle.Print(p.Options[i]) |
| 146 | Println() |
| 147 | result = p.Options[i] |
| 148 | return true, nil |
| 149 | } |
| 150 | } |
| 151 | case keys.Enter: |
| 152 | p.OptionsStyle.Print(p.Options[p.DefaultValueIndex]) |
| 153 | Println() |
| 154 | result = p.Options[p.DefaultValueIndex] |
| 155 | return true, nil |
| 156 | case keys.CtrlC: |
| 157 | internal.Exit(1) |
| 158 | return true, nil |
| 159 | } |
| 160 | return false, nil |
| 161 | }) |
| 162 | cursor.StartOfLine() |
| 163 | return result, err |
| 164 | } |
| 165 | |
| 166 | // getShortHandles returns the short hand answers for the continueation prompt |
| 167 | func (p InteractiveContinuePrinter) getShortHandles() []string { |