Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: completion for interactive mode #2729

Merged
merged 1 commit into from
Sep 19, 2024
Merged

Conversation

stuartwdouglas
Copy link
Collaborator

fixes: #2708

@stuartwdouglas stuartwdouglas requested review from a team and jonathanj-square and removed request for a team September 19, 2024 06:58
This was referenced Sep 19, 2024
Copy link
Collaborator

@alecthomas alecthomas left a comment

Choose a reason for hiding this comment

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

So cool!

type interactiveCmd struct {
}

func (i *interactiveCmd) Run(ctx context.Context, k *kong.Kong, projectConfig projectconfig.Config) error {
type FTLCompletion struct {
Copy link
Collaborator

@alecthomas alecthomas Sep 19, 2024

Choose a reason for hiding this comment

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

I know I said to put all the types at the top, but I'm going to slightly contradict myself 😂

It's preferable to have type followed immediately by methods. So in this case I'd put FTLCompletion + methods at the top, then interactiveCmd + methods below that, so it still works to read down the file and have seen everything.

Not a big deal though, but just for your reference.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That is where I was going to put it, but I remembered your comment from yesterday :-) I will move it.

lastCompleted := ""
lastSpace := false
// We don't care about anything past pos
// this completer can't handle completing in the middle of things
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah I've noticed that before, it sucks a bit :( - still, better than no completion

@@ -62,3 +74,72 @@ func (i *interactiveCmd) Run(ctx context.Context, k *kong.Kong, projectConfig pr
func errorf(format string, args ...any) {
fmt.Printf("\033[31m%s\033[0m\n", fmt.Sprintf(format, args...))
}

func (f *FTLCompletion) Do(line []rune, pos int) ([][]rune, int) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Awesome!

@stuartwdouglas stuartwdouglas merged commit 2b0d47a into main Sep 19, 2024
91 checks passed
@stuartwdouglas stuartwdouglas deleted the stuartwdouglas/2708 branch September 19, 2024 09:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add an interactive mode to the CLI
2 participants