diff options
author | Jack Humbert <jack.humb@gmail.com> | 2016-04-05 09:21:49 -0400 |
---|---|---|
committer | Jack Humbert <jack.humb@gmail.com> | 2016-04-05 09:21:49 -0400 |
commit | e1020672ac42a423a16747d2272cd2203bd3f988 (patch) | |
tree | e4261666c13be3406babd9d3541fc7f0c3dce1df /keyboard/ergodox_ez/keymaps/german-manuneo/compile_keymap.py | |
parent | 976d0a327b563ff83d0f7bcee41b2360877bface (diff) | |
parent | 0cdf5d292c36ba61030f96461369e057fb35cd43 (diff) |
Merge branch 'master' of https://github.com/jackhumbert/tmk_keyboard
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" |