feat: use CP437 character (#5)

* chore: no need unicode, only codepage 437

https://popey.com/blog/2023/09/codepage-437-aesthetic/

* qmkasciigen: clean up

* qmkasciigen: add cp437 chars

* chore: fixed go run

* feat: draw using cp437

* qmkasciigen: make cp437 default

* chore: update TODO

* qmkasciigen: more docs
main
sudo pacman -Syu 2023-09-09 16:53:39 +07:00 committed by GitHub
parent 762c22c917
commit d749a58aa1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 238 additions and 64 deletions

View File

@ -21,16 +21,16 @@ go:
draw_qmkasciigen:
$(MAKE) go
go run ./cmd/qmkasciigen/*.go \
go run ./cmd/qmkasciigen \
-qmk-keyboard dztech/dz60rgb_wkl/v2_1 \
-qmk-keymap-file dztech_dz60rgb_wkl/keymaps_json/haunt98/keymap.json \
-out dztech_dz60rgb_wkl/asciiart/haunt98.txt
draw_qmkasciigen_demo:
go run ./cmd/qmkasciigen/*.go -print-out -allow-layers 0 -qmk-keyboard matthewdias/m3n3van
go run ./cmd/qmkasciigen/*.go -print-out -allow-layers 0 -qmk-keyboard matthewdias/minim
go run ./cmd/qmkasciigen/*.go -print-out -allow-layers 0 -qmk-keyboard moondrop/dash75
go run ./cmd/qmkasciigen/*.go -print-out -allow-layers 0 -qmk-keyboard ymdk/id75 -qmk-keymap via
go run ./cmd/qmkasciigen -print-out -allow-layers 0 -qmk-keyboard matthewdias/m3n3van
go run ./cmd/qmkasciigen -print-out -allow-layers 0 -qmk-keyboard matthewdias/minim
go run ./cmd/qmkasciigen -print-out -allow-layers 0 -qmk-keyboard moondrop/dash75
go run ./cmd/qmkasciigen -print-out -allow-layers 0 -qmk-keyboard ymdk/id75 -qmk-keymap via
format_draw_caksoylar_keymap_drawer:
bun upgrade

View File

@ -168,4 +168,4 @@ Copycat QMK features with software.
- [x] Get data directly from qmk
- [x] Split transform keycodes to raw binding/transform (same as
keymap-drawer)
- [ ] Unicode support ?
- [x] Support [Code page 437](https://en.wikipedia.org/wiki/Code_page_437)

91
cmd/qmkasciigen/cp437.go Normal file
View File

@ -0,0 +1,91 @@
package main
// Only get what I want
// https://en.wikipedia.org/wiki/Code_page_437
// Copy from https://github.com/BenLubar/df2014/blob/master/cp437/cp437.go
var (
CP437Raws = []rune("░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀")
)
const (
cp437Empty = " "
cp437Vertical = "│"
cp437VerticalLeft = "┤"
cp437BottomVerticalLeft = "┐"
cp437TopVerticalRight = "└"
cp437TopVerticalLeftRight = "┴"
cp437BottomVerticalLeftRight = "┬"
cp437VerticalRight = "├"
cp437Horizontal = "─"
cp437VerticalLeftRight = "┼"
cp437TopVerticalLeft = "┘"
cp437BottomVerticalRight = "┌"
)
var (
// 0 exist 1 not exist
// left right top bottom
cp437EmptyB = 0b0000
cp437VerticalB = 0b0011
cp437VerticalLeftB = 0b1011
cp437BottomVerticalLeftB = 0b1001
cp437TopVerticalRightB = 0b0110
cp437TopVerticalLeftRightB = 0b1110
cp437BottomVerticalLeftRightB = 0b1101
cp437VerticalRightB = 0b0111
cp437HorizontalB = 0b1100
cp437VerticalLeftRightB = 0b1111
cp437TopVerticalLeftB = 0b1010
cp437BottomVerticalRightB = 0b0101
)
var cp437Str2B = map[string]int{
cp437Empty: cp437EmptyB,
cp437Vertical: cp437VerticalB,
cp437VerticalLeft: cp437VerticalLeftB,
cp437BottomVerticalLeft: cp437BottomVerticalLeftB,
cp437TopVerticalRight: cp437TopVerticalRightB,
cp437TopVerticalLeftRight: cp437TopVerticalLeftRightB,
cp437BottomVerticalLeftRight: cp437BottomVerticalLeftRightB,
cp437VerticalRight: cp437VerticalRightB,
cp437Horizontal: cp437HorizontalB,
cp437VerticalLeftRight: cp437VerticalLeftRightB,
cp437TopVerticalLeft: cp437TopVerticalLeftB,
cp437BottomVerticalRight: cp437BottomVerticalRightB,
}
var cp437B2Str = map[int]string{
cp437EmptyB: cp437Empty,
cp437VerticalB: cp437Vertical,
cp437VerticalLeftB: cp437VerticalLeft,
cp437BottomVerticalLeftB: cp437BottomVerticalLeft,
cp437TopVerticalRightB: cp437TopVerticalRight,
cp437TopVerticalLeftRightB: cp437TopVerticalLeftRight,
cp437BottomVerticalLeftRightB: cp437BottomVerticalLeftRight,
cp437VerticalRightB: cp437VerticalRight,
cp437HorizontalB: cp437Horizontal,
cp437VerticalLeftRightB: cp437VerticalLeftRight,
cp437TopVerticalLeftB: cp437TopVerticalLeft,
cp437BottomVerticalRightB: cp437BottomVerticalRight,
}
// Return x + y with combine rule
func cp437Plus(x, y string) string {
bx, ok := cp437Str2B[x]
if !ok {
return y
}
by, ok := cp437Str2B[y]
if !ok {
return x
}
// Use OR because if either one has vertical -> final one has vertical and so on
result, ok := cp437B2Str[bx|by]
if !ok {
return cp437Empty
}
return result
}

View File

@ -0,0 +1,48 @@
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestCP437Plus(t *testing.T) {
tests := []struct {
name string
x string
y string
want string
}{
{
name: "plus empty",
x: cp437Empty,
y: cp437Vertical,
want: cp437Vertical,
},
{
name: "corner top right + corner top left",
x: cp437BottomVerticalLeft,
y: cp437BottomVerticalRight,
want: cp437BottomVerticalLeftRight,
},
{
name: "corner bottom right + corner bottom left",
x: cp437TopVerticalLeft,
y: cp437TopVerticalRight,
want: cp437TopVerticalLeftRight,
},
{
name: "corner top right + corner top left + corner bottom right",
x: cp437BottomVerticalLeftRight,
y: cp437TopVerticalLeft,
want: cp437VerticalLeftRight,
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
got := cp437Plus(tc.x, tc.y)
assert.Equal(t, tc.want, got)
})
}
}

View File

@ -178,7 +178,7 @@ func Draw(
// Padding 1 in the right
table[i] = make([]string, newMaxX+1)
for j := 0; j <= newMaxX; j++ {
table[i][j] = " "
table[i][j] = cp437Empty
}
}
@ -237,23 +237,44 @@ func Draw(
if i == key.NewY || i == key.NewY+key.NewH {
if j == key.NewX || j == key.NewX+key.NewW {
// Draw corner
table[i][j] = "+"
} else if table[i][j] != "+" {
// Draw top/bottom
table[i][j] = "-"
var temp string
if i == key.NewY {
if j == key.NewX {
// Corner top left
temp = cp437BottomVerticalRight
} else {
// Corner top right
temp = cp437BottomVerticalLeft
}
} else {
if j == key.NewX {
// Corner bottom left
temp = cp437TopVerticalRight
} else {
// Corner top right
temp = cp437TopVerticalLeft
}
}
// Need to combine with current
table[i][j] = cp437Plus(table[i][j], temp)
} else {
// Draw horizontal
table[i][j] = cp437Plus(table[i][j], cp437Horizontal)
}
} else if i == key.NewY+key.NewH/2 {
// Write key in the middle
if j == key.NewX || j == key.NewX+key.NewW {
// Draw left/right
table[i][j] = "|"
// Draw vertical most left/right
table[i][j] = cp437Plus(table[i][j], cp437Vertical)
} else if len(keyStr) > 0 && j > key.NewX+padding && j < key.NewX+len(keyStr)+padding+1 && j <= key.NewX+key.NewW-padding {
// Only handle ASCII keyStr
table[i][j] = string(keyStr[j-key.NewX-padding-1])
}
} else {
// Draw vertical most left/right
if j == key.NewX || j == key.NewX+key.NewW {
table[i][j] = "|"
table[i][j] = cp437Plus(table[i][j], cp437Vertical)
}
}
}

View File

@ -1,10 +1,5 @@
package main
const (
DefaultQMKW = 1
DefaultQMKH = 1
)
// https://github.com/qmk/qmk_firmware/blob/master/docs/reference_info_json.md
type QMKInfo struct {
Layouts map[string]map[string][]QMKKeyDictionary `json:"layouts"`

View File

@ -1,47 +1,47 @@
+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+
| GESC | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | - | = | \ | ` |
+-------+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+-------+
| TAB | Q | W | E | R | T | Y | U | I | O | P | [ | ] | BACKSPACE |
+-----------+-+-----+-+-----+-+-----+-+-----+-+-----+-+-----+-+-----+-+-----+-+-----+-+-----+-+-----+-+-----+-----------+
| ESC CTRL | A | S | D | F | G | H | J | K | L | ; | ' | ENTER |
+-------------+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---------+-------+
| ( SHIFT | Z | X | C | V | B | N | M | , | . | / | ) SHIFT | L1 |
+-----------+-----+-+-----+-----+-+-------+-------+-------+-------+-------+-------+-----+-+-------+-+-------+---+-------+
| | OPT | CMD | SPACE | CMD | L2 | |
+-----------+-------+-----------+-------------------------------------------------------+-----------+-------+-----------+
┌───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┐
│ GESC │ 1 │ 2 │ 3 │ 4 │ 5 │ 6 │ 7 │ 8 │ 9 │ 0 │ - │ = │ \ │ ` │
├───────┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───────┤
│ TAB │ Q │ W │ E │ R │ T │ Y │ U │ I │ O │ P │ [ │ ] │ BACKSPACE │
├───────────┴─┬─────┴─┬─────┴─┬─────┴─┬─────┴─┬─────┴─┬─────┴─┬─────┴─┬─────┴─┬─────┴─┬─────┴─┬─────┴─┬─────┴───────────┤
│ ESC CTRL │ A │ S │ D │ F │ G │ H │ J │ K │ L │ ; │ ' │ ENTER │
├─────────────┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴─────────┬───────┤
│ ( SHIFT │ Z │ X │ C │ V │ B │ N │ M │ , │ . │ / │ ) SHIFT │ L1 │
├───────────┬─────┴─┬─────┴─────┬─┴───────┴───────┴───────┴───────┴───────┴───────┴─────┬─┴───────┴─┬───────┬───┴───────┤
│ │ OPT │ CMD │ SPACE │ CMD │ L2 │ │
└───────────┴───────┴───────────┴───────────────────────────────────────────────────────┴───────────┴───────┴───────────┘
+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+
| ` | F1 | F2 | F3 | F4 | F5 | F6 | F7 | F8 | F9 | F10 | F11 | F12 | | |
+-------+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+-------+
| | | | | | | | | | | | UP | | DEL |
+-----------+-+-----+-+-----+-+-----+-+-----+-+-----+-+-----+-+-----+-+-----+-+-----+-+-----+-+-----+-+-----+-----------+
| | | | | | | | | | | LEFT | RGHT | |
+-------------+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---------+-------+
| | | | | | | | | | | DOWN | | |
+-----------+-----+-+-----+-----+-+-------+-------+-------+-------+-------+-------+-----+-+-------+-+-------+---+-------+
| | | | | | L3 | |
+-----------+-------+-----------+-------------------------------------------------------+-----------+-------+-----------+
┌───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┐
│ ` │ F1 │ F2 │ F3 │ F4 │ F5 │ F6 │ F7 │ F8 │ F9 │ F10 │ F11 │ F12 │ │ │
├───────┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───────┤
│ │ │ │ │ │ │ │ │ │ │ │ UP │ │ DEL │
├───────────┴─┬─────┴─┬─────┴─┬─────┴─┬─────┴─┬─────┴─┬─────┴─┬─────┴─┬─────┴─┬─────┴─┬─────┴─┬─────┴─┬─────┴───────────┤
│ │ │ │ │ │ │ │ │ │ │ LEFT │ RGHT │ │
├─────────────┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴─────────┬───────┤
│ │ │ │ │ │ │ │ │ │ │ DOWN │ │ │
├───────────┬─────┴─┬─────┴─────┬─┴───────┴───────┴───────┴───────┴───────┴───────┴─────┬─┴───────┴─┬───────┬───┴───────┤
│ │ │ │ │ │ L3 │ │
└───────────┴───────┴───────────┴───────────────────────────────────────────────────────┴───────────┴───────┴───────────┘
+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+
| | | | | | | | | | | | | | | |
+-------+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+-------+
| | BRMD | BRMU | | | | | | | | | | | |
+-----------+-+-----+-+-----+-+-----+-+-----+-+-----+-+-----+-+-----+-+-----+-+-----+-+-----+-+-----+-+-----+-----------+
| CAPSLOCK | VOLD | VOLU | MUTE | | | | | | | | | |
+-------------+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---------+-------+
| | RGBH | RGBS | RGBV | | | | | | | | | L3 |
+-----------+-----+-+-----+-----+-+-------+-------+-------+-------+-------+-------+-----+-+-------+-+-------+---+-------+
| | RGBTO | RGBMO | | | | |
+-----------+-------+-----------+-------------------------------------------------------+-----------+-------+-----------+
┌───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┐
│ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
├───────┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───────┤
│ │ BRMD │ BRMU │ │ │ │ │ │ │ │ │ │ │ │
├───────────┴─┬─────┴─┬─────┴─┬─────┴─┬─────┴─┬─────┴─┬─────┴─┬─────┴─┬─────┴─┬─────┴─┬─────┴─┬─────┴─┬─────┴───────────┤
│ CAPSLOCK │ VOLD │ VOLU │ MUTE │ │ │ │ │ │ │ │ │ │
├─────────────┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴─────────┬───────┤
│ │ RGBH │ RGBS │ RGBV │ │ │ │ │ │ │ │ │ L3 │
├───────────┬─────┴─┬─────┴─────┬─┴───────┴───────┴───────┴───────┴───────┴───────┴─────┬─┴───────┴─┬───────┬───┴───────┤
│ │ RGBTO │ RGBMO │ │ │ │ │
└───────────┴───────┴───────────┴───────────────────────────────────────────────────────┴───────────┴───────┴───────────┘
+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+
| BOOT | EECLR | | | | | | | | | | | | | |
+-------+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+-------+
| | | | | | | | | | | | | | |
+-----------+-+-----+-+-----+-+-----+-+-----+-+-----+-+-----+-+-----+-+-----+-+-----+-+-----+-+-----+-+-----+-----------+
| | | | | | | | | | | | | |
+-------------+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---------+-------+
| | | | | | | | | | | | | |
+-----------+-----+-+-----+-----+-+-------+-------+-------+-------+-------+-------+-----+-+-------+-+-------+---+-------+
| | | | | | | |
+-----------+-------+-----------+-------------------------------------------------------+-----------+-------+-----------+
┌───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┐
│ BOOT │ EECLR │ │ │ │ │ │ │ │ │ │ │ │ │ │
├───────┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───────┤
│ │ │ │ │ │ │ │ │ │ │ │ │ │ │
├───────────┴─┬─────┴─┬─────┴─┬─────┴─┬─────┴─┬─────┴─┬─────┴─┬─────┴─┬─────┴─┬─────┴─┬─────┴─┬─────┴─┬─────┴───────────┤
│ │ │ │ │ │ │ │ │ │ │ │ │ │
├─────────────┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴─────────┬───────┤
│ │ │ │ │ │ │ │ │ │ │ │ │ │
├───────────┬─────┴─┬─────┴─────┬─┴───────┴───────┴───────┴───────┴───────┴───────┴─────┬─┴───────┴─┬───────┬───┴───────┤
│ │ │ │ │ │ │ │
└───────────┴───────┴───────────┴───────────────────────────────────────────────────────┴───────────┴───────┴───────────┘

11
go.mod
View File

@ -2,4 +2,13 @@ module github.com/haunt98/qmk_keymaps
go 1.20
require github.com/spf13/cast v1.5.1
require (
github.com/spf13/cast v1.5.1
github.com/stretchr/testify v1.8.4
)
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

10
go.sum
View File

@ -1,7 +1,17 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
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/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
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=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=