Skip to content

Commit

Permalink
Polish options that complete text automatically.
Browse files Browse the repository at this point in the history
  • Loading branch information
gjbae1212 committed Feb 16, 2020
1 parent 6e29b35 commit 4b70bd4
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ var (
)

var (
searchSuggest = prompt.Suggest{Text: "search", Description: "Search starred github repositories which matched text from Readme, topic, name ... and so on."}
searchSuggest = prompt.Suggest{Text: "search", Description: "Search starred github repositories which matched text from Readme, description, topic, name ... and so on."}
exitSuggest = prompt.Suggest{Text: "exit", Description: "Good bye."}
openSuggest = prompt.Suggest{Text: "open", Description: "Open a selected repository of found repositories to browser."}
listSuggest = prompt.Suggest{Text: "list", Description: "Show searched repositories currently."}
listSuggest = prompt.Suggest{Text: "list", Description: "Show searched repositories recently through search command."}

openNumSuggest = prompt.Suggest{Text: "num", Description: "Open url to browser using num value."}
openNameSuggest = prompt.Suggest{Text: "name", Description: "Open url to browser using name value."}
Expand Down Expand Up @@ -109,6 +109,33 @@ func completer(d prompt.Document) []prompt.Suggest {
for _, f := range foundList {
suggests = append(suggests, prompt.Suggest{Text: fmt.Sprintf("%s", f.FullName)})
}
break
}

if strings.HasPrefix(subText, "num") {
seps := strings.Split(subText, " ")
if len(seps) > 1 {
numText := strings.TrimSpace(strings.Join(seps[1:], " "))
for i, _ := range foundList {
if strings.HasPrefix(fmt.Sprintf("%d", i+1), numText) {
suggests = append(suggests, prompt.Suggest{Text: fmt.Sprintf("%d", i+1)})
}
}
break
}
}

if strings.HasPrefix(subText, "name") {
seps := strings.Split(subText, " ")
if len(seps) > 1 {
repositoryText := strings.TrimSpace(strings.Join(seps[1:], " "))
for _, f := range foundList {
if strings.HasPrefix(strings.ToLower(f.FullName), repositoryText) {
suggests = append(suggests, prompt.Suggest{Text: fmt.Sprintf("%s", f.FullName)})
}
}
break
}
}
}
return prompt.FilterHasPrefix(suggests, d.GetWordBeforeCursor(), true)
Expand Down Expand Up @@ -157,9 +184,11 @@ func executor(t string) {
foundList = result
foundMap = make(map[string]*search.Result)
for _, found := range foundList {
foundMap[found.FullName] = found
foundMap[strings.ToLower(found.FullName)] = found
}
showSearchedList()
default:
color.Red("Not Found Command.")
}
}

Expand Down

0 comments on commit 4b70bd4

Please sign in to comment.