Skip to content

Commit

Permalink
feat(readme): update bindings script
Browse files Browse the repository at this point in the history
  • Loading branch information
Nitestack committed Jul 13, 2024
1 parent ea1441e commit bd0a8a9
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions scripts/update_bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,21 @@ def generate_table(bindings):
"mouse:273": "Right Mouse Button",
"mouse_up": "Mouse Wheel Up",
"mouse_down": "Mouse Wheel Down",
"left": "←",
"right": "→",
"up": "↑",
"down": "↓",
}

table_content = "| Modifiers | Key | Description | OS | Flags |\n"
table_content += "| --- | --- | --- | --- | --- |\n"

def change_mod_label(mod):
mod = mod.capitalize() if mod.isalpha() else mod
if mod.lower() in key_labels.keys():
mod = key_labels[mod.lower()]
mod = (
mod.capitalize() if mod.isalpha() and mod.lower() not in key_labels else mod
)

if mod == "Super":
mod = "Win"
Expand All @@ -239,23 +247,29 @@ def change_mod_label(mod):
for binding in bindings:
# Mods
modifiers = (
" + ".join(map(change_mod_label, binding["mods"]))
"<kbd>"
+ ("</kbd> + <kbd>".join(map(change_mod_label, binding["mods"])))
+ "</kbd>"
if len(binding["mods"]) > 0
else "-"
)
# Key
key = re.sub(r"XF86([a-zA-Z0-9]+)", r"\1 Button", binding["key"])
if binding["key"] in key_labels:
key = key_labels[binding["key"]]
key = key.capitalize() if key.isalpha() else key
if binding["key"].lower() in key_labels.keys():
key = key_labels[binding["key"].lower()]
key = (
key.capitalize()
if key.isalpha() and binding["key"].lower() not in key_labels
else key
)

# Optional description
description = binding["description"] if binding["description"] else "-"

# Flags
flags = "`" + "`, `".join(binding["flags"]) + "`" if binding["flags"] else "-"

table_content += f"| {modifiers} | {key} | {description} | `L`{", `W`" if ("has_win" in binding and binding["has_win"] or False) else ""} | {flags} |\n"
table_content += f"| {modifiers} | <kbd>{key}</kbd> | {description} | `L`{", `W`" if ("has_win" in binding and binding["has_win"] or False) else ""} | {flags} |\n"

return table_content.strip()

Expand Down

0 comments on commit bd0a8a9

Please sign in to comment.