issue-9: moved keybindings out into a separate type

Also started working on a service which can be used to rebind keys using reflection.
This commit is contained in:
Leon Mika 2022-08-24 22:06:29 +10:00
parent cb31da3806
commit 2f89610c51
5 changed files with 102 additions and 15 deletions

View file

@ -6,6 +6,7 @@ import (
"fmt"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/dynamodb"
"github.com/charmbracelet/bubbles/key"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/lmika/audax/internal/common/ui/commandctrl"
@ -16,6 +17,7 @@ import (
"github.com/lmika/audax/internal/dynamo-browse/providers/dynamo"
"github.com/lmika/audax/internal/dynamo-browse/providers/workspacestore"
"github.com/lmika/audax/internal/dynamo-browse/services/itemrenderer"
"github.com/lmika/audax/internal/dynamo-browse/services/keybindings"
"github.com/lmika/audax/internal/dynamo-browse/services/tables"
workspaces_service "github.com/lmika/audax/internal/dynamo-browse/services/workspaces"
"github.com/lmika/audax/internal/dynamo-browse/ui"
@ -80,8 +82,33 @@ func main() {
tableReadController := controllers.NewTableReadController(state, tableService, workspaceService, itemRendererService, *flagTable, true)
tableWriteController := controllers.NewTableWriteController(state, tableService, tableReadController)
defaultKeyBindings := &ui.KeyBindings{
View: &ui.ViewKeyBindings{
Mark: key.NewBinding(key.WithKeys("m"), key.WithHelp("m", "mark")),
CopyItemToClipboard: key.NewBinding(key.WithKeys("c"), key.WithHelp("c", "copy item to clipboard")),
Rescan: key.NewBinding(key.WithKeys("R"), key.WithHelp("R", "rescan")),
PromptForQuery: key.NewBinding(key.WithKeys("?"), key.WithHelp("?", "prompt for query")),
PromptForFilter: key.NewBinding(key.WithKeys("f"), key.WithHelp("/", "filter")),
ViewBack: key.NewBinding(key.WithKeys("backspace"), key.WithHelp("backspace", "go back")),
ViewForward: key.NewBinding(key.WithKeys("\\"), key.WithHelp("\\", "go forward")),
CycleLayoutForward: key.NewBinding(key.WithKeys("w"), key.WithHelp("w", "cycle layout forward")),
CycleLayoutBackwards: key.NewBinding(key.WithKeys("W"), key.WithHelp("W", "cycle layout backward")),
PromptForCommand: key.NewBinding(key.WithKeys(":"), key.WithHelp(":", "prompt for command")),
Quit: key.NewBinding(key.WithKeys("ctrl+c", "esc"), key.WithHelp("ctrl+c/esc", "quit")),
},
}
commandController := commandctrl.NewCommandController()
model := ui.NewModel(tableReadController, tableWriteController, itemRendererService, commandController)
keyBindingService := keybindings.NewService(defaultKeyBindings)
_ = keyBindingService
model := ui.NewModel(
tableReadController,
tableWriteController,
itemRendererService,
commandController,
defaultKeyBindings,
)
// Pre-determine if layout has dark background. This prevents calls for creating a list to hang.
lipgloss.HasDarkBackground()