diff --git a/prompt.go b/prompt.go index c42c8b3..d1a9e3b 100644 --- a/prompt.go +++ b/prompt.go @@ -4,6 +4,7 @@ import ( "crypto/ecdsa" "fmt" "math/big" + "strings" "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/common" @@ -23,6 +24,11 @@ func MustSelectContractABI(abis map[string]abi.ABI) abi.ABI { Label: fmt.Sprintf("Select the contract to interact (total: %d)", len(abis)), Items: contractNames, Size: DefaultPromptListSize, + Searcher: func(input string, index int) bool { + // if there is a method name that contains the input, return true + return strings.Contains(contractNames[index], input) + }, + StartInSearchMode: shouldSupportSearchMode(len(abis)), } _, selected, err := prompt.Run() @@ -98,6 +104,11 @@ func MustSelectMethod(contractABI abi.ABI, rw MethodType) (string, abi.Method) { Label: fmt.Sprintf("Select Method (total: %d)", len(methodNames)), Items: methodNames, Size: DefaultPromptListSize, + Searcher: func(input string, index int) bool { + // if there is a method name that contains the input, return true + return strings.Contains(methodNames[index], input) + }, + StartInSearchMode: shouldSupportSearchMode(len(methodNames)), } _, selectedMethod, err := prompt.Run() diff --git a/utils.go b/utils.go new file mode 100644 index 0000000..9d03544 --- /dev/null +++ b/utils.go @@ -0,0 +1,7 @@ +package main + +const SelectableListSize = 4 + +func shouldSupportSearchMode(listLen int) bool { + return listLen > SelectableListSize +}