From 0aa6109d4d767cf77d4fb3eeefd0ac477d718ccf Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Thu, 4 Jan 2024 13:17:45 +1100 Subject: 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 --- pkg/cheatsheet/generate.go | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) (limited to 'pkg/cheatsheet') 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 += "
\n"
+		content += "| Key | Action | Info |\n"
+		content += "|-----|--------|-------------|\n"
 		for _, binding := range section.bindings {
 			content += formatBinding(binding)
 		}
-		content += "
\n" } return content @@ -206,19 +205,15 @@ func formatTitle(title string) string { } func formatBinding(binding *types.Binding) string { - result := fmt.Sprintf(" %s: %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 { -- cgit v1.2.3