0
0
Fork 0
mirror of https://github.com/schollz/croc.git synced 2025-10-11 13:21:00 +02:00

Implement tab completion for words

This commit is contained in:
BayLee4 2023-01-12 19:23:50 +01:00
parent 63feece074
commit 0024beaedc
No known key found for this signature in database
GPG key ID: F38A8009E8321253
3 changed files with 40 additions and 2 deletions

View file

@ -12,6 +12,7 @@ import (
"strings"
"time"
"github.com/chzyer/readline"
"github.com/schollz/cli/v2"
"github.com/schollz/croc/v9/src/comm"
"github.com/schollz/croc/v9/src/croc"
@ -19,6 +20,7 @@ import (
"github.com/schollz/croc/v9/src/tcp"
"github.com/schollz/croc/v9/src/utils"
log "github.com/schollz/logger"
"github.com/schollz/mnemonicode"
"github.com/schollz/pake/v3"
)
@ -353,6 +355,24 @@ func saveConfig(c *cli.Context, crocOptions croc.Options) {
}
}
type TabComplete struct{}
func (t TabComplete) Do(line []rune, pos int) ([][]rune, int) {
var words = strings.SplitAfter(string(line), "-")
var last_partial_word = words[len(words)-1]
if len(last_partial_word) == 0 {
// No completion
return [][]rune{[]rune("")}, 0
}
var strArray [][]rune
for _, s := range mnemonicode.WordList {
if strings.HasPrefix(s, last_partial_word) {
strArray = append(strArray, []rune(s[len(last_partial_word):]))
}
}
return strArray, len(last_partial_word)
}
func receive(c *cli.Context) (err error) {
comm.Socks5Proxy = c.String("socks5")
crocOptions := croc.Options{
@ -431,7 +451,17 @@ func receive(c *cli.Context) (err error) {
}
if crocOptions.SharedSecret == "" {
crocOptions.SharedSecret = utils.GetInput("Enter receive code: ")
l, err := readline.NewEx(&readline.Config{
Prompt: "Enter receive code: ",
AutoComplete: TabComplete{},
})
if err != nil {
return err
}
crocOptions.SharedSecret, err = l.Readline()
if err != nil {
return err
}
}
if c.String("out") != "" {
if err = os.Chdir(c.String("out")); err != nil {