...

Source file src/github.com/c-bata/go-prompt/shortcut.go

Documentation: github.com/c-bata/go-prompt

     1  package prompt
     2  
     3  func dummyExecutor(in string) {}
     4  
     5  // Input get the input data from the user and return it.
     6  func Input(prefix string, completer Completer, opts ...Option) string {
     7  	pt := New(dummyExecutor, completer)
     8  	pt.renderer.prefixTextColor = DefaultColor
     9  	pt.renderer.prefix = prefix
    10  
    11  	for _, opt := range opts {
    12  		if err := opt(pt); err != nil {
    13  			panic(err)
    14  		}
    15  	}
    16  	return pt.Input()
    17  }
    18  
    19  // Choose to the shortcut of input function to select from string array.
    20  // Deprecated: Maybe anyone want to use this.
    21  func Choose(prefix string, choices []string, opts ...Option) string {
    22  	completer := newChoiceCompleter(choices, FilterHasPrefix)
    23  	pt := New(dummyExecutor, completer)
    24  	pt.renderer.prefixTextColor = DefaultColor
    25  	pt.renderer.prefix = prefix
    26  
    27  	for _, opt := range opts {
    28  		if err := opt(pt); err != nil {
    29  			panic(err)
    30  		}
    31  	}
    32  	return pt.Input()
    33  }
    34  
    35  func newChoiceCompleter(choices []string, filter Filter) Completer {
    36  	s := make([]Suggest, len(choices))
    37  	for i := range choices {
    38  		s[i] = Suggest{Text: choices[i]}
    39  	}
    40  	return func(x Document) []Suggest {
    41  		return filter(s, x.GetWordBeforeCursor(), true)
    42  	}
    43  }
    44  

View as plain text