-
Notifications
You must be signed in to change notification settings - Fork 1
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
feat: show help text #138
Merged
Merged
feat: show help text #138
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
326965c
WIP
dbolson 24c1e9a
Add help text to all setup steps
dbolson 6e1a405
Extract keys to their own file
dbolson 6a4e143
Refactor
dbolson 67ba9ad
Refactor
dbolson 501875d
Rename
dbolson a51f09a
Merge branch 'main' into sc-237655/help-text
dbolson fafae39
Refactor
dbolson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package quickstart | ||
|
||
import "github.com/charmbracelet/bubbles/key" | ||
|
||
var ( | ||
BindingBack = key.NewBinding( | ||
key.WithKeys("esc"), | ||
key.WithHelp("esc", "back"), | ||
) | ||
BindingCursorUp = key.NewBinding( | ||
key.WithKeys("up", "k"), | ||
key.WithHelp("↑/k", "up"), | ||
) | ||
BindingCursorDown = key.NewBinding( | ||
key.WithKeys("down", "j"), | ||
key.WithHelp("↓/j", "down"), | ||
) | ||
BindingPrevPage = key.NewBinding( | ||
key.WithKeys("left", "h", "pgup", "b", "u"), | ||
key.WithHelp("←/h/pgup", "prev page"), | ||
) | ||
BindingNextPage = key.NewBinding( | ||
key.WithKeys("right", "l", "pgdown", "f", "d"), | ||
key.WithHelp("→/l/pgdn", "next page"), | ||
) | ||
BindingGoToStart = key.NewBinding( | ||
key.WithKeys("home", "g"), | ||
key.WithHelp("g/home", "go to start"), | ||
) | ||
BindingGoToEnd = key.NewBinding( | ||
key.WithKeys("end", "G"), | ||
key.WithHelp("G/end", "go to end"), | ||
) | ||
BindingShowFullHelp = key.NewBinding( | ||
key.WithKeys("?"), | ||
key.WithHelp("?", "more"), | ||
) | ||
BindingCloseFullHelp = key.NewBinding( | ||
key.WithKeys("?"), | ||
key.WithHelp("?", "close help"), | ||
) | ||
BindingQuit = key.NewBinding( | ||
key.WithKeys("ctrl+c"), | ||
key.WithHelp("ctrl+c", "quit"), | ||
) | ||
) | ||
|
||
// keyMap defines all the possible key presses we would respond to | ||
type keyMap struct { | ||
Back key.Binding | ||
CloseFullHelp key.Binding | ||
CursorDown key.Binding | ||
CursorUp key.Binding | ||
Enter key.Binding | ||
GoToEnd key.Binding | ||
GoToStart key.Binding | ||
NextPage key.Binding | ||
PrevPage key.Binding | ||
Quit key.Binding | ||
ShowFullHelp key.Binding | ||
Tab key.Binding | ||
} | ||
|
||
func (k keyMap) FullHelp() [][]key.Binding { | ||
return [][]key.Binding{ | ||
{k.CursorUp, k.CursorDown, k.PrevPage, k.NextPage}, | ||
{k.Back, k.Quit, k.CloseFullHelp}, | ||
} | ||
} | ||
|
||
func (k keyMap) ShortHelp() []key.Binding { | ||
return []key.Binding{k.Back, k.Quit, k.ShowFullHelp} | ||
} | ||
|
||
// pressableKeys are the possible key presses we support for all steps. | ||
// We don't necessarily want to show these in the help text, but we want to handle them when | ||
// pressed. | ||
var pressableKeys = keyMap{ | ||
Back: key.NewBinding( | ||
key.WithKeys("esc"), | ||
key.WithHelp("esc", "go back"), | ||
), | ||
Enter: key.NewBinding( | ||
key.WithKeys("enter"), | ||
key.WithHelp("enter", "select"), | ||
), | ||
Quit: key.NewBinding( | ||
key.WithKeys("ctrl+c"), | ||
key.WithHelp("ctrl+c", "quit"), | ||
), | ||
Tab: key.NewBinding( | ||
key.WithKeys("tab"), | ||
key.WithHelp("tab", "toggle"), | ||
), | ||
} |
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pattern here is to have each model define the help keys it shows. These are separate from the keys we handle when they're pressed since we don't necessarily want to show, eg. tab in the help text of the toggle flag model.