From c7dce785e6734fe45cc1b06966297e98467a3507 Mon Sep 17 00:00:00 2001 From: drew Date: Tue, 29 Jul 2025 09:27:04 +0400 Subject: [PATCH] fix: full input placeholders (#9) --- tui/composer.go | 8 +++++++- tui/login.go | 16 +++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/tui/composer.go b/tui/composer.go index 34d006562bfb48ecaac72f5f2c35ed3fb12a3cef..b50d04d60b00ff855414b49a2219441e7cddce33 100644 --- a/tui/composer.go +++ b/tui/composer.go @@ -49,7 +49,6 @@ func NewComposer(from string) *Composer { m.bodyInput.Placeholder = "Body..." m.bodyInput.Prompt = "> " m.bodyInput.SetHeight(10) - m.bodyInput.SetWidth(60) return m } @@ -63,6 +62,13 @@ func (m *Composer) Update(msg tea.Msg) (tea.Model, tea.Cmd) { var cmd tea.Cmd switch msg := msg.(type) { + case tea.WindowSizeMsg: + // When the window is resized, update the width of the inputs. + inputWidth := msg.Width - 6 // Subtract for padding and prompt + m.toInput.Width = inputWidth + m.subjectInput.Width = inputWidth + m.bodyInput.SetWidth(inputWidth) + case tea.KeyMsg: switch msg.Type { // IMPORTANT: Removed tea.KeyEsc from this case diff --git a/tui/login.go b/tui/login.go index b19f099859bb790d1fac9f036887313eaf73ae26..f7ca80e3399c7afc8adee7fd6808f8ec1a164d4b 100644 --- a/tui/login.go +++ b/tui/login.go @@ -13,8 +13,8 @@ type Login struct { } // NewLogin creates a new login model. -func NewLogin() tea.Model { - m := Login{ +func NewLogin() *Login { + m := &Login{ inputs: make([]textinput.Model, 4), // Increased to 4 for provider, name, email, and password } @@ -47,13 +47,19 @@ func NewLogin() tea.Model { } // Init initializes the login model. -func (m Login) Init() tea.Cmd { +func (m *Login) Init() tea.Cmd { return textinput.Blink } // Update handles messages for the login model. -func (m Login) Update(msg tea.Msg) (tea.Model, tea.Cmd) { +func (m *Login) Update(msg tea.Msg) (tea.Model, tea.Cmd) { switch msg := msg.(type) { + case tea.WindowSizeMsg: + // When the window is resized, update the width of the inputs. + for i := range m.inputs { + m.inputs[i].Width = msg.Width - 6 // Subtract for padding and prompt + } + case tea.KeyMsg: switch msg.Type { // On Enter, if we are on the last field, submit the credentials. @@ -105,7 +111,7 @@ func (m Login) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } // View renders the login form. -func (m Login) View() string { +func (m *Login) View() string { return lipgloss.JoinVertical(lipgloss.Left, titleStyle.Render("Account Settings"), "Update your credentials.",