Browse Source

updated to use cached conversation list

working autocomplete on input line
still only a partial list of team/channel pairs, need to see what i'm missing
pull/2/head
David Haukeness 5 years ago
parent
commit
316fbfa9aa
No known key found for this signature in database
GPG Key ID: A7F1091956853EF9
  1. 75
      main.go

75
main.go

@ -241,28 +241,46 @@ func longestCommonPrefix(ss []string) string {
return min return min
} }
func stringRemainder(aStr, bStr string) string {
var long, short string
//figure out which string is longer
switch {
case len(aStr) < len (bStr):
short = aStr
long = bStr
default:
short = bStr
long = aStr
}
// iterate over the strings using an external iterator so we don't lose the value
i := 0
for i < len(short) && i < len(long) {
if short[i] != long[i] {
// the strings aren't equal so don't return anything
return ""
}
i++
}
// return whatever's left of the longer string
return long[i:]
}
func generateTabCompletionSlice(inputWord string) []string { func generateTabCompletionSlice(inputWord string) []string {
// gets all possible tab completion cantidates // create a slice to hold the values
if testVar, err := k.ChatList(); err != nil { var firstSlice []string
log.Printf("%+v", err) // iterate over all the conversation results
} else { for _, s := range channels {
// create a slice to hold the values if s.MembersType == keybase.TEAM {
var firstSlice []string // its a team so add the topic name as a possible tab completion
// iterate over all the conversation results firstSlice = append(firstSlice, s.TopicName)
for _, s := range testVar.Result.Conversations { } else {
if s.Channel.MembersType == keybase.TEAM { // its a user, so clean the name and append the users name as a possible tab completion
// its a team so add the topic name as a possible tab completion firstSlice = append(firstSlice, cleanChannelName(s.Name))
firstSlice = append(firstSlice, s.Channel.TopicName)
} else {
// its a user, so clean the name and append the users name as a possible tab completion
firstSlice = append(firstSlice, cleanChannelName(s.Channel.Name))
}
} }
// now return the resultSlice which contains all that are prefixed with inputWord
resultSlice := filterStringSlice(firstSlice, inputWord)
return resultSlice
} }
return nil // now return the resultSlice which contains all that are prefixed with inputWord
resultSlice := filterStringSlice(firstSlice, inputWord)
return resultSlice
} }
func handleTab() error { func handleTab() error {
@ -275,8 +293,9 @@ func handleTab() error {
s := ss[len(ss)-1] s := ss[len(ss)-1]
// now call get the list of all possible cantidates that have that as a prefix // now call get the list of all possible cantidates that have that as a prefix
resultSlice := generateTabCompletionSlice(s) resultSlice := generateTabCompletionSlice(s)
result := longestCommonPrefix(resultSlice) lcp := longestCommonPrefix(resultSlice)
printToView("Feed", fmt.Sprintf("TabCompletion: %s", result)) remainder := stringRemainder(s, lcp)
writeToView("Input", remainder)
} }
return nil return nil
} }
@ -296,6 +315,20 @@ func clearView(viewName string) {
} }
func writeToView(viewName string, message string) {
g.Update(func(g *gocui.Gui) error {
updatingView, err := g.View(viewName)
if err != nil {
return err
} else {
for _, c := range message {
updatingView.EditWrite(c)
}
}
return nil
})
}
func printToView(viewName string, message string) { func printToView(viewName string, message string) {
g.Update(func(g *gocui.Gui) error { g.Update(func(g *gocui.Gui) error {
updatingView, err := g.View(viewName) updatingView, err := g.View(viewName)

Loading…
Cancel
Save