diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2024-01-04 13:17:45 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2024-01-28 08:12:01 +1100 |
commit | 0aa6109d4d767cf77d4fb3eeefd0ac477d718ccf (patch) | |
tree | 57f329144b24ff1bfd67a3c82c7c192b175e9c3c /pkg/cheatsheet | |
parent | cb1b13e95e09232cced846d167dae6cb21ba696e (diff) |
Render keybinding cheatsheet as markdown table
We're going to be adding tooltips to the cheatsheet to better explain what each actions
does. As such, we're switching to a table format rather than a list.
I'm also changing how the keys are represented, using a markdown approach rather than
an html approach
Diffstat (limited to 'pkg/cheatsheet')
-rw-r--r-- | pkg/cheatsheet/generate.go | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/pkg/cheatsheet/generate.go b/pkg/cheatsheet/generate.go index 205abf7cb..27667e686 100644 --- a/pkg/cheatsheet/generate.go +++ b/pkg/cheatsheet/generate.go @@ -14,7 +14,6 @@ import ( "fmt" "log" "os" - "strings" "github.com/jesseduffield/generics/maps" "github.com/jesseduffield/lazycore/pkg/utils" @@ -191,11 +190,11 @@ func formatSections(tr *i18n.TranslationSet, bindingSections []*bindingSection) for _, section := range bindingSections { content += formatTitle(section.title) - content += "<pre>\n" + content += "| Key | Action | Info |\n" + content += "|-----|--------|-------------|\n" for _, binding := range section.bindings { content += formatBinding(binding) } - content += "</pre>\n" } return content @@ -206,19 +205,15 @@ func formatTitle(title string) string { } func formatBinding(binding *types.Binding) string { - result := fmt.Sprintf(" <kbd>%s</kbd>: %s", escapeAngleBrackets(keybindings.LabelFromKey(binding.Key)), binding.Description) + action := keybindings.LabelFromKey(binding.Key) + description := binding.Description if binding.Alternative != "" { - result += fmt.Sprintf(" (%s)", binding.Alternative) + action += fmt.Sprintf(" (%s)", binding.Alternative) } - result += "\n" - return result -} - -func escapeAngleBrackets(str string) string { - result := strings.ReplaceAll(str, ">", ">") - result = strings.ReplaceAll(result, "<", "<") - return result + // Use backticks for keyboard keys. Two backticks are needed with an inner space + // to escape a key that is itself a backtick. + return fmt.Sprintf("| `` %s `` | %s | %s |\n", action, description, binding.Tooltip) } func italicize(str string) string { |