diff --git a/pam/internal/adapter/model.go b/pam/internal/adapter/model.go index c1b4cfa42..a11660d21 100644 --- a/pam/internal/adapter/model.go +++ b/pam/internal/adapter/model.go @@ -100,7 +100,7 @@ type ChangeStage struct { // Init initializes the main model orchestrator. func (m *UIModel) Init() tea.Cmd { m.exitStatus = pamError{status: pam.ErrSystem, msg: "model did not return anything"} - m.userSelectionModel = newUserSelectionModel(m.PamMTx) + m.userSelectionModel = newUserSelectionModel(m.PamMTx, m.ClientType) var cmds []tea.Cmd cmds = append(cmds, m.userSelectionModel.Init()) diff --git a/pam/internal/adapter/userselection.go b/pam/internal/adapter/userselection.go index 29583b67e..bf127fa1b 100644 --- a/pam/internal/adapter/userselection.go +++ b/pam/internal/adapter/userselection.go @@ -1,6 +1,7 @@ package adapter import ( + "github.com/charmbracelet/bubbles/cursor" "github.com/charmbracelet/bubbles/textinput" tea "github.com/charmbracelet/bubbletea" "github.com/msteinert/pam/v2" @@ -10,7 +11,8 @@ import ( type userSelectionModel struct { textinput.Model - pamMTx pam.ModuleTransaction + pamMTx pam.ModuleTransaction + clientType PamClientType } // userSelected events to select a new username. @@ -26,8 +28,13 @@ func sendUserSelected(username string) tea.Cmd { } // newUserSelectionModel returns an initialized userSelectionModel. -func newUserSelectionModel(pamMTx pam.ModuleTransaction) userSelectionModel { +func newUserSelectionModel(pamMTx pam.ModuleTransaction, clientType PamClientType) userSelectionModel { u := textinput.New() + if clientType != InteractiveTerminal { + // Cursor events are racy: https://github.com/charmbracelet/bubbletea/issues/909. + // FIXME: Avoid initializing the text input Model at all. + u.Cursor.SetMode(cursor.CursorHide) + } u.Prompt = "Username: " // TODO: i18n u.Placeholder = "user name" @@ -35,7 +42,8 @@ func newUserSelectionModel(pamMTx pam.ModuleTransaction) userSelectionModel { return userSelectionModel{ Model: u, - pamMTx: pamMTx, + pamMTx: pamMTx, + clientType: clientType, } }