Skip to content

Commit 8b0b46f

Browse files
authored
Merge pull request #76 from smallstep/fix-brew-tests
Fix homebrew tests that fails trying to allocate a terminal.
2 parents 52b2663 + 6c23205 commit 8b0b46f

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

ui/ui.go

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,6 @@ func PrintSelected(name, value string, opts ...Option) error {
8787

8888
// Prompt creates a runs a promptui.Prompt with the given label.
8989
func Prompt(label string, opts ...Option) (string, error) {
90-
clean, err := preparePromptTerminal()
91-
if err != nil {
92-
return "", err
93-
}
94-
defer clean()
95-
9690
o := &options{
9791
promptTemplates: PromptTemplates(),
9892
}
@@ -103,6 +97,13 @@ func Prompt(label string, opts ...Option) (string, error) {
10397
return o.getValue()
10498
}
10599

100+
// Prompt using the terminal
101+
clean, err := preparePromptTerminal()
102+
if err != nil {
103+
return "", err
104+
}
105+
defer clean()
106+
106107
prompt := &promptui.Prompt{
107108
Label: label,
108109
Default: o.defaultValue,
@@ -120,12 +121,6 @@ func Prompt(label string, opts ...Option) (string, error) {
120121
// PromptPassword creates a runs a promptui.Prompt with the given label. This
121122
// prompt will mask the key entries with \r.
122123
func PromptPassword(label string, opts ...Option) ([]byte, error) {
123-
clean, err := preparePromptTerminal()
124-
if err != nil {
125-
return nil, err
126-
}
127-
defer clean()
128-
129124
// Using a not printable character as they work better than \r
130125
o := &options{
131126
mask: 1,
@@ -138,6 +133,13 @@ func PromptPassword(label string, opts ...Option) ([]byte, error) {
138133
return o.getValueBytes()
139134
}
140135

136+
// Prompt using the terminal
137+
clean, err := preparePromptTerminal()
138+
if err != nil {
139+
return nil, err
140+
}
141+
defer clean()
142+
141143
prompt := &promptui.Prompt{
142144
Label: label,
143145
Mask: o.mask,
@@ -175,17 +177,17 @@ func PromptPasswordGenerate(label string, opts ...Option) ([]byte, error) {
175177

176178
// Select creates and runs a promptui.Select with the given label and items.
177179
func Select(label string, items interface{}, opts ...Option) (int, string, error) {
180+
o := &options{
181+
selectTemplates: SelectTemplates(label),
182+
}
183+
o.apply(opts)
184+
178185
clean, err := prepareSelectTerminal()
179186
if err != nil {
180187
return 0, "", err
181188
}
182189
defer clean()
183190

184-
o := &options{
185-
selectTemplates: SelectTemplates(label),
186-
}
187-
o.apply(opts)
188-
189191
prompt := &promptui.Select{
190192
Label: label,
191193
Items: items,

0 commit comments

Comments
 (0)