Skip to content

Commit

Permalink
fix: if mid-word then provide all possible completions
Browse files Browse the repository at this point in the history
  • Loading branch information
johnrichardrinehart committed May 28, 2023
1 parent 5e10c13 commit e086922
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
1 change: 0 additions & 1 deletion complete.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ func (o *opCompleter) CompleteRefresh() {
if inSelect {
buf.WriteString("\033[30;47m")
}
buf.WriteString(string(same))
buf.WriteString(string(c))
buf.WriteString("\n")

Expand Down
21 changes: 18 additions & 3 deletions completers/complete_long_short.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,15 @@ func doLongShortInternal(p LongShortCompleter, line []rune, pos int, origLine []
newLine = append(newLine, []rune{' '})
}
} else {
newLine = append(newLine, []rune(fmt.Sprintf("%s\t%s", childName, string(child.Text))))
if long {
newLine = append(newLine, []rune(fmt.Sprintf("%s\t\t%s", childName, string(child.Text))))
} else {
if newLine == nil {
newLine = [][]rune{[]rune(childName)}
} else {
newLine[0] = []rune(fmt.Sprintf("%s\t%s", string(newLine[0]), childName))
}
}
}
offset = len(childName)
lineCompleter = child
Expand All @@ -95,8 +103,15 @@ func doLongShortInternal(p LongShortCompleter, line []rune, pos int, origLine []
// check if whole line matches a child
if runes.HasPrefix([]rune(childName), line) {
// the entire line already matches a child
// newLine = append(newLine, []rune(childName[len(line):]))
newLine = append(newLine, []rune(fmt.Sprintf("%s\t\t%s", childName[len(line):], string(child.Text))))
if long {
newLine = append(newLine, []rune(fmt.Sprintf("%s\t\t%s", childName[len(line):], string(child.Text))))
} else {
if newLine == nil {
newLine = [][]rune{[]rune(childName)}
} else {
newLine[0] = []rune(fmt.Sprintf("%s\t%s", string(newLine[0]), childName))
}
}

offset = len(line)
lineCompleter = child
Expand Down

7 comments on commit e086922

@wader
Copy link

@wader wader commented on e086922 Jun 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, i noticed your changes in the insights network thingy in github. Maybe this fork is interesting to you https://github.com/ergochat/readline

@johnrichardrinehart
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, i noticed your changes in the insights network thingy in github. Maybe this fork is interesting to you https://github.com/ergochat/readline

Thanks a lot, man! I was looking for a maintained fork! It looks like you've contributed to Ergochat's fork. Thanks for directing me, there!\

@wader
Copy link

@wader wader commented on e086922 Jun 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries! yeap we were a few ppl who used to cherry pick each other commits on separate forks but it started to become a nightmare to maintain so the ergochat maintainer took initiative to have a common fork. Please have a look and see if it makes semse to base on for you or send PR:s if you think something might be useful for others.

@johnrichardrinehart
Copy link
Owner Author

@johnrichardrinehart johnrichardrinehart commented on e086922 Jun 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wader @slingamn Would you be opposed to a new issue to be filed at https://github.com/chzyer/readline/issues indicating that https://github.com/ergochat/readline is intended to be a recommended and maintained fork in place of https://github.com/chzyer/readline ? I saw that you seemed to have done that at chzyer#226 but I thought that maybe a top-level Issue would be good, too. I want to get both of your approval before I post. Or, maybe one/both of you want to post/own instead?

Thanks!

@slingamn
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your interest in the project! Please consider submitting this patch to us :-)

I think creating such an issue is a good idea but I'd like to hold off for a few days, since I have something in the works that may help convince people that the fork is reliable.

@wader
Copy link

@wader wader commented on e086922 Jun 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 just keep the wording humble :) recommended and maintained sounds good

@johnrichardrinehart
Copy link
Owner Author

@johnrichardrinehart johnrichardrinehart commented on e086922 Jun 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your interest in the project! Please consider submitting this patch to us :-)

I think creating such an issue is a good idea but I'd like to hold off for a few days, since I have something in the works that may help convince people that the fork is reliable.

Sure no problem. I can circle back in a week to see what's good.

Please sign in to comment.