aboutsummaryrefslogtreecommitdiffstats
path: root/keyboards/gboards/combos/_generator/main.go
diff options
context:
space:
mode:
authorGravatar Jeremy Bernhardt <jeremythegeek@gmail.com>2020-05-04 10:49:47 -0600
committerGravatar GitHub <noreply@github.com>2020-05-04 12:49:47 -0400
commit15e84f79f177d92e0faeb5e424a48506489eb955 (patch)
tree8936f6087b900274928107b4fbf27a3bba149d92 /keyboards/gboards/combos/_generator/main.go
parent6f30b402a285ddecce9b6f5b002a649f775225d2 (diff)
downloadqmk_firmware-15e84f79f177d92e0faeb5e424a48506489eb955.tar.gz
gBoards Common (#8921)
Co-Authored-By: Drashna Jaelre <drashna@live.com>
Diffstat (limited to 'keyboards/gboards/combos/_generator/main.go')
-rw-r--r--keyboards/gboards/combos/_generator/main.go60
1 files changed, 60 insertions, 0 deletions
diff --git a/keyboards/gboards/combos/_generator/main.go b/keyboards/gboards/combos/_generator/main.go
new file mode 100644
index 000000000..043c8b78c
--- /dev/null
+++ b/keyboards/gboards/combos/_generator/main.go
@@ -0,0 +1,60 @@
+// Package for taking a mapping of words to keys and outputing a
+// combo engine commpatible def
+
+package main
+
+import (
+ "io/ioutil"
+ "fmt"
+ "encoding/json"
+ "os"
+ "sort"
+ "strings"
+ "hash/crc64"
+ //"encoding/base64"
+)
+
+func main() {
+ // Show Usage
+ if len(os.Args) < 3 {
+ fmt.Println("Usage: ./keymap-gen inputfile outfile")
+ fmt.Println("Outputs dict in current dir")
+ return
+ }
+
+ // Read the source
+ data, err := ioutil.ReadFile(os.Args[1])
+ if err != nil {
+ panic(err)
+ }
+
+ // Unbundle Data
+ var FullDict map[string]string
+ var output []string
+ json.Unmarshal(data, &FullDict)
+
+ // Loop over entries and store
+ for i,v := range FullDict {
+ // This checks for colllisions, Generates hash
+ hash := crc64.Checksum([]byte(v), crc64.MakeTable(crc64.ECMA))
+ hashStr := fmt.Sprintf("txt_%x", hash)[:10]
+
+ // Format keys into combo
+ var keys string
+ for _, k := range(v) {
+ keys += fmt.Sprintf("KC_%v, ", string(k))
+
+ }
+ keys = keys[:len(keys)-2]
+
+ // Append to output
+ spacer := strings.Repeat(" ", 15-len(i))
+ output = append(output, fmt.Sprintf("SUBS(%v, %v\"%v\", %v)\n", hashStr, spacer, i, keys))
+ }
+
+
+ sort.Slice(output, func (i,j int) bool {
+ return strings.Count(output[i], " ") > strings.Count(output[j], " ")
+ })
+ ioutil.WriteFile(os.Args[2], []byte(strings.Join(output, "")), 0555)
+}