Documentation
¶
Overview ¶
Package connection owns the connection-screen feature: the profile form (values, validation, TLS modes, DSN building), the action buttons, the recent-profiles list and filter, profile add/edit/delete operations, and the pane rendering. The root shell supplies the persistence path, screen geometry, keybindings, and modal form-mode routing; the component owns every connection-screen interaction that does not need a root overlay and requests database actions through typed events.
Index ¶
- Constants
- func ActionRender(style lipgloss.Style, label string) string
- func ActionWidth() int
- func RecentListItems(profiles []profile.Profile) []list.Item
- func Same(left, right profile.Profile) bool
- type ActionButtons
- func (b *ActionButtons) Blur() tea.Cmd
- func (b *ActionButtons) Error() error
- func (b *ActionButtons) Focus() tea.Cmd
- func (b *ActionButtons) GetKey() string
- func (b *ActionButtons) GetValue() any
- func (b *ActionButtons) Init() tea.Cmd
- func (b *ActionButtons) KeyBinds() []key.Binding
- func (b *ActionButtons) Run() error
- func (b *ActionButtons) RunAccessible(writer io.Writer, reader io.Reader) error
- func (b *ActionButtons) Skip() bool
- func (b *ActionButtons) Update(message tea.Msg) (huh.Model, tea.Cmd)
- func (b *ActionButtons) View() string
- func (b *ActionButtons) WithHeight(height int) huh.Field
- func (b *ActionButtons) WithKeyMap(keyMap *huh.KeyMap) huh.Field
- func (b *ActionButtons) WithPosition(position huh.FieldPosition) huh.Field
- func (b *ActionButtons) WithTheme(theme huh.Theme) huh.Field
- func (b *ActionButtons) WithWidth(width int) huh.Field
- func (b *ActionButtons) Zoom() bool
- type Driver
- type Event
- type Form
- func (f *Form) ApplySelectOption(field string, option int) tea.Cmd
- func (f *Form) BeginConfirmation()
- func (f *Form) Blur()
- func (f Form) ConnectionName() string
- func (f Form) ConnectionTarget() string
- func (f Form) DriverName() string
- func (f Form) FieldTitles() []string
- func (f *Form) FocusField(field int) tea.Cmd
- func (f *Form) FocusForm() tea.Cmd
- func (f *Form) FocusValidationError()
- func (f Form) HostValue() string
- func (f Form) PortValue() string
- func (f Form) Profile() profile.Profile
- func (f *Form) Rebuild() tea.Cmd
- func (f *Form) SelectDriver(driver Driver) tea.Cmd
- func (f Form) SelectOptionAt(view string, viewLine int) (string, int)
- func (f *Form) SetFocus(index int) tea.Cmd
- func (f *Form) SetHeight(height int)
- func (f *Form) SetWidth(width int)
- func (f *Form) ShowValidationError() tea.Cmd
- func (f Form) TargetValue() string
- func (f *Form) UpdateHuh(message tea.Msg) (tea.Cmd, Event)
- func (f Form) Validate() error
- func (f Form) View() string
- type FormValues
- type Model
- func (m *Model) ApplyFilter()
- func (m *Model) BlurFilter()
- func (m Model) ConnectionTarget() string
- func (m *Model) Delete(connection profile.Profile)
- func (m Model) Draw(canvas uv.ScreenBuffer, layout uikit.Layout)
- func (m *Model) FocusFilter() tea.Cmd
- func (m Model) FormPaneView(height int, modeBadge string) string
- func (m *Model) LoadValues(connection profile.Profile)
- func (m Model) RecentPaneView(filterRow string, width int) string
- func (m *Model) Record(openedTarget string, readOnly bool) (profile.Profile, error)
- func (m Model) Save() error
- func (m Model) Selected() (profile.Profile, bool)
- func (m *Model) SetProfiles(profiles []profile.Profile)
- func (m *Model) SyncFilter()
- func (m Model) Update(msg tea.Msg, layout uikit.Layout, keys uikit.KeyMatcher) (Model, Event, tea.Cmd)
- type MySQLTLS
- type OpenRequested
- type PostgreSQLTLS
- type ProfilesChanged
- type RecentProfile
- type StatusChanged
- type TestRequested
- type ValidationMsg
Constants ¶
const ( DriverSQLite = profile.DriverSQLite DriverMySQL = profile.DriverMySQL DriverPostgreSQL = profile.DriverPostgreSQL MySQLTLSVerify = profile.MySQLTLSVerify MySQLTLSSkipVerify = profile.MySQLTLSSkipVerify MySQLTLSDisabled = profile.MySQLTLSDisabled PostgreSQLTLSVerifyFull = profile.PostgreSQLTLSVerifyFull PostgreSQLTLSEncrypt = profile.PostgreSQLTLSEncrypt PostgreSQLTLSDisabled = profile.PostgreSQLTLSDisabled )
const ( FocusRecent = iota FocusForm )
Pane focus values: the profiles list pane or the form pane.
const ( ActionTest = "Test connection" ActionConnect = "Connect" )
Action values of the Test/Connect buttons.
Variables ¶
This section is empty.
Functions ¶
func ActionRender ¶
ActionRender renders an action button at the common width with its label centered.
func ActionWidth ¶
func ActionWidth() int
ActionWidth returns the common rendered width of the Test connection and Connect buttons; the shorter label is centered into it.
func RecentListItems ¶
RecentListItems converts profiles into list items for the profiles pane.
Types ¶
type ActionButtons ¶
type ActionButtons struct {
// contains filtered or unexported fields
}
ActionButtons is the Test/Connect huh field at the bottom of the connection form.
func NewActionButtons ¶
func NewActionButtons(value *string) *ActionButtons
NewActionButtons builds the inline Test/Connect selector bound to value.
func (*ActionButtons) Blur ¶
func (b *ActionButtons) Blur() tea.Cmd
func (*ActionButtons) Error ¶
func (b *ActionButtons) Error() error
func (*ActionButtons) Focus ¶
func (b *ActionButtons) Focus() tea.Cmd
func (*ActionButtons) GetKey ¶
func (b *ActionButtons) GetKey() string
func (*ActionButtons) GetValue ¶
func (b *ActionButtons) GetValue() any
func (*ActionButtons) Init ¶
func (b *ActionButtons) Init() tea.Cmd
func (*ActionButtons) KeyBinds ¶
func (b *ActionButtons) KeyBinds() []key.Binding
func (*ActionButtons) Run ¶
func (b *ActionButtons) Run() error
func (*ActionButtons) RunAccessible ¶
func (*ActionButtons) Skip ¶
func (b *ActionButtons) Skip() bool
func (*ActionButtons) View ¶
func (b *ActionButtons) View() string
func (*ActionButtons) WithHeight ¶
func (b *ActionButtons) WithHeight(height int) huh.Field
func (*ActionButtons) WithKeyMap ¶
func (b *ActionButtons) WithKeyMap(keyMap *huh.KeyMap) huh.Field
func (*ActionButtons) WithPosition ¶
func (b *ActionButtons) WithPosition(position huh.FieldPosition) huh.Field
func (*ActionButtons) Zoom ¶
func (b *ActionButtons) Zoom() bool
type Driver ¶
Driver and TLS mode types are the persisted profile types; the form aliases them so form values and profiles share one representation.
type Event ¶
type Event interface {
// contains filtered or unexported methods
}
Event is a typed request from the connection component to the root shell. The root performs database opening/testing and profile persistence side effects; the component only edits profiles and requests actions.
type Form ¶
type Form struct {
Huh *huh.Form
Confirmation *uikit.ConfirmationDialog
Values *FormValues
Focus, Width int
// Height is the pane body height the form viewport is clipped to; huh
// scrolls its group viewport to the focused field (see SetHeight).
Height int
// contains filtered or unexported fields
}
Form is the connection profile form: the huh form, its bound values, the optional confirmation dialog, and the pane geometry.
func NewForm ¶
func NewForm() Form
NewForm builds a fresh connection form with the disabled TLS defaults.
func (*Form) ApplySelectOption ¶
ApplySelectOption sets the clicked select's value and rebuilds the form so the selection highlight follows (huh renders the cursor from its own state). A TLS click restores focus to the TLS field; the driver rebuild resets focus to the first field, matching the keyboard path.
func (*Form) BeginConfirmation ¶
func (f *Form) BeginConfirmation()
BeginConfirmation opens the Connect confirmation for the current values.
func (Form) ConnectionName ¶
ConnectionName returns the display name of the current values.
func (Form) ConnectionTarget ¶
ConnectionTarget returns the full opener target for the current values: server drivers gain their URL scheme prefix.
func (Form) DriverName ¶
DriverName returns the display label of the selected driver.
func (Form) FieldTitles ¶
FieldTitles lists the rendered titles of every connection form field in render order; the layout follows the selected driver's spec.
func (*Form) FocusField ¶
focusField moves the field cursor to the field at index. The Privacy note is skipped by Huh navigation, so clicks on it leave focus unchanged. The loop bounds guard against navigation skipping fields.
func (*Form) FocusValidationError ¶
func (f *Form) FocusValidationError()
FocusValidationError moves the field cursor to the first invalid field.
func (Form) HostValue ¶
HostValue returns the effective connection host: an empty Host field falls back to localhost so the user can leave the field untouched.
func (Form) PortValue ¶
PortValue returns the effective connection port: an empty Port field falls back to the driver default so the user can leave the field untouched.
func (Form) Profile ¶
Profile builds the persisted profile for the current form values, without an identity (record assigns one).
func (*Form) SelectDriver ¶
SelectDriver applies a driver change: a port holding another driver's well-known default follows the new driver's default, then the form rebuilds for the new driver's layout.
func (Form) SelectOptionAt ¶
SelectOptionAt maps a click on the rendered form view to an option row of the Driver or TLS select. It returns the field key and option index, or ("", -1) when the click misses every option row. Huh's select fields do not handle mouse clicks, so the app picks the option itself: option rows render below the select's title line, long option keys are word-wrapped across several lines, and the scan stops at the nearest field title so a value line that happens to read like an option (a database named "MySQL") is not mistaken for a select row.
func (*Form) SetHeight ¶
SetHeight clips the form viewport to the pane body height. Huh's group viewport scrolls to the focused field on every navigation, so fields that overflow the pane (TLS options, Read-Only, the action buttons) stay reachable and visible instead of being clipped away.
func (*Form) SetWidth ¶
SetWidth clamps the form width. Huh's text input panics when its internal width goes negative, which happens below roughly frame(2) + prompt(2) + 1 cells. Keep the form renderable even during degenerate 0x0 layouts.
func (*Form) ShowValidationError ¶
ShowValidationError rebuilds the form and focuses the invalid field.
func (Form) TargetValue ¶
TargetValue builds the driver-specific opener target from the form values, resolving secret references. The driver's registered target builder serializes the values; unknown drivers fall back to the raw target field.
func (*Form) UpdateHuh ¶
UpdateHuh routes one message through the form while it is the insert target. It returns the form command and, when the form completes, the action request for the root to perform (test or open).
type FormValues ¶
type FormValues struct {
ID string
Driver Driver
Name, Target string
Host, Port string
User, Pass string
MySQLTLS MySQLTLS
PostgreSQLTLS PostgreSQLTLS
ReadOnly bool
Action string
Extras map[string]string
Undecryptable map[string]string
}
FormValues holds the editable form fields. ID is the opaque profile scope: never displayed or user-edited. Extras carries driver-specific fields beyond the fixed set, persisted in the profile. Undecryptable mirrors profile.Profile.Undecryptable through an edit round-trip: a field still holding its retained undecryptable blob is refused by Save until the user re-enters it.
type Model ¶
type Model struct {
Form Form
Recent list.Model
RecentFilter textinput.Model
Profiles []profile.Profile
Path string
}
Model is the connection-screen feature component: the profile form with its values, the recent profiles list and filter, the persisted profile list and path, and the pane geometry. Root keeps the file picker, modal confirmations, context menus, and database opening.
func (*Model) ApplyFilter ¶
func (m *Model) ApplyFilter()
ApplyFilter pushes the visible filter input's value into the profiles list, which filters its items and reports the committed state the status bar mirrors.
func (*Model) BlurFilter ¶
func (m *Model) BlurFilter()
BlurFilter exits the filter input, keeping the applied filter.
func (Model) ConnectionTarget ¶
ConnectionTarget returns the full opener target for the form's current values: server drivers gain their URL scheme prefix.
func (Model) Draw ¶
func (m Model) Draw(canvas uv.ScreenBuffer, layout uikit.Layout)
Draw renders nothing: the connection screen has no canvas overlays. The contract mirrors the other feature components; root calls it at its overlay draw slots.
func (*Model) FocusFilter ¶
FocusFilter enters the filter input.
func (Model) FormPaneView ¶
FormPaneView renders the form pane body: the form view plus the mode badge footer supplied by root (vim mode and modal form mode are root concerns).
func (*Model) LoadValues ¶
LoadValues copies a saved profile into the connection form's values, normalizing empty TLS modes to the disabled defaults.
func (Model) RecentPaneView ¶
RecentPaneView renders the profiles list with its pane-local action hints; the layout reserves rows for the filter box (3) and the hint line (1). filterRow is the rendered filter box (root supplies it from the shared layout), width the pane content width.
func (*Model) Record ¶
Record saves the form's current credentials as a recent profile. openedTarget is the target that was actually opened (Connect after updateOpen, or the target a successful Test just verified); for SQLite it wins over the form value, so Connect records the resolved file while Test records the form target and never picks up a previously connected root target. readOnly is the root's current read-only default.
func (Model) Save ¶
Save persists the current profile list, best-effort like the original callers; it returns the persistence error so callers that must know (Record) can surface it.
func (*Model) SetProfiles ¶
SetProfiles replaces the persisted profile list and refreshes the list items; it never writes through (the root owns the save boundary).
func (*Model) SyncFilter ¶
func (m *Model) SyncFilter()
SyncFilter clears the visible input when the list's own keymap dropped the filter (esc in list navigation).
func (Model) Update ¶
func (m Model) Update(msg tea.Msg, layout uikit.Layout, keys uikit.KeyMatcher) (Model, Event, tea.Cmd)
Update handles the recent-profiles pane messages: filter editing (every message goes to the input so clipboard paste works; enter/escape exit editing, keeping the applied filter) and the list passthrough. The pane's action keys (add/edit/delete/menu/switch) stay in the root dispatcher because they open root-owned overlays or the form-mode controller; the component emits events for the database flows.
type OpenRequested ¶
OpenRequested asks the root to open the given target with the current form profile. Reconnect is reserved for sidebar database switches.
type PostgreSQLTLS ¶
type PostgreSQLTLS = profile.PostgreSQLTLS
type ProfilesChanged ¶
ProfilesChanged reports that the component's profile list changed; the root re-reads it through the component API.
type RecentProfile ¶
RecentProfile adapts a persisted connection profile to the profiles list. Driver display labels and profile descriptions are presentation concerns, so they live with the connection feature rather than in the profile persistence package.
func (RecentProfile) Description ¶
func (c RecentProfile) Description() string
func (RecentProfile) FilterValue ¶
func (c RecentProfile) FilterValue() string
func (RecentProfile) Title ¶
func (c RecentProfile) Title() string
type StatusChanged ¶
type StatusChanged = uikit.StatusChanged
StatusChanged is the shared status-line event (uikit.StatusChanged).
type TestRequested ¶
type TestRequested struct{ Target string }
TestRequested asks the root to test-connect the given target.
type ValidationMsg ¶
type ValidationMsg struct{}
ValidationMsg asks the root to re-render the form focused on its first invalid field after a failed validation attempt.