diff options
author | Manuel Barkhau <mbarkhau@gmail.com> | 2016-04-03 21:46:32 +0200 |
---|---|---|
committer | Manuel Barkhau <mbarkhau@gmail.com> | 2016-04-03 21:46:32 +0200 |
commit | 22691de580da46c09ba9024f9543e43e115ce2b6 (patch) | |
tree | 992da1318dfa6c77fc41a1bb8fe7e02929df4765 /keyboard/ergodox_ez/keymaps/german-manuneo/compile_keymap.py | |
parent | 381a9fd55319d1f29783748f5d6d5c5820e81636 (diff) |
add indent to generated keymap
Diffstat (limited to 'keyboard/ergodox_ez/keymaps/german-manuneo/compile_keymap.py')
-rw-r--r-- | keyboard/ergodox_ez/keymaps/german-manuneo/compile_keymap.py | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/keyboard/ergodox_ez/keymaps/german-manuneo/compile_keymap.py b/keyboard/ergodox_ez/keymaps/german-manuneo/compile_keymap.py index 3d26672762..7076a6ecb2 100644 --- a/keyboard/ergodox_ez/keymaps/german-manuneo/compile_keymap.py +++ b/keyboard/ergodox_ez/keymaps/german-manuneo/compile_keymap.py @@ -43,6 +43,9 @@ KEYBOARD_LAYOUTS = { ] } +ROW_INDENTS = { + 'ergodox_ez': [0, 0, 0, 0, 0, 1, 0, 0, 0, 2, 5, 0, 6, 0, 4, 0] +} BLANK_LAYOUTS = [ # Compact Layout @@ -591,16 +594,43 @@ def unicode_macro_cases(config): ) -def iter_keymap_lines(keymap): +def iter_keymap_lines(keymap, row_indents=None): + col_widths = {} + col = 0 + # first pass, figure out the column widths + prev_row_index = None + for code, row_index in keymap.values(): + if row_index != prev_row_index: + col = 0 + if row_indents: + col = row_indents[row_index] + col_widths[col] = max(len(code), col_widths.get(col, 0)) + prev_row_index = row_index + col += 1 + + # second pass, yield the cell values + col = 0 prev_row_index = None for key_index in sorted(keymap): code, row_index = keymap[key_index] if row_index != prev_row_index: + col = 0 yield "\n" + if row_indents: + for indent_col in range(row_indents[row_index]): + pad = " " * (col_widths[indent_col] - 4) + yield (" /*-*/" + pad) + col = row_indents[row_index] + else: + yield pad yield " {}".format(code) if key_index < len(keymap) - 1: yield "," + # This will be yielded on the next iteration when + # we know that we're not at the end of a line. + pad = " " * (col_widths[col] - len(code)) prev_row_index = row_index + col += 1 def iter_keymap_parts(config, keymaps): @@ -628,11 +658,12 @@ def iter_keymap_parts(config, keymaps): # comment layer_lines = config['layer_lines'][layer_name] prefixed_lines = " * " + " * ".join(layer_lines) - yield "/*\n{}*/\n".format(prefixed_lines) + yield "/*\n{} */\n".format(prefixed_lines) # keymap codes keymap = keymaps[layer_name] - keymap_lines = "".join(iter_keymap_lines(keymap)) + row_indents = ROW_INDENTS.get(config['layout']) + keymap_lines = "".join(iter_keymap_lines(keymap, row_indents)) yield "[L{0}] = KEYMAP({1}\n),\n".format(i, keymap_lines) yield "};\n\n" |