diff options
Diffstat (limited to 'lib/python/qmk/keyboard.py')
-rw-r--r-- | lib/python/qmk/keyboard.py | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/lib/python/qmk/keyboard.py b/lib/python/qmk/keyboard.py index 9ebb2d77d..a4c287375 100644 --- a/lib/python/qmk/keyboard.py +++ b/lib/python/qmk/keyboard.py | |||
@@ -9,6 +9,25 @@ from glob import glob | |||
9 | from qmk.c_parse import parse_config_h_file | 9 | from qmk.c_parse import parse_config_h_file |
10 | from qmk.makefile import parse_rules_mk_file | 10 | from qmk.makefile import parse_rules_mk_file |
11 | 11 | ||
12 | BOX_DRAWING_CHARACTERS = { | ||
13 | "unicode": { | ||
14 | "tl": "┌", | ||
15 | "tr": "┐", | ||
16 | "bl": "└", | ||
17 | "br": "┘", | ||
18 | "v": "│", | ||
19 | "h": "─", | ||
20 | }, | ||
21 | "ascii": { | ||
22 | "tl": " ", | ||
23 | "tr": " ", | ||
24 | "bl": "|", | ||
25 | "br": "|", | ||
26 | "v": "|", | ||
27 | "h": "_", | ||
28 | }, | ||
29 | } | ||
30 | |||
12 | base_path = os.path.join(os.getcwd(), "keyboards") + os.path.sep | 31 | base_path = os.path.join(os.getcwd(), "keyboards") + os.path.sep |
13 | 32 | ||
14 | 33 | ||
@@ -72,10 +91,12 @@ def rules_mk(keyboard): | |||
72 | return rules | 91 | return rules |
73 | 92 | ||
74 | 93 | ||
75 | def render_layout(layout_data, key_labels=None): | 94 | def render_layout(layout_data, render_ascii, key_labels=None): |
76 | """Renders a single layout. | 95 | """Renders a single layout. |
77 | """ | 96 | """ |
78 | textpad = [array('u', ' ' * 200) for x in range(50)] | 97 | textpad = [array('u', ' ' * 200) for x in range(50)] |
98 | style = 'ascii' if render_ascii else 'unicode' | ||
99 | box_chars = BOX_DRAWING_CHARACTERS[style] | ||
79 | 100 | ||
80 | for key in layout_data: | 101 | for key in layout_data: |
81 | x = ceil(key.get('x', 0) * 4) | 102 | x = ceil(key.get('x', 0) * 4) |
@@ -97,13 +118,13 @@ def render_layout(layout_data, key_labels=None): | |||
97 | label = label[:label_len] | 118 | label = label[:label_len] |
98 | 119 | ||
99 | label_blank = ' ' * label_len | 120 | label_blank = ' ' * label_len |
100 | label_border = '─' * label_len | 121 | label_border = box_chars['h'] * label_len |
101 | label_middle = label + ' '*label_leftover # noqa: yapf insists there be no whitespace around * | 122 | label_middle = label + ' '*label_leftover # noqa: yapf insists there be no whitespace around * |
102 | 123 | ||
103 | top_line = array('u', '┌' + label_border + '┐') | 124 | top_line = array('u', box_chars['tl'] + label_border + box_chars['tr']) |
104 | lab_line = array('u', '│' + label_middle + '│') | 125 | lab_line = array('u', box_chars['v'] + label_middle + box_chars['v']) |
105 | mid_line = array('u', '│' + label_blank + '│') | 126 | mid_line = array('u', box_chars['v'] + label_blank + box_chars['v']) |
106 | bot_line = array('u', '└' + label_border + "┘") | 127 | bot_line = array('u', box_chars['bl'] + label_border + box_chars['br']) |
107 | 128 | ||
108 | textpad[y][x:x + w] = top_line | 129 | textpad[y][x:x + w] = top_line |
109 | textpad[y + 1][x:x + w] = lab_line | 130 | textpad[y + 1][x:x + w] = lab_line |
@@ -119,13 +140,13 @@ def render_layout(layout_data, key_labels=None): | |||
119 | return '\n'.join(lines) | 140 | return '\n'.join(lines) |
120 | 141 | ||
121 | 142 | ||
122 | def render_layouts(info_json): | 143 | def render_layouts(info_json, render_ascii): |
123 | """Renders all the layouts from an `info_json` structure. | 144 | """Renders all the layouts from an `info_json` structure. |
124 | """ | 145 | """ |
125 | layouts = {} | 146 | layouts = {} |
126 | 147 | ||
127 | for layout in info_json['layouts']: | 148 | for layout in info_json['layouts']: |
128 | layout_data = info_json['layouts'][layout]['layout'] | 149 | layout_data = info_json['layouts'][layout]['layout'] |
129 | layouts[layout] = render_layout(layout_data) | 150 | layouts[layout] = render_layout(layout_data, render_ascii) |
130 | 151 | ||
131 | return layouts | 152 | return layouts |