Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ module github.com/rebelice/lazypg
go 1.24.0

require (
github.com/99designs/keyring v1.2.2
github.com/alecthomas/chroma/v2 v2.20.0
github.com/atotto/clipboard v0.1.4
github.com/charmbracelet/bubbles v0.21.0
github.com/charmbracelet/bubbletea v1.3.10
Expand All @@ -14,29 +16,30 @@ require (
github.com/mattn/go-runewidth v0.0.16
github.com/mattn/go-sqlite3 v1.14.32
github.com/spf13/viper v1.21.0
github.com/zalando/go-keyring v0.2.6
gopkg.in/yaml.v3 v3.0.1
)

require (
al.essio.dev/pkg/shellescape v1.5.1 // indirect
github.com/alecthomas/chroma/v2 v2.20.0 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/charmbracelet/colorprofile v0.3.1 // indirect
github.com/charmbracelet/x/cellbuf v0.0.13 // indirect
github.com/charmbracelet/x/term v0.2.1 // indirect
github.com/danieljoos/wincred v1.2.2 // indirect
github.com/dlclark/regexp2 v1.11.5 // indirect
github.com/dvsekhvalnov/jose2go v1.5.0 // indirect
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
github.com/fsnotify/fsnotify v1.9.0 // indirect
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/jackc/puddle/v2 v2.2.2 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mtibben/percent v0.2.1 // indirect
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/termenv v0.16.0 // indirect
Expand All @@ -53,5 +56,6 @@ require (
golang.org/x/crypto v0.31.0 // indirect
golang.org/x/sync v0.16.0 // indirect
golang.org/x/sys v0.36.0 // indirect
golang.org/x/term v0.27.0 // indirect
golang.org/x/text v0.28.0 // indirect
)
32 changes: 24 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
al.essio.dev/pkg/shellescape v1.5.1 h1:86HrALUujYS/h+GtqoB26SBEdkWfmMI6FubjXlsXyho=
al.essio.dev/pkg/shellescape v1.5.1/go.mod h1:6sIqp7X2P6mThCQ7twERpZTuigpr6KbZWtls1U8I890=
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMbk2FiG/kXiLl8BRyzTWDw7gX/Hz7Dd5eDMs=
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4/go.mod h1:hN7oaIRCjzsZ2dE+yG5k+rsdt3qcwykqK6HVGcKwsw4=
github.com/99designs/keyring v1.2.2 h1:pZd3neh/EmUzWONb35LxQfvuY7kiSXAq3HQd97+XBn0=
github.com/99designs/keyring v1.2.2/go.mod h1:wes/FrByc8j7lFOAGLGSNEg8f/PaI3cgTBqhFkHUrPk=
github.com/alecthomas/assert/v2 v2.11.0 h1:2Q9r3ki8+JYXvGsDyBXwH3LcJ+WK5D0gc5E8vS6K3D0=
github.com/alecthomas/assert/v2 v2.11.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k=
github.com/alecthomas/chroma/v2 v2.20.0 h1:sfIHpxPyR07/Oylvmcai3X/exDlE8+FA820NTz+9sGw=
github.com/alecthomas/chroma/v2 v2.20.0/go.mod h1:e7tViK0xh/Nf4BYHl00ycY6rV7b8iXBksI9E359yNmA=
github.com/alecthomas/repr v0.5.1 h1:E3G4t2QbHTSNpPKBgMTln5KLkZHLOcU7r37J4pXBuIg=
github.com/alecthomas/repr v0.5.1/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4=
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
Expand All @@ -27,6 +33,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dlclark/regexp2 v1.11.5 h1:Q/sSnsKerHeCkc/jSTNq1oCm7KiVgUMZRDUoRu0JQZQ=
github.com/dlclark/regexp2 v1.11.5/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
github.com/dvsekhvalnov/jose2go v1.5.0 h1:3j8ya4Z4kMCwT5nXIKFSV84YS+HdqSSO0VsTQxaLAeM=
github.com/dvsekhvalnov/jose2go v1.5.0/go.mod h1:QsHjhyTlD/lAVqn/NSbVZmSCGeDehTB/mPZadG+mhXU=
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4=
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM=
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
Expand All @@ -35,14 +43,16 @@ github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S
github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
github.com/go-viper/mapstructure/v2 v2.4.0 h1:EBsztssimR/CONLSZZ04E8qAkxNYq4Qp9LvH92wZUgs=
github.com/go-viper/mapstructure/v2 v2.4.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=
github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 h1:ZpnhV/YsD2/4cESfV5+Hoeu/iUR3ruzNvZ+yQfO03a0=
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2/go.mod h1:bBOAhwG1umN6/6ZUMtDFBMQR8jRg9O75tm9K00oMsK4=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c h1:6rhixN/i8ZofjG1Y75iExal34USq5p+wiN1tpie8IrU=
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c/go.mod h1:NMPJylDgVpX0MLRlPy15sqSwOFv/U1GZ2m21JhFfek0=
github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg=
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
Expand All @@ -53,6 +63,8 @@ github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/lrstanley/bubblezone v1.0.0 h1:bIpUaBilD42rAQwlg/4u5aTqVAt6DSRKYZuSdmkr8UA=
Expand All @@ -67,12 +79,15 @@ github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6T
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mattn/go-sqlite3 v1.14.32 h1:JD12Ag3oLy1zQA+BNn74xRgaBbdhbNIDYvQUEuuErjs=
github.com/mattn/go-sqlite3 v1.14.32/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
github.com/mtibben/percent v0.2.1 h1:5gssi8Nqo8QU/r2pynCm+hBQHpkB/uNK7BJCFogWdzs=
github.com/mtibben/percent v0.2.1/go.mod h1:KG9uO+SZkUp+VkRHsCdYQV3XSZrrSpR3O9ibNBTZrns=
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI=
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6/go.mod h1:CJlz5H+gyd6CUWT45Oy4q24RdLyn7Md9Vj2/ldJBSIo=
github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA=
github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=
github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc=
github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4=
github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down Expand Up @@ -105,8 +120,6 @@ github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
github.com/zalando/go-keyring v0.2.6 h1:r7Yc3+H+Ux0+M72zacZoItR3UDxeWfKTcabvkI8ua9s=
github.com/zalando/go-keyring v0.2.6/go.mod h1:2TCrxYrbUNYfNS/Kgy/LSrkSQzZ5UPVH85RwfczwvcI=
go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U=
Expand All @@ -119,9 +132,12 @@ golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.36.0 h1:KVRy2GtZBrk1cBYA7MKu5bEZFxQk4NIDV6RLVcC8o0k=
golang.org/x/sys v0.36.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/term v0.27.0 h1:WP60Sv1nlK1T6SupCHbXzSaN0b9wUmsPoRS9b61A23Q=
golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM=
golang.org/x/text v0.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng=
golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down
117 changes: 112 additions & 5 deletions internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ type App struct {
// Connection history
connectionHistory *connection_history.Manager

// Password dialog for missing passwords
showPasswordDialog bool
passwordDialog *components.PasswordDialog
pendingConnectionInfo *models.ConnectionHistoryEntry

// Search input
showSearch bool
searchInput *components.SearchInput
Expand Down Expand Up @@ -330,6 +335,7 @@ func New(cfg *config.Config) *App {
favoritesManager: favoritesManager,
favoritesDialog: favoritesDialog,
connectionHistory: connectionHistory,
passwordDialog: components.NewPasswordDialog(th),
showSearch: false,
searchInput: searchInput,
executeSpinner: s,
Expand Down Expand Up @@ -588,6 +594,34 @@ func (a *App) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
a.showError = false
return a, nil

case components.PasswordSubmitMsg:
// User submitted password from password dialog
a.showPasswordDialog = false
if a.pendingConnectionInfo != nil {
// Create connection config with the entered password
config := a.pendingConnectionInfo.ToConnectionConfig()
config.Password = msg.Password

// Try to save the password for future use
if a.connectionHistory != nil {
if err := a.connectionHistory.SavePassword(config.Host, config.Port, config.Database, config.User, config.Password); err != nil {
log.Printf("Warning: Failed to save password: %v", err)
}
}

a.pendingConnectionInfo = nil
return a.performConnection(config)
}
return a, nil

case components.PasswordCancelMsg:
// User cancelled password dialog
a.showPasswordDialog = false
a.pendingConnectionInfo = nil
// Re-show connection dialog
a.showConnectionDialog = true
return a, nil

case components.CloseCommandPaletteMsg:
a.showCommandPalette = false
return a, nil
Expand Down Expand Up @@ -785,6 +819,13 @@ func (a *App) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return a.handleConnectionDialog(msg)
}

// Handle password dialog if visible
if a.showPasswordDialog {
var cmd tea.Cmd
a.passwordDialog, cmd = a.passwordDialog.Update(msg)
return a, cmd
}

// Handle command palette if visible
if a.showCommandPalette {
return a.handleCommandPalette(msg)
Expand Down Expand Up @@ -1726,6 +1767,11 @@ func (a *App) View() string {
return zone.Scan(a.renderConnectionDialog())
}

// If password dialog is showing, render it
if a.showPasswordDialog {
return zone.Scan(a.renderPasswordDialog())
}

// If in help mode, show help overlay
if a.state.ViewMode == models.HelpMode {
return help.Render(a.state.Width, a.state.Height, lipgloss.NewStyle())
Expand Down Expand Up @@ -2749,7 +2795,18 @@ func (a *App) connectToHistoryEntry(entry models.ConnectionHistoryEntry) (tea.Mo

// Convert history entry to connection config WITH password from keyring
if a.connectionHistory != nil {
config = a.connectionHistory.GetConnectionConfigWithPassword(&entry)
result := a.connectionHistory.GetConnectionConfigWithPassword(&entry)
config = result.Config

// If password is missing, show password dialog
if result.PasswordMissing {
entryCopy := entry
a.pendingConnectionInfo = &entryCopy
a.passwordDialog.SetConnectionInfo(entry.Host, entry.Port, entry.Database, entry.User)
a.showPasswordDialog = true
a.showConnectionDialog = false
return a, a.passwordDialog.Init()
}
} else {
config = entry.ToConnectionConfig()
}
Expand Down Expand Up @@ -2799,9 +2856,13 @@ func (a *App) performConnection(config models.ConnectionConfig) (tea.Model, tea.

// Save to connection history (ignore errors)
if a.connectionHistory != nil {
if err := a.connectionHistory.Add(config); err != nil {
result, err := a.connectionHistory.Add(config)
if err != nil {
log.Printf("Warning: Failed to save connection to history: %v", err)
} else {
if result != nil && result.PasswordSaveError != nil {
log.Printf("Warning: Failed to save password: %v", result.PasswordSaveError)
}
// Reload history in dialog
history := a.connectionHistory.GetRecent(10)
a.connectionDialog.SetHistoryEntries(history)
Expand Down Expand Up @@ -2965,9 +3026,13 @@ func (a *App) handleConnectionDialog(msg tea.KeyMsg) (tea.Model, tea.Cmd) {

// Save to connection history (ignore errors)
if a.connectionHistory != nil {
if err := a.connectionHistory.Add(config); err != nil {
result, err := a.connectionHistory.Add(config)
if err != nil {
log.Printf("Warning: Failed to save connection to history: %v", err)
} else {
if result != nil && result.PasswordSaveError != nil {
log.Printf("Warning: Failed to save password: %v", result.PasswordSaveError)
}
// Reload history in dialog
history := a.connectionHistory.GetRecent(10)
a.connectionDialog.SetHistoryEntries(history)
Expand All @@ -2993,7 +3058,18 @@ func (a *App) handleConnectionDialog(msg tea.KeyMsg) (tea.Model, tea.Cmd) {

// Convert history entry to connection config WITH password from keyring
if a.connectionHistory != nil {
config = a.connectionHistory.GetConnectionConfigWithPassword(historyEntry)
result := a.connectionHistory.GetConnectionConfigWithPassword(historyEntry)
config = result.Config

// If password is missing, show password dialog
if result.PasswordMissing {
entryCopy := *historyEntry
a.pendingConnectionInfo = &entryCopy
a.passwordDialog.SetConnectionInfo(historyEntry.Host, historyEntry.Port, historyEntry.Database, historyEntry.User)
a.showPasswordDialog = true
a.showConnectionDialog = false
return a, a.passwordDialog.Init()
}
} else {
config = historyEntry.ToConnectionConfig()
}
Expand Down Expand Up @@ -3045,9 +3121,13 @@ func (a *App) handleConnectionDialog(msg tea.KeyMsg) (tea.Model, tea.Cmd) {

// Save to connection history (ignore errors)
if a.connectionHistory != nil {
if err := a.connectionHistory.Add(config); err != nil {
result, err := a.connectionHistory.Add(config)
if err != nil {
log.Printf("Warning: Failed to save connection to history: %v", err)
} else {
if result != nil && result.PasswordSaveError != nil {
log.Printf("Warning: Failed to save password: %v", result.PasswordSaveError)
}
// Reload history in dialog
history := a.connectionHistory.GetRecent(10)
a.connectionDialog.SetHistoryEntries(history)
Expand Down Expand Up @@ -3323,6 +3403,33 @@ func (a *App) renderConnectionDialog() string {
return style.Render(dialog)
}

func (a *App) renderPasswordDialog() string {
// Center the dialog
dialogWidth := 50
dialogHeight := 12

a.passwordDialog.Width = dialogWidth
a.passwordDialog.Height = dialogHeight

dialog := a.passwordDialog.View()

// Center it
verticalPadding := (a.state.Height - dialogHeight) / 2
horizontalPadding := (a.state.Width - dialogWidth) / 2

if verticalPadding < 0 {
verticalPadding = 0
}
if horizontalPadding < 0 {
horizontalPadding = 0
}

style := lipgloss.NewStyle().
Padding(verticalPadding, 0, 0, horizontalPadding)

return style.Render(dialog)
}

// triggerDiscovery runs discovery in the background and returns a command
func (a *App) triggerDiscovery() tea.Cmd {
return func() tea.Msg {
Expand Down
36 changes: 36 additions & 0 deletions internal/connection_history/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package connection_history

import "errors"

// ErrPasswordNotFound is returned when a password is not found in the keyring
var ErrPasswordNotFound = errors.New("password not found in keyring")

// PasswordSaveError represents an error that occurred while saving a password
type PasswordSaveError struct {
Err error
Message string
}

func (e *PasswordSaveError) Error() string {
if e.Message != "" {
return e.Message + ": " + e.Err.Error()
}
return e.Err.Error()
}

func (e *PasswordSaveError) Unwrap() error {
return e.Err
}

// PasswordReadError represents an error that occurred while reading a password
type PasswordReadError struct {
Err error
}

func (e *PasswordReadError) Error() string {
return "failed to read password from keyring: " + e.Err.Error()
}

func (e *PasswordReadError) Unwrap() error {
return e.Err
}
Loading