Skip to content

Instantly share code, notes, and snippets.

@zvakanaka
Created October 4, 2024 06:53
Show Gist options
  • Save zvakanaka/798174e2c09a76b99b0e03c43bd3d591 to your computer and use it in GitHub Desktop.
Save zvakanaka/798174e2c09a76b99b0e03c43bd3d591 to your computer and use it in GitHub Desktop.
Untitled
console.clear()
const j = getVil() // JSON.parse(require('fs').readFileSync('./peterxjang-crkbd-3x5_3.vil'))
const getMaxLength = (acc, cur) => {if (cur.length > acc) return cur.length;return acc;}
const maxKcLength = j.layout.flat().flat().reduce(getMaxLength,0)
const nRows = 3
const nCols = 6
const nThumbKeys = 3
const nThumbKeysStickingOut = 1
const layers = j.layout
layers.map((layer, layerIndex) => {
const halfAndThumbRows = layer.map((row, i) => {
const newRow = row.map((kc, j) => `${kc}`.padStart(maxKcLength, ' ')).filter(val => val.trim() !== '-1')
const isRightSide = i > nRows
return (!isRightSide ? newRow : newRow.reverse()).join(`,`)
})
const nRowsIncludingThumb = nRows + (nThumbKeys > 0 ? 1 : 0)
const combinedRows = []
const middlePadding = 3
const nonThumbRowBetweenStr = ''.padStart(maxKcLength * 2 + 2 + middlePadding) // space between the two sides
const thumbRowBetweenStr = ''.padStart(middlePadding)
document.write()
const nShiftOverThumbKeys = nCols - nThumbKeys + nThumbKeysStickingOut // number of keys to skip before showing thumb keys
const preThumbRowStr = ''.padStart(nShiftOverThumbKeys * maxKcLength + nShiftOverThumbKeys)
for (let i = 0; i < nRowsIncludingThumb; i++) {
const isThumbRow = i === (nRowsIncludingThumb - 1)
const nextRowIsThumbRow = i === (nRowsIncludingThumb - 2)
const betweenStr = (!isThumbRow) ? nonThumbRowBetweenStr : thumbRowBetweenStr
const middleBetweenStr = (!isThumbRow && !nextRowIsThumbRow) ? nonThumbRowBetweenStr : thumbRowBetweenStr
const leftBorderCh = i < nRowsIncludingThumb - 1 ? '|' : '\''
const borderOneHalf = Array(nCols + 1 + (nextRowIsThumbRow ? 1 : 0)).fill('+').join(''.padStart(maxKcLength, '-'))
const top = i === 0 ? `${borderOneHalf.replace(/^./, ',').replace(/.$/, '.')}${betweenStr}${borderOneHalf.replace(/^./, ',').replace(/.$/, '.')}\n` : ''
const middle = !isThumbRow ? `${borderOneHalf.replace(/^./, leftBorderCh)}${middleBetweenStr}${borderOneHalf.replace(/^./, leftBorderCh).replace(/.$/, nextRowIsThumbRow ? '\'' : '|')}` : ``
const bottomEachBar = Array(nThumbKeys + 1).fill('+').join(''.padStart(maxKcLength, '-'))
const bottom = isThumbRow ? `${preThumbRowStr}${bottomEachBar.replace(/^./, '`').replace(/.$/, '\'')}${betweenStr}${bottomEachBar.replace(/^./, '`').replace(/.$/, '\'')}` : ''
const combinedRow = `${top} ${isThumbRow ? preThumbRowStr : ''}${halfAndThumbRows[i]},${betweenStr} ${halfAndThumbRows[i + nRowsIncludingThumb]}
${middle}${bottom}`
combinedRows.push(combinedRow)
}
const str = combinedRows.join('\n')
document.write(`<pre>${str}</pre>`)
})
function getVil() {
return {
"version": 1,
"uid": 15126841831861545787,
"layout": [
[
[
"KC_NO",
"KC_Q",
"KC_W",
"KC_E",
"KC_R",
"KC_T"
],
[
"KC_NO",
"KC_A",
"KC_S",
"KC_D",
"KC_F",
"KC_G"
],
[
"KC_NO",
"LSFT_T(KC_Z)",
"KC_X",
"KC_C",
"KC_V",
"KC_B"
],
[
-1,
-1,
-1,
"LALT_T(KC_ESCAPE)",
"LGUI_T(KC_SPACE)",
"LCTL_T(KC_TAB)"
],
[
"KC_NO",
"KC_P",
"KC_O",
"KC_I",
"KC_U",
"KC_Y"
],
[
"KC_NO",
"LT3(KC_QUOTE)",
"KC_L",
"KC_K",
"KC_J",
"KC_H"
],
[
"KC_NO",
"RSFT_T(KC_SLASH)",
"KC_DOT",
"KC_COMMA",
"KC_M",
"KC_N"
],
[
-1,
-1,
-1,
"LT2(KC_BSPACE)",
"LT1(KC_SPACE)",
"ALL_T(KC_ENTER)"
]
],
[
[
"KC_NO",
"KC_1",
"KC_2",
"KC_3",
"KC_4",
"KC_5"
],
[
"KC_NO",
"KC_F1",
"KC_F2",
"KC_F3",
"KC_F4",
"KC_F5"
],
[
"KC_NO",
"LSFT_T(KC_F7)",
"KC_F8",
"KC_F9",
"KC_F10",
"KC_F11"
],
[
-1,
-1,
-1,
"KC_TRNS",
"KC_TRNS",
"KC_TRNS"
],
[
"KC_NO",
"KC_0",
"KC_9",
"KC_8",
"KC_7",
"KC_6"
],
[
"KC_NO",
"KC_SCOLON",
"KC_GRAVE",
"KC_EQUAL",
"KC_MINUS",
"KC_F7"
],
[
"KC_NO",
"RSFT_T(KC_BSLASH)",
"KC_RBRACKET",
"KC_LBRACKET",
"KC_TRNS",
"KC_F12"
],
[
-1,
-1,
-1,
"KC_TRNS",
"KC_TRNS",
"KC_TRNS"
]
],
[
[
"KC_NO",
"KC_TRNS",
"KC_TRNS",
"KC_MS_U",
"KC_BTN3",
"KC_TRNS"
],
[
"KC_NO",
"KC_BTN1",
"KC_MS_L",
"KC_MS_D",
"KC_MS_R",
"KC_BTN2"
],
[
"KC_NO",
"KC_TRNS",
"KC_MPRV",
"KC_MSTP",
"KC_MPLY",
"KC_MNXT"
],
[
-1,
-1,
-1,
"KC_TRNS",
"KC_TRNS",
"KC_TRNS"
],
[
"KC_NO",
"RESET",
"KC_PGUP",
"KC_PGDOWN",
"KC_END",
"KC_HOME"
],
[
"KC_NO",
"KC_TRNS",
"KC_RIGHT",
"KC_UP",
"KC_DOWN",
"KC_LEFT"
],
[
"KC_NO",
"KC_TRNS",
"KC_VOLU",
"KC_VOLD",
"KC_BRIU",
"KC_BRID"
],
[
-1,
-1,
-1,
"KC_TRNS",
"KC_TRNS",
"KC_TRNS"
]
],
[
[
"KC_NO",
"KC_NO",
"KC_NO",
"KC_NO",
"KC_NO",
"KC_NO"
],
[
"KC_NO",
"KC_NO",
"KC_NO",
"KC_NO",
"KC_NO",
"KC_NO"
],
[
"KC_NO",
"KC_NO",
"KC_NO",
"KC_NO",
"KC_NO",
"KC_NO"
],
[
-1,
-1,
-1,
"KC_NO",
"KC_NO",
"KC_NO"
],
[
"KC_NO",
"KC_NO",
"KC_NO",
"KC_NO",
"DYN_MACRO_PLAY1",
"DYN_REC_START1"
],
[
"KC_NO",
"KC_NO",
"KC_NO",
"KC_NO",
"DYN_REC_STOP",
"KC_NO"
],
[
"KC_NO",
"KC_NO",
"KC_NO",
"KC_NO",
"DYN_MACRO_PLAY2",
"DYN_REC_START2"
],
[
-1,
-1,
-1,
"KC_NO",
"KC_NO",
"KC_NO"
]
]
],
"encoder_layout": [
[],
[],
[],
[]
],
"layout_options": -1,
"macro": [
[
[
"down",
"KC_LGUI",
"KC_TAB"
],
[
"up",
"KC_TAB",
"KC_LGUI"
]
],
[
[
"text",
"npm start"
],
[
"tap",
"KC_ENTER"
]
],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[]
],
"vial_protocol": 6,
"via_protocol": 9,
"tap_dance": [
[
"KC_NO",
"KC_NO",
"KC_NO",
"KC_NO",
180
],
[
"KC_NO",
"KC_NO",
"KC_NO",
"KC_NO",
180
],
[
"KC_NO",
"KC_NO",
"KC_NO",
"KC_NO",
180
],
[
"KC_NO",
"KC_NO",
"KC_NO",
"KC_NO",
180
],
[
"KC_NO",
"KC_NO",
"KC_NO",
"KC_NO",
180
],
[
"KC_NO",
"KC_NO",
"KC_NO",
"KC_NO",
180
],
[
"KC_NO",
"KC_NO",
"KC_NO",
"KC_NO",
180
],
[
"KC_NO",
"KC_NO",
"KC_NO",
"KC_NO",
180
]
],
"combo": [],
"key_override": [
{
"trigger": "KC_NO",
"replacement": "KC_NO",
"layers": 65535,
"trigger_mods": 0,
"negative_mod_mask": 0,
"suppressed_mods": 0,
"options": 7
},
{
"trigger": "KC_NO",
"replacement": "KC_NO",
"layers": 65535,
"trigger_mods": 0,
"negative_mod_mask": 0,
"suppressed_mods": 0,
"options": 7
},
{
"trigger": "KC_NO",
"replacement": "KC_NO",
"layers": 65535,
"trigger_mods": 0,
"negative_mod_mask": 0,
"suppressed_mods": 0,
"options": 7
},
{
"trigger": "KC_NO",
"replacement": "KC_NO",
"layers": 65535,
"trigger_mods": 0,
"negative_mod_mask": 0,
"suppressed_mods": 0,
"options": 7
},
{
"trigger": "KC_NO",
"replacement": "KC_NO",
"layers": 65535,
"trigger_mods": 0,
"negative_mod_mask": 0,
"suppressed_mods": 0,
"options": 7
},
{
"trigger": "KC_NO",
"replacement": "KC_NO",
"layers": 65535,
"trigger_mods": 0,
"negative_mod_mask": 0,
"suppressed_mods": 0,
"options": 7
},
{
"trigger": "KC_NO",
"replacement": "KC_NO",
"layers": 65535,
"trigger_mods": 0,
"negative_mod_mask": 0,
"suppressed_mods": 0,
"options": 7
},
{
"trigger": "KC_NO",
"replacement": "KC_NO",
"layers": 65535,
"trigger_mods": 0,
"negative_mod_mask": 0,
"suppressed_mods": 0,
"options": 7
}
],
"settings": {}
}
}
body {
color: wheat;
background: #013;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment