mirror of
https://github.com/Rudi9719/kbtui.git
synced 2026-03-22 12:07:23 +00:00
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
This commit is contained in:
57
main.go
57
main.go
@ -241,29 +241,47 @@ 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
|
|
||||||
if testVar, err := k.ChatList(); err != nil {
|
|
||||||
log.Printf("%+v", err)
|
|
||||||
} else {
|
|
||||||
// create a slice to hold the values
|
// create a slice to hold the values
|
||||||
var firstSlice []string
|
var firstSlice []string
|
||||||
// iterate over all the conversation results
|
// iterate over all the conversation results
|
||||||
for _, s := range testVar.Result.Conversations {
|
for _, s := range channels {
|
||||||
if s.Channel.MembersType == keybase.TEAM {
|
if s.MembersType == keybase.TEAM {
|
||||||
// its a team so add the topic name as a possible tab completion
|
// its a team so add the topic name as a possible tab completion
|
||||||
firstSlice = append(firstSlice, s.Channel.TopicName)
|
firstSlice = append(firstSlice, s.TopicName)
|
||||||
} else {
|
} else {
|
||||||
// its a user, so clean the name and append the users name as a possible tab completion
|
// its a user, so clean the name and append the users name as a possible tab completion
|
||||||
firstSlice = append(firstSlice, cleanChannelName(s.Channel.Name))
|
firstSlice = append(firstSlice, cleanChannelName(s.Name))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// now return the resultSlice which contains all that are prefixed with inputWord
|
// now return the resultSlice which contains all that are prefixed with inputWord
|
||||||
resultSlice := filterStringSlice(firstSlice, inputWord)
|
resultSlice := filterStringSlice(firstSlice, inputWord)
|
||||||
return resultSlice
|
return resultSlice
|
||||||
}
|
}
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func handleTab() error {
|
func handleTab() error {
|
||||||
inputString, err := getInputString("Input")
|
inputString, err := getInputString("Input")
|
||||||
@ -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)
|
||||||
|
|||||||
Reference in New Issue
Block a user