connection

package
v0.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 22, 2026 License: MIT Imports: 19 Imported by: 0

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

View Source
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
)
View Source
const (
	FocusRecent = iota
	FocusForm
)

Pane focus values: the profiles list pane or the form pane.

View Source
const (
	ActionTest    = "Test connection"
	ActionConnect = "Connect"
)

Action values of the Test/Connect buttons.

Variables

This section is empty.

Functions

func ActionRender

func ActionRender(style lipgloss.Style, label string) string

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

func RecentListItems(profiles []profile.Profile) []list.Item

RecentListItems converts profiles into list items for the profiles pane.

func Same

func Same(left, right profile.Profile) bool

Same reports whether two profiles describe the same connection. Plugin identity is part of the scope; legacy profiles without it compare by family.

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 (b *ActionButtons) RunAccessible(writer io.Writer, reader io.Reader) error

func (*ActionButtons) Skip

func (b *ActionButtons) Skip() bool

func (*ActionButtons) Update

func (b *ActionButtons) Update(message tea.Msg) (huh.Model, tea.Cmd)

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) WithTheme

func (b *ActionButtons) WithTheme(theme huh.Theme) huh.Field

func (*ActionButtons) WithWidth

func (b *ActionButtons) WithWidth(width int) huh.Field

func (*ActionButtons) Zoom

func (b *ActionButtons) Zoom() bool

type Driver

type Driver = profile.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 and the first registered plugin selected.

func (*Form) ApplySelectOption

func (f *Form) ApplySelectOption(field string, option int) tea.Cmd

func (*Form) BeginConfirmation

func (f *Form) BeginConfirmation()

BeginConfirmation opens the Connect confirmation for the current values.

func (*Form) Blur

func (f *Form) Blur()

Blur removes focus from the focused field.

func (Form) ConnectionName

func (f Form) ConnectionName() string

ConnectionName returns the display name of the current values.

func (Form) ConnectionTarget

func (f Form) ConnectionTarget() string

ConnectionTarget returns the full opener target for the current values: the selected plugin's form prefix remains intact for explicit routing.

func (Form) DriverName

func (f Form) DriverName() string

DriverName returns the display label of the selected plugin's family.

func (Form) FieldTitles

func (f Form) FieldTitles() []string

FieldTitles lists the rendered titles of every connection form field in render order; the layout follows the selected plugin's spec.

func (*Form) FocusField

func (f *Form) FocusField(field int) tea.Cmd

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) FocusForm

func (f *Form) FocusForm() tea.Cmd

FocusForm refocuses the focused field.

func (*Form) FocusValidationError

func (f *Form) FocusValidationError()

FocusValidationError moves the field cursor to the first invalid field.

func (Form) HostValue

func (f Form) HostValue() string

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

func (f Form) PortValue() string

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

func (f Form) Profile() profile.Profile

Profile builds the persisted profile for the current form values, without an identity (record assigns one).

func (*Form) Rebuild

func (f *Form) Rebuild() tea.Cmd

Rebuild rebuilds the huh form for the current plugin's spec layout.

func (Form) SelectOptionAt

func (f Form) SelectOptionAt(view string, viewLine int) (string, int)

SelectOptionAt maps a click on the rendered form view to an option row of the Plugin 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) SelectPlugin added in v0.11.0

func (f *Form) SelectPlugin(pluginID string) tea.Cmd

SelectPlugin applies a plugin change and rebuilds the form for its family.

func (*Form) SetFocus

func (f *Form) SetFocus(index int) tea.Cmd

SetFocus switches the pane focus; leaving the form blurs its field.

func (*Form) SetHeight

func (f *Form) SetHeight(height int)

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

func (f *Form) SetWidth(width int)

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

func (f *Form) ShowValidationError() tea.Cmd

ShowValidationError rebuilds the form and focuses the invalid field.

func (Form) TargetValue

func (f Form) TargetValue() string

TargetValue builds the selected plugin's opener target body from the form values, resolving secret references.

func (*Form) UpdateHuh

func (f *Form) UpdateHuh(message tea.Msg) (tea.Cmd, Event)

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).

func (Form) Validate

func (f Form) Validate() error

Validate checks the selected plugin's advertised field rules.

func (Form) View

func (f Form) View() string

View renders the form, or empty while unbuilt.

type FormValues

type FormValues struct {
	ID            string
	Plugin        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 connection fields. Plugin is the selected plugin instance; Driver remains its non-unique database family.

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 New

func New() Model

New builds the connection component with an empty recent list.

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

func (m Model) ConnectionTarget() string

ConnectionTarget returns the full opener target for the form's current values: server drivers gain their URL scheme prefix.

func (*Model) Delete

func (m *Model) Delete(connection profile.Profile)

Delete removes the given profile from the recent list.

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

func (m *Model) FocusFilter() tea.Cmd

FocusFilter enters the filter input.

func (Model) FormPaneView

func (m Model) FormPaneView(height int, modeBadge string) string

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

func (m *Model) LoadValues(connection profile.Profile)

LoadValues copies a saved profile into the connection form's values, normalizing empty TLS modes to the disabled defaults.

func (Model) RecentPaneView

func (m Model) RecentPaneView(filterRow string, width int) string

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

func (m *Model) Record(openedTarget string, readOnly bool) (profile.Profile, error)

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.

func (Model) Save

func (m Model) Save() error

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) Selected

func (m Model) Selected() (profile.Profile, bool)

Selected returns the profile under the recent list cursor, if any.

func (*Model) SetProfiles

func (m *Model) SetProfiles(profiles []profile.Profile)

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 MySQLTLS

type MySQLTLS = profile.MySQLTLS

type OpenRequested

type OpenRequested struct {
	Plugin    string
	Target    string
	Profile   profile.Profile
	Reconnect bool
}

OpenRequested asks the root to open the given target with the selected plugin and current form profile. Reconnect is reserved for sidebar switches.

type PostgreSQLTLS

type PostgreSQLTLS = profile.PostgreSQLTLS

type ProfilesChanged

type ProfilesChanged struct{ Profiles []profile.Profile }

ProfilesChanged reports that the component's profile list changed; the root re-reads it through the component API.

type RecentProfile

type RecentProfile struct {
	profile.Profile
}

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 {
	Plugin string
	Target string
}

TestRequested asks the root to test-connect the given target through plugin.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL