github.com/mutagen-io/mutagen@v0.18.0-rc1/pkg/prompting/response_mode.go (about)

     1  package prompting
     2  
     3  import (
     4  	"strings"
     5  )
     6  
     7  // ResponseMode encodes how a prompt response should be displayed and validated.
     8  type ResponseMode uint8
     9  
    10  const (
    11  	// ResponseModeSecret indicates that a prompt response shouldn't be echoed.
    12  	ResponseModeSecret ResponseMode = iota
    13  	// ResponseModeMasked indicates that a prompt response should be masked.
    14  	ResponseModeMasked
    15  	// ResponseModeEcho indicates that a prompt response should be echoed.
    16  	ResponseModeEcho
    17  )
    18  
    19  // echoedPromptSuffixes are the list of prompt suffixes known to be used by
    20  // OpenSSH for which responses should be echoed.
    21  var echoedPromptSuffixes = []string{
    22  	"(yes/no)? ",
    23  	"(yes/no): ",
    24  	"(yes/no/[fingerprint])? ",
    25  	"Please type 'yes', 'no' or the fingerprint: ",
    26  }
    27  
    28  // determineResponseMode attempts to determine the appropriate response mode for
    29  // a prompt based on the prompt text.
    30  func determineResponseMode(prompt string) ResponseMode {
    31  	// Check if this is an echoed prompt.
    32  	for _, suffix := range echoedPromptSuffixes {
    33  		if strings.HasSuffix(prompt, suffix) {
    34  			return ResponseModeEcho
    35  		}
    36  	}
    37  
    38  	// TODO: Are there any non-binary prompts from OpenSSH with responses that
    39  	// should be echoed? If so, we need to create a white-listed registry of
    40  	// regular expressions to match them.
    41  
    42  	// Otherwise assume this is a secret prompt.
    43  	return ResponseModeSecret
    44  }