Fixed prompt input to filter out 0x0D and 0x08 keystrokes
These can occur when pasting input with line-feeds.
This commit is contained in:
parent
46a430f58f
commit
7b194d0a19
|
@ -7,3 +7,13 @@ func Map[T, U any](ts []T, fn func(t T) U) []U {
|
||||||
}
|
}
|
||||||
return us
|
return us
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Filter[T any](ts []T, fn func(t T) bool) []T {
|
||||||
|
us := make([]T, 0)
|
||||||
|
for _, t := range ts {
|
||||||
|
if fn(t) {
|
||||||
|
us = append(us, t)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return us
|
||||||
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"github.com/charmbracelet/bubbles/textinput"
|
"github.com/charmbracelet/bubbles/textinput"
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
"github.com/charmbracelet/lipgloss"
|
"github.com/charmbracelet/lipgloss"
|
||||||
|
"github.com/lmika/awstools/internal/common/sliceutils"
|
||||||
"github.com/lmika/awstools/internal/common/ui/events"
|
"github.com/lmika/awstools/internal/common/ui/events"
|
||||||
"github.com/lmika/awstools/internal/dynamo-browse/ui/teamodels/layout"
|
"github.com/lmika/awstools/internal/dynamo-browse/ui/teamodels/layout"
|
||||||
)
|
)
|
||||||
|
@ -59,15 +60,18 @@ func (s *StatusAndPrompt) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
return s, nil
|
return s, nil
|
||||||
case tea.KeyMsg:
|
case tea.KeyMsg:
|
||||||
if s.pendingInput != nil {
|
if s.pendingInput != nil {
|
||||||
switch msg.String() {
|
switch msg.Type {
|
||||||
case "ctrl+c", "esc":
|
case tea.KeyCtrlC, tea.KeyEsc:
|
||||||
s.pendingInput = nil
|
s.pendingInput = nil
|
||||||
case "enter":
|
case tea.KeyEnter:
|
||||||
pendingInput := s.pendingInput
|
pendingInput := s.pendingInput
|
||||||
s.pendingInput = nil
|
s.pendingInput = nil
|
||||||
|
|
||||||
return s, pendingInput.OnDone(s.textInput.Value())
|
return s, pendingInput.OnDone(s.textInput.Value())
|
||||||
default:
|
default:
|
||||||
|
if msg.Type == tea.KeyRunes {
|
||||||
|
msg.Runes = sliceutils.Filter(msg.Runes, func(r rune) bool { return r != '\x0d' && r != '\x0a' })
|
||||||
|
}
|
||||||
newTextInput, cmd := s.textInput.Update(msg)
|
newTextInput, cmd := s.textInput.Update(msg)
|
||||||
s.textInput = newTextInput
|
s.textInput = newTextInput
|
||||||
return s, cmd
|
return s, cmd
|
||||||
|
|
Loading…
Reference in a new issue