diff --git a/internal/common/sliceutils/map.go b/internal/common/sliceutils/map.go index f74602c..8d34dd8 100644 --- a/internal/common/sliceutils/map.go +++ b/internal/common/sliceutils/map.go @@ -7,3 +7,13 @@ func Map[T, U any](ts []T, fn func(t T) U) []U { } 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 +} diff --git a/internal/dynamo-browse/ui/teamodels/statusandprompt/model.go b/internal/dynamo-browse/ui/teamodels/statusandprompt/model.go index a290750..ddee99d 100644 --- a/internal/dynamo-browse/ui/teamodels/statusandprompt/model.go +++ b/internal/dynamo-browse/ui/teamodels/statusandprompt/model.go @@ -4,6 +4,7 @@ import ( "github.com/charmbracelet/bubbles/textinput" tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/lipgloss" + "github.com/lmika/awstools/internal/common/sliceutils" "github.com/lmika/awstools/internal/common/ui/events" "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 case tea.KeyMsg: if s.pendingInput != nil { - switch msg.String() { - case "ctrl+c", "esc": + switch msg.Type { + case tea.KeyCtrlC, tea.KeyEsc: s.pendingInput = nil - case "enter": + case tea.KeyEnter: pendingInput := s.pendingInput s.pendingInput = nil return s, pendingInput.OnDone(s.textInput.Value()) 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) s.textInput = newTextInput return s, cmd