Layout images generator

This commit is contained in:
He4eT 2021-08-03 11:52:59 +05:00 committed by Alexey
commit 4894240006
4 changed files with 182 additions and 0 deletions

View file

@ -21,3 +21,15 @@ flash:
@make keymap_copy
@make qmk_flash
@make keymap_clean
preview_cmd = node \
./preview_generator/preview_generator.js \
"${PWD}/keymap/keymap.c"
preview:
@${preview_cmd}
preview_and_copy:
@${preview_cmd} | xclip -sel clipboard
@echo 'Copied to the clipboard! Paste it in the "Raw data" tab:'
@echo 'http://www.keyboard-layout-editor.com/'

View file

@ -0,0 +1,113 @@
const legends = {
'NO': '',
'TRNS': '▽',
'MO(1': 'FN1',
'MO(2': 'Mouse\nmode',
'GRV': '~\n`',
'1': '!\n1',
'2': '@\n2',
'3': '#\n3',
'4': '$\n4',
'5': '%\n5',
'6': '^\n6',
'7': '&\n7',
'8': '*\n8',
'9': '(\n9',
'0': ')\n0',
'MINS': '_\n',
'EQL': '+\n=',
'SLSH': '?\n/',
'BSLS': '|\n\\',
'LBRC': '{\n[',
'RBRC': '}\n]',
'SCLN': ':\n;',
'QUOT': '"\n\'',
'COMM': '<\n,',
'DOT': '>\n.',
'GT': '>',
'LT': '<',
'LPRN': '(',
'RPRN': ')',
'LCBR': '{',
'RCBR': '}',
'PLUS': '+',
'PMNS': '',
'PAST': '*',
'PSLS': '/',
'PEQL': '=',
'UNDS': '_',
'ESC': 'Esc',
'ENT': 'Enter',
'SPC': 'Space',
'BSPC': 'Back\nSpace',
'TAB': 'Tab',
'LCTRL': 'Ctrl',
'RCTRL': 'Ctrl',
'LALT': 'Alt',
'RALT': 'Alt',
'LSFT': 'Shift',
'RSFT': 'Shift',
'LGUI': 'OS',
'RGUI': 'OS',
'LCTL_T(ESC': 'Ctrl\nEsc',
'RCTL_T(ESC': 'Ctrl\nEsc',
'HOME': 'Home',
'INS': 'Insert',
'DEL': 'Delete',
'END': 'End',
'PGDN': 'PgDn',
'PGUP': 'PgUp',
'PAUS': 'Pause',
'PSCR': 'PrScr',
'APP': 'Menu',
'LEFT': 'Left',
'DOWN': 'Down',
'RGHT': 'Right',
'UP': 'Up',
'MUTE': 'Mute',
'VOLD': 'Vol +',
'VOLU': 'Vol ',
'ACL0': 'Slow',
'ACL1': 'Usual',
'ACL2': 'Fast',
'BTN1': 'Click',
'BTN2': 'Mouse\n2',
'BTN3': 'Mouse\n3',
'BTN4': 'Mouse\n4',
'BTN5': 'Mouse\n5',
'MS_D': 'Mouse\nDown',
'MS_L': 'Mouse\nLeft',
'MS_R': 'Mouse\nRight',
'MS_U': 'Mouse\nUp',
'WH_D': 'Wheel\ndown',
'WH_U': 'Wheel\nup',
}
const cleanKeys = keys => keys
.map(key => key
.replaceAll(')', '')
.trim())
.filter(Boolean)
const printLegends = keys => keys
.map(key => key.replace('KC_', ''))
.map(key => legends[key] ?? key)
.map(key => [{a: key.includes('\n')
? 5 // 2 lines
: 3 // 1 line
}, key])
module.exports = {
cleanKeys,
printLegends
}

View file

@ -0,0 +1,30 @@
/**
* Convert the keymap.c file to the "Raw data" for
* http://www.keyboard-layout-editor.com/
*/
const fs = require('fs')
const {buildRow} = require('./rows')
const {cleanKeys, printLegends} = require('./legends')
const keymapFilePath = process.argv[2]
const fileContent = fs.readFileSync(keymapFilePath, 'utf8')
const keymapToKLERawData = fileContent =>
fileContent
.split('\n')
.map(row => row.split(','))
.filter(key => key.length > 1)
.map(cleanKeys)
.map(printLegends)
.map(buildRow)
.map(JSON.stringify)
const result = keymapToKLERawData(fileContent)
// .slice(0, 8)
// .slice(8, 16)
// .slice(16)
console.log(result.join(',\n'))

27
preview_generator/rows.js Normal file
View file

@ -0,0 +1,27 @@
const HALVES_GAP = 5
const row = (keys, start, gapOffset) => [
{x: start},
...keys.slice(0, keys.length / 2),
{x: HALVES_GAP + gapOffset},
...keys.slice(keys.length / 2),
].flat()
const row12 = keys =>
row(keys, 0, 0)
const row4 = (keys, rowIndex) => ({
4: row(keys, 2, 4),
5: row(keys, 4, 0),
6: row(keys, 6, -4),
7: row(keys, 6, -4),
}[rowIndex % 8])
const buildRow = (keys, rowIndex) => ({
12: row12(keys),
4: row4(keys, rowIndex)
}[keys.length] || ['Oh no...'])
module.exports = {
buildRow
}