mirror of https://github.com/schollz/croc.git
Enhance tab completion
This commit is contained in:
parent
f5a02df17b
commit
fae2e81b4a
|
@ -9,6 +9,7 @@ import (
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -365,10 +366,21 @@ func (t TabComplete) Do(line []rune, pos int) ([][]rune, int) {
|
||||||
// No completion
|
// No completion
|
||||||
return [][]rune{[]rune("")}, 0
|
return [][]rune{[]rune("")}, 0
|
||||||
}
|
}
|
||||||
|
if len(words) == 1 && nbCharacter == utils.NbPinNumbers {
|
||||||
|
// Check if word is indeed a number
|
||||||
|
_, err := strconv.Atoi(lastPartialWord)
|
||||||
|
if err == nil {
|
||||||
|
return [][]rune{[]rune("-")}, nbCharacter
|
||||||
|
}
|
||||||
|
}
|
||||||
var strArray [][]rune
|
var strArray [][]rune
|
||||||
for _, s := range mnemonicode.WordList {
|
for _, s := range mnemonicode.WordList {
|
||||||
if strings.HasPrefix(s, lastPartialWord) {
|
if strings.HasPrefix(s, lastPartialWord) {
|
||||||
strArray = append(strArray, []rune(s[nbCharacter:]))
|
var completionCandidate = s[nbCharacter:]
|
||||||
|
if len(words) <= mnemonicode.WordsRequired(utils.NbBytesWords) {
|
||||||
|
completionCandidate += "-"
|
||||||
|
}
|
||||||
|
strArray = append(strArray, []rune(completionCandidate))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return strArray, nbCharacter
|
return strArray, nbCharacter
|
||||||
|
|
|
@ -27,6 +27,9 @@ import (
|
||||||
"github.com/schollz/mnemonicode"
|
"github.com/schollz/mnemonicode"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const NbPinNumbers = 4
|
||||||
|
const NbBytesWords = 4
|
||||||
|
|
||||||
// Get or create home directory
|
// Get or create home directory
|
||||||
func GetConfigDir() (homedir string, err error) {
|
func GetConfigDir() (homedir string, err error) {
|
||||||
homedir, err = os.UserHomeDir()
|
homedir, err = os.UserHomeDir()
|
||||||
|
@ -186,7 +189,7 @@ func GenerateRandomPin() string {
|
||||||
s := ""
|
s := ""
|
||||||
max := new(big.Int)
|
max := new(big.Int)
|
||||||
max.SetInt64(9)
|
max.SetInt64(9)
|
||||||
for i := 0; i < 4; i++ {
|
for i := 0; i < NbPinNumbers; i++ {
|
||||||
v, err := rand.Int(rand.Reader, max)
|
v, err := rand.Int(rand.Reader, max)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -199,7 +202,7 @@ func GenerateRandomPin() string {
|
||||||
// GetRandomName returns mnemonicoded random name
|
// GetRandomName returns mnemonicoded random name
|
||||||
func GetRandomName() string {
|
func GetRandomName() string {
|
||||||
var result []string
|
var result []string
|
||||||
bs := make([]byte, 4)
|
bs := make([]byte, NbBytesWords)
|
||||||
rand.Read(bs)
|
rand.Read(bs)
|
||||||
result = mnemonicode.EncodeWordList(result, bs)
|
result = mnemonicode.EncodeWordList(result, bs)
|
||||||
return GenerateRandomPin() + "-" + strings.Join(result, "-")
|
return GenerateRandomPin() + "-" + strings.Join(result, "-")
|
||||||
|
|
Loading…
Reference in New Issue