Skip to content

Instantly share code, notes, and snippets.

@mehmetcantas
Created April 9, 2022 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mehmetcantas/2c08cd0e989def75ad46cf81f739bf80 to your computer and use it in GitHub Desktop.
Save mehmetcantas/2c08cd0e989def75ad46cf81f739bf80 to your computer and use it in GitHub Desktop.
import "github.com/charmbracelet/bubbles/key"
type KeyMap struct {
Up key.Binding
Down key.Binding
TogglePreview key.Binding
OpenGithub key.Binding
Refresh key.Binding
PageDown key.Binding
PageUp key.Binding
NextSection key.Binding
PrevSection key.Binding
SwitchView key.Binding
Help key.Binding
Quit key.Binding
}
func (k KeyMap) ShortHelp() []key.Binding {
return []key.Binding{k.Help, k.Quit}
}
func (k KeyMap) FullHelp() [][]key.Binding {
return [][]key.Binding{
{k.Up, k.Down},
{k.PrevSection, k.NextSection},
{k.PageDown, k.PageUp},
{k.TogglePreview, k.OpenGithub},
{k.Refresh, k.SwitchView},
{k.Help, k.Quit},
}
}
var Keys = KeyMap{
Up: key.NewBinding(
key.WithKeys("up", "k"),
key.WithHelp("⬆/k", "move up"),
),
Down: key.NewBinding(
key.WithKeys("down", "j"),
key.WithHelp("⬇/j", "move down"),
),
PrevSection: key.NewBinding(
key.WithKeys("left", "h"),
key.WithHelp("<-/h", "previous section"),
),
NextSection: key.NewBinding(
key.WithKeys("right", "l"),
key.WithHelp("->/l", "next section"),
),
PageUp: key.NewBinding(
key.WithKeys("ctrl+u"),
key.WithHelp("Ctrl+u", "preview page up"),
),
PageDown: key.NewBinding(
key.WithKeys("ctrl+d"),
key.WithHelp("Ctrl+d", "preview page down"),
),
TogglePreview: key.NewBinding(
key.WithKeys("p"),
key.WithHelp("p", "open in preview"),
),
OpenGithub: key.NewBinding(
key.WithKeys("o"),
key.WithHelp("o", "open in Github"),
),
Refresh: key.NewBinding(
key.WithKeys("r"),
key.WithHelp("r", "refresh"),
),
SwitchView: key.NewBinding(
key.WithKeys("?"),
key.WithHelp("?", "toggle help"),
),
Quit: key.NewBinding(
key.WithKeys("q", "esc", "ctrl+c"),
key.WithHelp("q", "quit"),
),
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment