Skip to content

Conversation

@jabr
Copy link
Contributor

@jabr jabr commented Nov 5, 2025

Implements #125 as uc ctx connection

@jabr jabr force-pushed the choose-default-connection branch from acaa6c2 to f427cab Compare November 6, 2025 04:48
Copy link
Owner

@psviderski psviderski left a comment

Choose a reason for hiding this comment

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

Nice one! 👍

Please see the comment about simplifying the selection logic and removing unnecessary code for comparing connections.

BTW, did you consider implementing this as part of uc ctx as described in #125?
Any reason you decided to make it a separate command?

var selectedConnection *config.MachineConnection
form := huh.NewForm(
huh.NewGroup(
huh.NewSelect[*config.MachineConnection]().
Copy link
Owner

Choose a reason for hiding this comment

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

I think this could be significantly simplified by using an int type (index) instead of MachineConnection for the selected item. In this case, we don't need to compare connections and maintain the Equal method.

You may also want to move the reordering logic to a method of the Context struct, something like currentCtx.SetDefaultConnection(index). It's up to you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, yeah, good idea! The non-comparable MachineConnection due to the key's byte slice sent both Gemini and I down a rabbit hole on that one... 😭

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

@jabr
Copy link
Contributor Author

jabr commented Nov 6, 2025

BTW, did you consider implementing this as part of uc ctx as described in #125?
Any reason you decided to make it a separate command?

I think I just misunderstood what you meant by "extend the uc ctx command" then. I figured you meant something like what I did here uc ctx connection.

So are you thinking uc ctx would have ui for selecting both the context and then the connection? Or a flag/option to select default connection rather than default context? Or do you mean extending/reusing the ui code from ctx in a separate command?

@jabr jabr force-pushed the choose-default-connection branch 2 times, most recently from a890a45 to 9b3389a Compare November 9, 2025 03:47
@jabr
Copy link
Contributor Author

jabr commented Nov 9, 2025

I somehow missed the last bit from your comment #125 about extending uc ctx originally:

Then, before pressing enter, you can press 'c', and a nested selector appears that allows you to select the default connection for that context

I just looked into doing that, and while I see we could have a second group/page with the connections selection after context, I don't see anything in huh to add a "custom command" like the "c" option to trigger going into that "nested" selector.

Did you have any idea in mind on how you would implement that UI?

Another option would be to make uc ctx always a two step progress (first context, then connection). With the current default already selected, I don't think the extra enter would be a terrible ux for the default case.

@jabr jabr force-pushed the choose-default-connection branch from 9b3389a to 8b47829 Compare November 10, 2025 04:08
@psviderski
Copy link
Owner

Did you have any idea in mind on how you would implement that UI?

Not really, I just fantasised the UX I'd likely want to have but unsure what's the best way to implement it. Looks like it will require wrapping the form in a Bubble Tea program and calling its View/Update methods instead of Run.

Another option would be to make uc ctx always a two step progress (first context, then connection).

It's not a terrible UX but I switch clusters often and in my 99.9% use cases I don't care about the connection so that will annoy me personally.

I like having a separate command for selecting only the connection that this PR introduces, so let's have it regardless of trying to make the uc ctx even fancier.

Copy link
Owner

@psviderski psviderski left a comment

Choose a reason for hiding this comment

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

Looks very good! 👍

@psviderski psviderski merged commit 1d41373 into psviderski:main Nov 19, 2025
3 of 4 checks passed
@jabr jabr deleted the choose-default-connection branch November 27, 2025 07:03
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.

2 participants