Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature #49: Custom keys mapping #51

Merged
merged 4 commits into from
Mar 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion config.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
github:
token: <your github token>
token: <your github token>

keys:
switchTabRight: shift+right
switchTabLeft: shift+left
quit: ctrl+c
refresh: ctrl+r
enter: enter
tab: tab
52 changes: 32 additions & 20 deletions internal/terminal/handler/ghrepository/keymap.go
Original file line number Diff line number Diff line change
@@ -1,41 +1,53 @@
package ghrepository

import (
"fmt"

teakey "github.com/charmbracelet/bubbles/key"
pkgconfig "github.com/termkit/gama/pkg/config"
)

type keyMap struct {
Refresh teakey.Binding
LaunchOption teakey.Binding
TabSwitch teakey.Binding
Refresh teakey.Binding
LaunchTab teakey.Binding
SwitchTab teakey.Binding
}

func (k keyMap) ShortHelp() []teakey.Binding {
return []teakey.Binding{k.TabSwitch, k.Refresh, k.LaunchOption}
return []teakey.Binding{k.SwitchTab, k.Refresh, k.LaunchTab}
}

func (k keyMap) FullHelp() [][]teakey.Binding {
return [][]teakey.Binding{
{k.TabSwitch},
{k.SwitchTab},
{k.Refresh},
{k.LaunchOption},
{k.LaunchTab},
}
}

var keys = keyMap{
Refresh: teakey.NewBinding(
teakey.WithKeys("ctrl+r", "ctrl+R"),
teakey.WithHelp("ctrl + (r | R)", "Refresh list"),
),
LaunchOption: teakey.NewBinding(
teakey.WithKeys("enter"),
teakey.WithHelp("enter", "Launch the selected option"),
),
TabSwitch: teakey.NewBinding(
teakey.WithKeys(""), // help-only binding
teakey.WithHelp("shift + (← | →)", "switch tab"),
),
}
var keys = func() keyMap {
cfg, err := pkgconfig.LoadConfig()
if err != nil {
panic(fmt.Sprintf("failed to load config: %v", err))
}

var tabSwitch = fmt.Sprintf("%s | %s", cfg.Shortcuts.SwitchTabLeft, cfg.Shortcuts.SwitchTabRight)

return keyMap{
Refresh: teakey.NewBinding(
teakey.WithKeys(cfg.Shortcuts.Refresh),
teakey.WithHelp(cfg.Shortcuts.Refresh, "Refresh list"),
),
LaunchTab: teakey.NewBinding(
teakey.WithKeys(cfg.Shortcuts.Enter),
teakey.WithHelp(cfg.Shortcuts.Enter, "Launch the selected option"),
),
SwitchTab: teakey.NewBinding(
teakey.WithKeys(""), // help-only binding
teakey.WithHelp(tabSwitch, "switch tab"),
),
}
}()

func (m *ModelGithubRepository) ViewHelp() string {
return m.Help.View(m.Keys)
Expand Down
60 changes: 36 additions & 24 deletions internal/terminal/handler/ghtrigger/keymap.go
Original file line number Diff line number Diff line change
@@ -1,47 +1,59 @@
package ghtrigger

import (
"fmt"

teakey "github.com/charmbracelet/bubbles/key"
pkgconfig "github.com/termkit/gama/pkg/config"
)

type keyMap struct {
PreviousTab teakey.Binding
SwitchTab teakey.Binding
Trigger teakey.Binding
Refresh teakey.Binding
SwitchTabLeft teakey.Binding
SwitchTab teakey.Binding
Trigger teakey.Binding
Refresh teakey.Binding
}

func (k keyMap) ShortHelp() []teakey.Binding {
return []teakey.Binding{k.PreviousTab, k.Refresh, k.SwitchTab, k.Trigger}
return []teakey.Binding{k.SwitchTabLeft, k.Refresh, k.SwitchTab, k.Trigger}
}

func (k keyMap) FullHelp() [][]teakey.Binding {
return [][]teakey.Binding{
{k.PreviousTab},
{k.SwitchTabLeft},
{k.Refresh},
{k.SwitchTab},
{k.Trigger},
}
}

var keys = keyMap{
PreviousTab: teakey.NewBinding(
teakey.WithKeys(""), // help-only binding
teakey.WithHelp("shift + ←", "previous tab"),
),
Refresh: teakey.NewBinding(
teakey.WithKeys("ctrl+r", "ctrl+R"),
teakey.WithHelp("ctrl+r", "Refresh content"),
),
SwitchTab: teakey.NewBinding(
teakey.WithKeys("tab"),
teakey.WithHelp("tab", "switch button"),
),
Trigger: teakey.NewBinding(
teakey.WithKeys("enter"),
teakey.WithHelp("enter", "trigger workflow"),
),
}
var keys = func() keyMap {
cfg, err := pkgconfig.LoadConfig()
if err != nil {
panic(fmt.Sprintf("failed to load config: %v", err))
}

var previousTab = fmt.Sprintf("%s", cfg.Shortcuts.SwitchTabLeft)

return keyMap{
SwitchTabLeft: teakey.NewBinding(
teakey.WithKeys(""), // help-only binding
teakey.WithHelp(previousTab, "previous tab"),
),
Refresh: teakey.NewBinding(
teakey.WithKeys(cfg.Shortcuts.Refresh),
teakey.WithHelp(cfg.Shortcuts.Refresh, "Refresh list"),
),
SwitchTab: teakey.NewBinding(
teakey.WithKeys(cfg.Shortcuts.Tab),
teakey.WithHelp(cfg.Shortcuts.Tab, "switch button"),
),
Trigger: teakey.NewBinding(
teakey.WithKeys(cfg.Shortcuts.Enter),
teakey.WithHelp(cfg.Shortcuts.Enter, "trigger workflow"),
),
}
}()

func (m *ModelGithubTrigger) ViewHelp() string {
return m.Help.View(m.Keys)
Expand Down
30 changes: 21 additions & 9 deletions internal/terminal/handler/ghworkflow/keymap.go
Original file line number Diff line number Diff line change
@@ -1,29 +1,41 @@
package ghworkflow

import (
"fmt"

teakey "github.com/charmbracelet/bubbles/key"
pkgconfig "github.com/termkit/gama/pkg/config"
)

type keyMap struct {
TabSwitch teakey.Binding
SwitchTab teakey.Binding
}

func (k keyMap) ShortHelp() []teakey.Binding {
return []teakey.Binding{k.TabSwitch}
return []teakey.Binding{k.SwitchTab}
}

func (k keyMap) FullHelp() [][]teakey.Binding {
return [][]teakey.Binding{
{k.TabSwitch},
{k.SwitchTab},
}
}

var keys = keyMap{
TabSwitch: teakey.NewBinding(
teakey.WithKeys(""), // help-only binding
teakey.WithHelp("shift + (← | →)", "switch tab"),
),
}
var keys = func() keyMap {
cfg, err := pkgconfig.LoadConfig()
if err != nil {
panic(fmt.Sprintf("failed to load config: %v", err))
}

var tabSwitch = fmt.Sprintf("%s | %s", cfg.Shortcuts.SwitchTabLeft, cfg.Shortcuts.SwitchTabRight)

return keyMap{
SwitchTab: teakey.NewBinding(
teakey.WithKeys(""), // help-only binding
teakey.WithHelp(tabSwitch, "switch tab"),
),
}
}()

func (m *ModelGithubWorkflow) ViewHelp() string {
return m.Help.View(m.Keys)
Expand Down
46 changes: 29 additions & 17 deletions internal/terminal/handler/ghworkflowhistory/keymap.go
Original file line number Diff line number Diff line change
@@ -1,41 +1,53 @@
package ghworkflowhistory

import (
"fmt"

teakey "github.com/charmbracelet/bubbles/key"
pkgconfig "github.com/termkit/gama/pkg/config"
)

type keyMap struct {
LaunchTab teakey.Binding
Refresh teakey.Binding
TabSwitch teakey.Binding
SwitchTab teakey.Binding
}

func (k keyMap) ShortHelp() []teakey.Binding {
return []teakey.Binding{k.TabSwitch, k.Refresh, k.LaunchTab}
return []teakey.Binding{k.SwitchTab, k.Refresh, k.LaunchTab}
}

func (k keyMap) FullHelp() [][]teakey.Binding {
return [][]teakey.Binding{
{k.TabSwitch},
{k.SwitchTab},
{k.Refresh},
{k.LaunchTab},
}
}

var keys = keyMap{
Refresh: teakey.NewBinding(
teakey.WithKeys("r", "R"),
teakey.WithHelp("r/R", "Refresh list"),
),
LaunchTab: teakey.NewBinding(
teakey.WithKeys("enter"),
teakey.WithHelp("enter", "Launch the selected option"),
),
TabSwitch: teakey.NewBinding(
teakey.WithKeys(""), // help-only binding
teakey.WithHelp("shift + (← | →)", "switch tab"),
),
}
var keys = func() keyMap {
cfg, err := pkgconfig.LoadConfig()
if err != nil {
panic(fmt.Sprintf("failed to load config: %v", err))
}

var tabSwitch = fmt.Sprintf("%s | %s", cfg.Shortcuts.SwitchTabLeft, cfg.Shortcuts.SwitchTabRight)

return keyMap{
Refresh: teakey.NewBinding(
teakey.WithKeys(cfg.Shortcuts.Refresh),
teakey.WithHelp(cfg.Shortcuts.Refresh, "Refresh list"),
),
LaunchTab: teakey.NewBinding(
teakey.WithKeys(cfg.Shortcuts.Enter),
teakey.WithHelp(cfg.Shortcuts.Enter, "Launch the selected option"),
),
SwitchTab: teakey.NewBinding(
teakey.WithKeys(""), // help-only binding
teakey.WithHelp(tabSwitch, "switch tab"),
),
}
}()

func (m *ModelGithubWorkflowHistory) ViewHelp() string {
return m.Help.View(m.Keys)
Expand Down
40 changes: 26 additions & 14 deletions internal/terminal/handler/information/keymap.go
Original file line number Diff line number Diff line change
@@ -1,35 +1,47 @@
package information

import (
"fmt"

teakey "github.com/charmbracelet/bubbles/key"
pkgconfig "github.com/termkit/gama/pkg/config"
)

type keyMap struct {
NextTab teakey.Binding
Quit teakey.Binding
SwitchTabRight teakey.Binding
Quit teakey.Binding
}

func (k keyMap) ShortHelp() []teakey.Binding {
return []teakey.Binding{k.NextTab, k.Quit}
return []teakey.Binding{k.SwitchTabRight, k.Quit}
}

func (k keyMap) FullHelp() [][]teakey.Binding {
return [][]teakey.Binding{
{k.NextTab},
{k.SwitchTabRight},
{k.Quit},
}
}

var keys = keyMap{
NextTab: teakey.NewBinding(
teakey.WithKeys(""), // help-only binding
teakey.WithHelp("shift + →", "next tab"),
),
Quit: teakey.NewBinding(
teakey.WithKeys("q", "ctrl+c"),
teakey.WithHelp("q", "quit"),
),
}
var keys = func() keyMap {
cfg, err := pkgconfig.LoadConfig()
if err != nil {
panic(fmt.Sprintf("failed to load config: %v", err))
}

var switchTabRight = fmt.Sprintf("%s", cfg.Shortcuts.SwitchTabRight)

return keyMap{
SwitchTabRight: teakey.NewBinding(
teakey.WithKeys(""), // help-only binding
teakey.WithHelp(switchTabRight, "next tab"),
),
Quit: teakey.NewBinding(
teakey.WithKeys("q", cfg.Shortcuts.Quit),
teakey.WithHelp("q", "quit"),
),
}
}()

func (m *ModelInfo) ViewHelp() string {
return m.Help.View(m.Keys)
Expand Down
31 changes: 20 additions & 11 deletions internal/terminal/handler/keymap.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package handler

import (
"fmt"

teakey "github.com/charmbracelet/bubbles/key"
pkgconfig "github.com/termkit/gama/pkg/config"
)

type keyMap struct {
Expand All @@ -10,14 +13,20 @@ type keyMap struct {
Quit teakey.Binding
}

var keys = keyMap{
SwitchTabRight: teakey.NewBinding(
teakey.WithKeys("shift+right"),
),
SwitchTabLeft: teakey.NewBinding(
teakey.WithKeys("shift+left"),
),
Quit: teakey.NewBinding(
teakey.WithKeys("ctrl+c"),
),
}
var keys = func() keyMap {
cfg, err := pkgconfig.LoadConfig()
if err != nil {
panic(fmt.Sprintf("failed to load config: %v", err))
}
return keyMap{
SwitchTabRight: teakey.NewBinding(
teakey.WithKeys(cfg.Shortcuts.SwitchTabRight),
),
SwitchTabLeft: teakey.NewBinding(
teakey.WithKeys(cfg.Shortcuts.SwitchTabLeft),
),
Quit: teakey.NewBinding(
teakey.WithKeys(cfg.Shortcuts.Quit),
),
}
}()
Loading