summaryrefslogtreecommitdiff
path: root/keyboard/ergodox_ez/keymaps/german-manuneo/compile_keymap.py
diff options
context:
space:
mode:
authorErez Zukerman <bulk@ezuk.org>2016-04-04 08:04:31 +0300
committerErez Zukerman <bulk@ezuk.org>2016-04-04 08:04:31 +0300
commit0cdf5d292c36ba61030f96461369e057fb35cd43 (patch)
treec3c0e264e2d37e1a303298cfed4326f151537046 /keyboard/ergodox_ez/keymaps/german-manuneo/compile_keymap.py
parenta90d68739a29debe93bdf9e26f2c126e8eca46e9 (diff)
parent22691de580da46c09ba9024f9543e43e115ce2b6 (diff)
Merge pull request #235 from mbarkhau/master
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.py37
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"