-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(keybindings): Use bubble tea keybindings (#47)
- Loading branch information
Showing
8 changed files
with
109 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,54 @@ | ||
package app | ||
|
||
import tea "github.com/charmbracelet/bubbletea" | ||
import "github.com/charmbracelet/bubbles/key" | ||
|
||
func (a Application) isQuitKeyMap( | ||
msg tea.KeyMsg, | ||
) bool { | ||
switch msg.String() { | ||
case "ctrl+c", "f10": | ||
return true | ||
default: | ||
return false | ||
} | ||
} | ||
|
||
func (a Application) isEnterKeyMap(msg tea.KeyMsg) bool { | ||
return msg.String() == "enter" | ||
} | ||
|
||
func (a Application) isArrowUpKeyMap(msg tea.KeyMsg) bool { | ||
return msg.Type == tea.KeyUp | ||
type KeyMap struct { | ||
Exit key.Binding | ||
Back key.Binding | ||
ToggleView key.Binding | ||
ToggleViewArrow key.Binding | ||
Up key.Binding | ||
Down key.Binding | ||
Filter key.Binding | ||
} | ||
|
||
func (a Application) isArrowRightKeyMap(msg tea.KeyMsg) bool { | ||
return msg.Type == tea.KeyRight | ||
var defaultKeys = KeyMap{ | ||
Exit: key.NewBinding( | ||
key.WithKeys("ctrl+c", "f10"), | ||
key.WithHelp("Ctrl+C", "Exit"), | ||
), | ||
Back: key.NewBinding( | ||
key.WithKeys("esc", "q"), | ||
key.WithHelp("Esc", "Back"), | ||
), | ||
ToggleView: key.NewBinding( | ||
key.WithKeys("enter"), | ||
key.WithHelp("Enter", "Open/Hide"), | ||
), | ||
ToggleViewArrow: key.NewBinding( | ||
key.WithKeys("right"), | ||
), | ||
Up: key.NewBinding( | ||
key.WithKeys("up"), | ||
key.WithHelp("↑", "Up"), | ||
), | ||
Down: key.NewBinding( | ||
key.WithKeys("down"), | ||
key.WithHelp("↓", "Down"), | ||
), | ||
Filter: key.NewBinding( | ||
key.WithKeys("f"), | ||
key.WithHelp("F", "Filter"), | ||
), | ||
} | ||
|
||
func (a Application) isFilterKeyMap(msg tea.KeyMsg) bool { | ||
return msg.String() == "f" | ||
func (k KeyMap) ShortHelp() []key.Binding { | ||
return []key.Binding{k.Exit, k.Back, k.ToggleView, k.Up, k.Down, k.Filter} | ||
} | ||
|
||
func (a Application) isBackKeyMap(msg tea.KeyMsg) bool { | ||
switch msg.String() { | ||
case "esc", "q": | ||
return true | ||
default: | ||
return false | ||
func (k KeyMap) FullHelp() [][]key.Binding { | ||
return [][]key.Binding{ | ||
{k.Back, k.Up, k.Down}, // first column | ||
{k.ToggleView, k.Exit, k.Filter}, // second column | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.