fix: hiddenInput & remove viewportState
This commit is contained in:
parent
f46b0b2c44
commit
0af704abf3
7
input.go
7
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))
|
||||
|
|
40
model.go
40
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
|
||||
|
|
Reference in New Issue