Skip to content
This repository has been archived by the owner on Aug 30, 2024. It is now read-only.

Commit

Permalink
handle pipes
Browse files Browse the repository at this point in the history
  • Loading branch information
abs3ntdev committed Jan 4, 2023
1 parent 8cccf39 commit 6ce981d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
13 changes: 7 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"path/filepath"
"runtime/debug"
"strings"

"github.com/pborman/getopt"

Expand Down Expand Up @@ -59,8 +60,8 @@ func main() {
func markdownHandler(configValues *reader.ConfigValues, flags *flags.Flags) error {
md := keybindsToMarkdown(configValues.KeyboardBinds, configValues.MouseBinds)
out := ""
out += "| Keybind | Dispatcher | Command |\n"
out += "|---------|------------|---------|\n"
out += "| Keybind | Dispatcher | Command | Comments |\n"
out += "|---------|------------|---------|----------|\n"
for _, row := range md {
out += row + "\n"
}
Expand Down Expand Up @@ -92,10 +93,10 @@ func jsonHandler(configValues *reader.ConfigValues, flags *flags.Flags) error {
func rawHandler(configValues *reader.ConfigValues, flags *flags.Flags) error {
out := ""
for _, bind := range configValues.KeyboardBinds {
out += fmt.Sprintf("%s = %s %s %s", bind.BindType, bind.Bind, bind.Dispatcher, bind.Command) + "\n"
out += fmt.Sprintf("%s = %s %s %s #%s", bind.BindType, bind.Bind, bind.Dispatcher, bind.Command, bind.Comments) + "\n"
}
for _, bind := range configValues.MouseBinds {
out += fmt.Sprintf("%s = %s %s %s", bind.BindType, bind.Bind, bind.Dispatcher, bind.Command) + "\n"
out += fmt.Sprintf("%s = %s %s %s #%s", bind.BindType, bind.Bind, bind.Dispatcher, bind.Command, bind.Comments) + "\n"
}
for _, val := range configValues.Settings {
out += val.Name + " {" + "\n"
Expand Down Expand Up @@ -125,10 +126,10 @@ func rawHandler(configValues *reader.ConfigValues, flags *flags.Flags) error {
func keybindsToMarkdown(kbKeybinds, mKeybinds []*reader.Keybind) []string {
var markdown []string
for _, keybind := range kbKeybinds {
markdown = append(markdown, "| <kbd>"+keybind.Bind+"</kbd> | "+keybind.Dispatcher+" | "+keybind.Command+" |")
markdown = append(markdown, "| <kbd>"+keybind.Bind+"</kbd> | "+keybind.Dispatcher+" | "+strings.ReplaceAll(keybind.Command, "|", "\\|")+" | "+strings.ReplaceAll(keybind.Comments, "|", "\\|")+" |")
}
for _, keybind := range mKeybinds {
markdown = append(markdown, "| <kbd>"+keybind.Bind+"</kbd> | "+keybind.Dispatcher+" | "+keybind.Command+" |")
markdown = append(markdown, "| <kbd>"+keybind.Bind+"</kbd> | "+keybind.Dispatcher+" | "+strings.ReplaceAll(keybind.Command, "|", "\\|")+" |")
}
return markdown
}
15 changes: 15 additions & 0 deletions reader/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,21 @@ func makeBind(bind string) *Keybind {
keyBind.Bind = fmt.Sprintf("%s %s", keybindSlice[0], keybindSlice[1])
}

lastString := keybindSlice[3]
// comment handler
if keybindSlice[3] == "" {
lastString = keybindSlice[2]
}
comments := strings.SplitN(lastString, "#", 2)
if len(comments) > 1 {
lastString = comments[0]
keyBind.Comments = strings.TrimSpace(comments[1])
}
if keybindSlice[3] == "" {
keyBind.Dispatcher = lastString
} else {
keyBind.Command = lastString
}
return keyBind
}

Expand Down

0 comments on commit 6ce981d

Please sign in to comment.