Skip to content

Commit dcfa0e7

Browse files
committed
fix(layout): generate an image for each layout
The layout name was not appended to the name of the image, so each layout overrode the prior. Closes #7
1 parent 1a05be7 commit dcfa0e7

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

internal/lib/root.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package lib
22

33
import (
4-
"fmt"
54
"image"
65
"image/png"
76
"os"
@@ -29,15 +28,15 @@ func (g *GenerateCmd) Run() error {
2928
}
3029
g.KeyboardName = strings.ReplaceAll(g.KeyboardName, "/", "_")
3130

32-
for _, layout := range keyboardInfo {
31+
for layoutName, layout := range keyboardInfo {
3332
ctx := createContext(&layout)
3433
err := drawLayout(ctx, g.Transparent, layout)
3534
if err != nil {
3635
return err
3736
}
3837

3938
base := ctx.Image()
40-
images[path.Join(g.Output, fmt.Sprintf("%s.png", g.KeyboardName))] = base
39+
images[generateName(g.Output, g.KeyboardName, layoutName, "")] = base
4140

4241
if keymap, ok := parseKeymap(g.File); ok {
4342
for _, layer := range keymap.Device.Keymap.Layers {
@@ -47,7 +46,7 @@ func (g *GenerateCmd) Run() error {
4746
if err != nil {
4847
return err
4948
}
50-
images[path.Join(g.Output, fmt.Sprintf("%s_%s.png", g.KeyboardName, layer.Name))] = ctx.Image()
49+
images[generateName(g.Output, g.KeyboardName, layoutName, layer.Name)] = ctx.Image()
5150
}
5251
}
5352
}
@@ -66,3 +65,14 @@ func (g *GenerateCmd) Run() error {
6665

6766
return nil
6867
}
68+
69+
func generateName(output, name, layout, layer string) string {
70+
file := name
71+
if layout != "LAYOUT" {
72+
file += "_" + strings.ReplaceAll(layout, "LAYOUT_", "")
73+
}
74+
if layer != "" {
75+
file += "_" + layer
76+
}
77+
return path.Join(output, file+".png")
78+
}

0 commit comments

Comments
 (0)