summaryrefslogtreecommitdiffstats
path: root/lib/python/qmk/keyboard.py
diff options
context:
space:
mode:
authorRyan <fauxpark@gmail.com>2020-11-02 19:41:01 +1100
committerGitHub <noreply@github.com>2020-11-02 00:41:01 -0800
commite69da2db2c59a8017f0c9dee9933dd508d22b356 (patch)
tree69dbe7f0731199331f6975df2ada13feab09eaeb /lib/python/qmk/keyboard.py
parentdc40f00aafeea148d8998c594c4e414d87ee84a3 (diff)
`qmk info`: Add `--ascii` flag (#10793)
* `qmk info`: Add `--ascii` flag * Fix typo * Force ASCII for Windows/MSYS2 * Make it gooder * Remove redundant windows check * ...And this too * Make pytest work on Windows
Diffstat (limited to 'lib/python/qmk/keyboard.py')
-rw-r--r--lib/python/qmk/keyboard.py37
1 files changed, 29 insertions, 8 deletions
diff --git a/lib/python/qmk/keyboard.py b/lib/python/qmk/keyboard.py
index 9ebb2d77d3..a4c2873757 100644
--- a/lib/python/qmk/keyboard.py
+++ b/lib/python/qmk/keyboard.py
@@ -9,6 +9,25 @@ from glob import glob
from qmk.c_parse import parse_config_h_file
from qmk.makefile import parse_rules_mk_file
+BOX_DRAWING_CHARACTERS = {
+ "unicode": {
+ "tl": "┌",
+ "tr": "┐",
+ "bl": "└",
+ "br": "┘",
+ "v": "│",
+ "h": "─",
+ },
+ "ascii": {
+ "tl": " ",
+ "tr": " ",
+ "bl": "|",
+ "br": "|",
+ "v": "|",
+ "h": "_",
+ },
+}
+
base_path = os.path.join(os.getcwd(), "keyboards") + os.path.sep
@@ -72,10 +91,12 @@ def rules_mk(keyboard):
return rules
-def render_layout(layout_data, key_labels=None):
+def render_layout(layout_data, render_ascii, key_labels=None):
"""Renders a single layout.
"""
textpad = [array('u', ' ' * 200) for x in range(50)]
+ style = 'ascii' if render_ascii else 'unicode'
+ box_chars = BOX_DRAWING_CHARACTERS[style]
for key in layout_data:
x = ceil(key.get('x', 0) * 4)
@@ -97,13 +118,13 @@ def render_layout(layout_data, key_labels=None):
label = label[:label_len]
label_blank = ' ' * label_len
- label_border = '─' * label_len
+ label_border = box_chars['h'] * label_len
label_middle = label + ' '*label_leftover # noqa: yapf insists there be no whitespace around *
- top_line = array('u', '┌' + label_border + '┐')
- lab_line = array('u', '│' + label_middle + '│')
- mid_line = array('u', '│' + label_blank + '│')
- bot_line = array('u', '└' + label_border + "┘")
+ top_line = array('u', box_chars['tl'] + label_border + box_chars['tr'])
+ lab_line = array('u', box_chars['v'] + label_middle + box_chars['v'])
+ mid_line = array('u', box_chars['v'] + label_blank + box_chars['v'])
+ bot_line = array('u', box_chars['bl'] + label_border + box_chars['br'])
textpad[y][x:x + w] = top_line
textpad[y + 1][x:x + w] = lab_line
@@ -119,13 +140,13 @@ def render_layout(layout_data, key_labels=None):
return '\n'.join(lines)
-def render_layouts(info_json):
+def render_layouts(info_json, render_ascii):
"""Renders all the layouts from an `info_json` structure.
"""
layouts = {}
for layout in info_json['layouts']:
layout_data = info_json['layouts'][layout]['layout']
- layouts[layout] = render_layout(layout_data)
+ layouts[layout] = render_layout(layout_data, render_ascii)
return layouts