Skip to content

Commit

Permalink
fix crash on layout name length exceeding 20
Browse files Browse the repository at this point in the history
  • Loading branch information
semilin committed Feb 11, 2024
1 parent 4551090 commit c6a4f01
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions globals.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var FingerNames = [8]string{"LP", "LR", "LM", "LI", "RI", "RM", "RR", "RP"}
var Layouts map[string]Layout
var GeneratedFingermap map[Finger][]Pos
var GeneratedFingermatrix map[Pos]Finger
var LongestLayoutName int

var SwapPossibilities []Pos

Expand Down
10 changes: 8 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func runCommand(args []string) {
})

for _, l := range sorted {
spaces := strings.Repeat(".", 20-len(l.name))
spaces := strings.Repeat(".", 1+LongestLayoutName-len(l.name))
fmt.Printf("%s.%s%.2f\n", l.name, spaces, l.score)
}
} else if cmd == "analyze" {
Expand All @@ -232,7 +232,7 @@ func runCommand(args []string) {
})

for _, l := range sorted {
spaces := strings.Repeat(".", 25-len(l.name))
spaces := strings.Repeat(".", 1+LongestLayoutName-len(l.name))
fmt.Printf("%s.%s%d%%\n", l.name, spaces, int(100*optimal/(Score(Layouts[l.name]))))
}
} else if cmd == "interactive" {
Expand Down Expand Up @@ -303,6 +303,12 @@ func main() {
Layouts = make(map[string]Layout)
LoadLayoutDir()

for _, l := range Layouts {
if len(l.Name) > LongestLayoutName {
LongestLayoutName = len(l.Name)
}
}

runCommand(args)
}

Expand Down

0 comments on commit c6a4f01

Please sign in to comment.