Fixed a few cosmetic bugs

- Clear status messages when setting or deleting fields
- Fixed "Filter" status label
This commit is contained in:
Leon Mika 2022-08-31 20:46:53 +10:00
parent 0c377e231a
commit 5f76836166
7 changed files with 22 additions and 12 deletions

View file

@ -10,8 +10,10 @@ func Error(err error) tea.Msg {
return ErrorMsg(err) return ErrorMsg(err)
} }
func SetStatus(msg string) tea.Msg { func SetStatus(msg string) tea.Cmd {
return StatusMsg(msg) return func() tea.Msg {
return StatusMsg(msg)
}
} }
func PromptForInput(prompt string, onDone func(value string) tea.Msg) tea.Msg { func PromptForInput(prompt string, onDone func(value string) tea.Msg) tea.Msg {

View file

@ -27,7 +27,7 @@ func (rs NewResultSet) ModeMessage() string {
} }
if rs.currentFilter != "" { if rs.currentFilter != "" {
modeLine = fmt.Sprintf("%v - PromptForFilter: '%v'", modeLine, rs.currentFilter) modeLine = fmt.Sprintf("%v - Filter: '%v'", modeLine, rs.currentFilter)
} }
return modeLine return modeLine
} }

View file

@ -19,7 +19,7 @@ func NewKeyBindingController(service *keybindings.Service) *KeyBindingController
func (kb *KeyBindingController) Rebind(bindingName string, newKey string, force bool) tea.Msg { func (kb *KeyBindingController) Rebind(bindingName string, newKey string, force bool) tea.Msg {
err := kb.service.Rebind(bindingName, newKey, force) err := kb.service.Rebind(bindingName, newKey, force)
if err == nil { if err == nil {
return events.SetStatus(fmt.Sprintf("Binding '%v' now bound to '%v'", bindingName, newKey)) return events.StatusMsg(fmt.Sprintf("Binding '%v' now bound to '%v'", bindingName, newKey))
} else if force { } else if force {
return events.Error(errors.Wrapf(err, "cannot bind '%v' to '%v'", bindingName, newKey)) return events.Error(errors.Wrapf(err, "cannot bind '%v' to '%v'", bindingName, newKey))
} }
@ -32,7 +32,7 @@ func (kb *KeyBindingController) Rebind(bindingName string, newKey string, force
if err != nil { if err != nil {
return events.Error(err) return events.Error(err)
} }
return events.SetStatus(fmt.Sprintf("Binding '%v' now bound to '%v'", bindingName, newKey)) return events.StatusMsg(fmt.Sprintf("Binding '%v' now bound to '%v'", bindingName, newKey))
}) })
} }

View file

@ -152,7 +152,7 @@ func (c *TableReadController) doIfNoneDirty(cmd tea.Cmd) tea.Msg {
Prompt: "reset modified items? ", Prompt: "reset modified items? ",
OnDone: func(value string) tea.Msg { OnDone: func(value string) tea.Msg {
if value != "y" { if value != "y" {
return events.SetStatus("operation aborted") return events.StatusMsg("operation aborted")
} }
return cmd() return cmd()
@ -321,7 +321,7 @@ func (c *TableReadController) CopyItemToClipboard(idx int) tea.Msg {
clipboard.Write(clipboard.FmtText, []byte(sb.String())) clipboard.Write(clipboard.FmtText, []byte(sb.String()))
}) })
return events.SetStatus(applyToN("", itemCount, "item", "items", " copied to clipboard")) return events.StatusMsg(applyToN("", itemCount, "item", "items", " copied to clipboard"))
} }
func (c *TableReadController) initClipboard() error { func (c *TableReadController) initClipboard() error {

View file

@ -288,7 +288,7 @@ func (twc *TableWriteController) PutItems() tea.Msg {
Prompt: promptMessage, Prompt: promptMessage,
OnDone: func(value string) tea.Msg { OnDone: func(value string) tea.Msg {
if value != "y" { if value != "y" {
return events.SetStatus("operation aborted") return events.StatusMsg("operation aborted")
} }
if err := twc.state.withResultSetReturningError(func(rs *models.ResultSet) error { if err := twc.state.withResultSetReturningError(func(rs *models.ResultSet) error {
@ -370,7 +370,7 @@ func (twc *TableWriteController) DeleteMarked() tea.Msg {
Prompt: applyToN("delete ", len(markedItems), "item", "items", "? "), Prompt: applyToN("delete ", len(markedItems), "item", "items", "? "),
OnDone: func(value string) tea.Msg { OnDone: func(value string) tea.Msg {
if value != "y" { if value != "y" {
return events.SetStatus("operation aborted") return events.StatusMsg("operation aborted")
} }
ctx := context.Background() ctx := context.Background()

View file

@ -139,7 +139,7 @@ func NewModel(
for _, arg := range args { for _, arg := range args {
s.WriteString(arg) s.WriteString(arg)
} }
return events.SetStatus(s.String()) return events.StatusMsg(s.String())
}, },
"rebind": func(ctx commandctrl.ExecContext, args []string) tea.Msg { "rebind": func(ctx commandctrl.ExecContext, args []string) tea.Msg {
if len(args) != 2 { if len(args) != 2 {
@ -189,7 +189,10 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
cmd := m.setMainViewIndex(msg.ViewIndex) cmd := m.setMainViewIndex(msg.ViewIndex)
return m, cmd return m, cmd
case controllers.ResultSetUpdated: case controllers.ResultSetUpdated:
return m, m.tableView.Refresh() return m, tea.Batch(
m.tableView.Refresh(),
events.SetStatus(msg.StatusMessage()),
)
case tea.KeyMsg: case tea.KeyMsg:
if !m.statusAndPrompt.InPrompt() && !m.tableSelect.Visible() { if !m.statusAndPrompt.InPrompt() && !m.tableSelect.Visible() {
switch { switch {

View file

@ -7,6 +7,7 @@ import (
"github.com/lmika/audax/internal/common/sliceutils" "github.com/lmika/audax/internal/common/sliceutils"
"github.com/lmika/audax/internal/common/ui/events" "github.com/lmika/audax/internal/common/ui/events"
"github.com/lmika/audax/internal/dynamo-browse/ui/teamodels/layout" "github.com/lmika/audax/internal/dynamo-browse/ui/teamodels/layout"
"log"
) )
// StatusAndPrompt is a resizing model which displays a submodel and a status bar. When the start prompt // StatusAndPrompt is a resizing model which displays a submodel and a status bar. When the start prompt
@ -67,7 +68,11 @@ func (s *StatusAndPrompt) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
pendingInput := s.pendingInput pendingInput := s.pendingInput
s.pendingInput = nil s.pendingInput = nil
return s, func() tea.Msg { return pendingInput.OnDone(s.textInput.Value()) } return s, func() tea.Msg {
m := pendingInput.OnDone(s.textInput.Value())
log.Printf("return msg type = %T", m)
return m
}
default: default:
if msg.Type == tea.KeyRunes { if msg.Type == tea.KeyRunes {
msg.Runes = sliceutils.Filter(msg.Runes, func(r rune) bool { return r != '\x0d' && r != '\x0a' }) msg.Runes = sliceutils.Filter(msg.Runes, func(r rune) bool { return r != '\x0d' && r != '\x0a' })