Fix terminal keypad mode (#4042)

Fix terminal keypad mode
This commit is contained in:
Mikhail Shilkov 2020-03-11 08:55:36 +01:00 committed by GitHub
parent 74ffbfd9ba
commit f01208af3b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 24 additions and 0 deletions

View file

@ -13,6 +13,8 @@ CHANGELOG
- Ensure Python overlays work as part of our SDK generation
[#4043](https://github.com/pulumi/pulumi/pull/4043)
- Fix terminal gets into a state where UP/DOWN don't work with prompts.
[#4042](https://github.com/pulumi/pulumi/pull/4042)
- Ensure old provider is not used when configuration has changed
[#4051](https://github.com/pulumi/pulumi/pull/4051)

View file

@ -745,6 +745,8 @@ func chooseTemplate(templates []workspace.Template, opts display.Options) (works
continue
}
cmdutil.EndKeypadTransmitMode()
var option string
if err := survey.AskOne(&survey.Select{
Message: message,

View file

@ -197,6 +197,8 @@ func choosePolicyPackTemplate(templates []workspace.PolicyPackTemplate,
options, optionToTemplateMap := policyTemplatesToOptionArrayAndMap(templates)
cmdutil.EndKeypadTransmitMode()
var option string
if err := survey.AskOne(&survey.Select{
Message: message,

View file

@ -98,6 +98,8 @@ func locateStackResource(opts display.Options, snap *deploy.Snapshot, urn resour
optionMap[message] = ambiguousResource
}
cmdutil.EndKeypadTransmitMode()
var option string
if err := survey.AskOne(&survey.Select{
Message: prompt,
@ -146,6 +148,7 @@ func runTotalStateEdit(
surveycore.SelectFocusIcon = opts.Color.Colorize(colors.BrightGreen + ">" + colors.Reset)
prompt := opts.Color.Colorize(colors.Yellow + "warning" + colors.Reset + ": ")
prompt += "This command will edit your stack's state directly. Confirm?"
cmdutil.EndKeypadTransmitMode()
if err = survey.AskOne(&survey.Confirm{
Message: prompt,
}, &confirm, nil); err != nil || !confirm {

View file

@ -290,6 +290,8 @@ func chooseStack(
}
message = opts.Color.Colorize(colors.SpecPrompt + message + colors.Reset)
cmdutil.EndKeypadTransmitMode()
var option string
if err = survey.AskOne(&survey.Select{
Message: message,

View file

@ -18,6 +18,7 @@ import (
"bytes"
"context"
"fmt"
"github.com/pulumi/pulumi/pkg/util/cmdutil"
"os"
"strings"
@ -161,6 +162,8 @@ func confirmBeforeUpdating(kind apitype.UpdateKind, stack Stack,
colors.Reset)
}
cmdutil.EndKeypadTransmitMode()
// Now prompt the user for a yes, no, or details, and then proceed accordingly.
if err := survey.AskOne(&survey.Select{
Message: prompt,

View file

@ -95,6 +95,16 @@ func RemoveTrailingNewline(s string) string {
return s
}
// EndKeypadTransmitMode switches the terminal out of the keypad transmit 'application' mode back to 'normal' mode.
func EndKeypadTransmitMode() {
if runtime.GOOS != "windows" && Interactive() {
// Print an escape sequence to switch the keypad mode, same as 'tput rmkx'.
// Work around https://github.com/pulumi/pulumi/issues/3480.
// A better fix might be fixing upstream https://github.com/AlecAivazis/survey/issues/228.
fmt.Print("\033[?1l")
}
}
type Table struct {
Headers []string
Rows []TableRow // Rows of the table.