feat(qmkasciigen): add flag allow layers
parent
449b9ebd0c
commit
6d61ef927b
|
@ -94,6 +94,7 @@ var mapBindingTiny = []map[string]string{
|
|||
}
|
||||
|
||||
type DrawConfig struct {
|
||||
AllowLayers map[int]struct{}
|
||||
PrintLayout bool
|
||||
PrintLayer bool
|
||||
}
|
||||
|
@ -155,6 +156,14 @@ func Draw(
|
|||
// Each keymap has many layers
|
||||
layersStr := make([]string, 0, len(keymap.Layers))
|
||||
for iLayer, layer := range keymap.Layers {
|
||||
if len(cfg.AllowLayers) > 0 {
|
||||
// Only check if valid
|
||||
if _, ok := cfg.AllowLayers[iLayer]; !ok {
|
||||
// Skip if not in list
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
// PreProcess table with space
|
||||
table := make([][]string, newMaxY+1)
|
||||
for i := 0; i <= newMaxY; i++ {
|
||||
|
|
|
@ -10,6 +10,8 @@ import (
|
|||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -30,6 +32,7 @@ var (
|
|||
flagPrintOutput bool
|
||||
flagPrintLayout bool
|
||||
flagPrintLayer bool
|
||||
flagAllowLayers string
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
@ -42,6 +45,7 @@ func init() {
|
|||
flag.BoolVar(&flagPrintOutput, "print-out", false, "Print output")
|
||||
flag.BoolVar(&flagPrintLayout, "print-layout", false, "Print layout name")
|
||||
flag.BoolVar(&flagPrintLayer, "print-layer", false, "Print layer name")
|
||||
flag.StringVar(&flagAllowLayers, "allow-layers", "", "Allow layers to print aka 0 or 0,2,3. Use , to split. Empty mean all")
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
@ -55,6 +59,19 @@ func main() {
|
|||
log.Printf("flagPrintOutput: [%v]\n", flagPrintOutput)
|
||||
log.Printf("flagPrintLayout: [%v]\n", flagPrintLayout)
|
||||
log.Printf("flagPrintLayer: [%v]\n", flagPrintLayer)
|
||||
log.Printf("flagAllowLayers: [%s]\n", flagAllowLayers)
|
||||
}
|
||||
|
||||
// 0,2,3 -> [0, 2, 3]
|
||||
allowLayers := make(map[int]struct{})
|
||||
for _, l := range strings.Split(flagAllowLayers, ",") {
|
||||
l = strings.TrimSpace(l)
|
||||
if l == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
lInt := cast.ToInt(l)
|
||||
allowLayers[lInt] = struct{}{}
|
||||
}
|
||||
|
||||
qmkInfo, err := wrapGetQMKInfo(flagQMKKeyboard, flagQMKInfoFile, flagDebug)
|
||||
|
@ -71,6 +88,7 @@ func main() {
|
|||
qmkInfo.Layouts,
|
||||
qmkKeymap,
|
||||
DrawConfig{
|
||||
AllowLayers: allowLayers,
|
||||
PrintLayout: flagPrintLayout,
|
||||
PrintLayer: flagPrintLayer,
|
||||
},
|
||||
|
|
2
go.mod
2
go.mod
|
@ -1,3 +1,5 @@
|
|||
module github.com/haunt98/qmk_keymaps
|
||||
|
||||
go 1.20
|
||||
|
||||
require github.com/spf13/cast v1.5.1
|
||||
|
|
7
go.sum
7
go.sum
|
@ -0,0 +1,7 @@
|
|||
github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY=
|
||||
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
||||
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
|
||||
github.com/spf13/cast v1.5.1 h1:R+kOtfhWQE6TVQzY+4D7wJLBgkdVasCEFxSUBYBYIlA=
|
||||
github.com/spf13/cast v1.5.1/go.mod h1:b9PdjNptOpzXr7Rq1q9gJML/2cdGQAo69NKzQ10KN48=
|
Loading…
Reference in New Issue