diff --git a/input.go b/input.go index 3442f6e..77ee289 100644 --- a/input.go +++ b/input.go @@ -123,7 +123,7 @@ func handleCommand(cmd, hiddenInput string) tea.Msg { } func hidePasswordInput(m *model) { - val := m.input.Value() + val := strings.TrimSpace(m.input.Value()) if len(val) == 0 { return @@ -138,10 +138,11 @@ func hidePasswordInput(m *model) { return } - if cmds[1] == "create" && len(cmds) > 3 || cmds[1] == "unlock" && len(cmds) > 2 { + if cmds[1] == "create" && len(cmds) > 3 || + cmds[1] == "unlock" && len(cmds) > 2 { lastChar := string(val[len(val)-1]) - m.hiddenInput += lastChar if lastChar != " " { + m.hiddenInput += lastChar newCmd := []rune(val) newCmd[len(val)-1] = '*' m.input.SetValue(string(newCmd)) diff --git a/model.go b/model.go index ced373d..a6c54ff 100644 --- a/model.go +++ b/model.go @@ -67,7 +67,6 @@ type model struct { statusViewport viewport.Model statusViewportLines []string statusViewportReady bool - viewportState int profiles profiles profileState int @@ -139,6 +138,24 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { cmds []tea.Cmd ) + m.input, cmd = m.input.Update(msg) + cmds = append(cmds, cmd) + + m.statusViewport, cmd = m.statusViewport.Update(msg) + cmds = append(cmds, cmd) + + for _, p := range m.profiles { + p.statusViewport, cmd = p.statusViewport.Update(msg) + cmds = append(cmds, cmd) + } + + if m.showWelcomeMessage { + cmds = append(cmds, m.sendStatusCmd( + strings.Split(welcomeMessage, "\n")..., + )) + m.showWelcomeMessage = false + } + switch msg := msg.(type) { case tea.WindowSizeMsg: m.width = msg.Width @@ -321,24 +338,6 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { cmds = append(cmds, m.sendStatusCmd(msg.Error())) } - m.input, cmd = m.input.Update(msg) - cmds = append(cmds, cmd) - - m.statusViewport, cmd = m.statusViewport.Update(msg) - cmds = append(cmds, cmd) - - for _, p := range m.profiles { - p.statusViewport, cmd = p.statusViewport.Update(msg) - cmds = append(cmds, cmd) - } - - if m.showWelcomeMessage { - cmds = append(cmds, m.sendStatusCmd( - strings.Split(welcomeMessage, "\n")..., - )) - m.showWelcomeMessage = false - } - return m, tea.Batch(cmds...) } @@ -358,15 +357,12 @@ func (m model) View() string { switch m.menuState { case 0: chosenViewport = m.statusViewport - m.viewportState = 0 default: if m.menuState > len(m.profiles) { chosenViewport = m.statusViewport - m.viewportState = 0 break } chosenViewport = m.profiles[m.menuState-1].statusViewport - m.viewportState = m.menuState - 1 } var renderedCmdHelp []string