Skip to content

Commit

Permalink
Merge pull request #962 from Textualize/binding-tuple-fix
Browse files Browse the repository at this point in the history
Fix bindings as tuples
  • Loading branch information
willmcgugan authored Oct 19, 2022
2 parents 48d59bb + f28cfec commit b18842b
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions src/textual/binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,28 @@ class Bindings:
def __init__(self, bindings: Iterable[BindingType] | None = None) -> None:
def make_bindings(bindings: Iterable[BindingType]) -> Iterable[Binding]:
for binding in bindings:
if isinstance(binding, Binding):
binding_keys = binding.key.split(",")
if len(binding_keys) > 1:
for key in binding_keys:
new_binding = Binding(
key=key,
action=binding.action,
description=binding.description,
show=binding.show,
key_display=binding.key_display,
universal=binding.universal,
)
yield new_binding
else:
yield binding
else:
# If it's a tuple of length 3, convert into a Binding first
if isinstance(binding, tuple):
if len(binding) != 3:
raise BindingError(
f"BINDINGS must contain a tuple of three strings, not {binding!r}"
)
yield Binding(*binding)
binding = Binding(*binding)

binding_keys = binding.key.split(",")
if len(binding_keys) > 1:
for key in binding_keys:
new_binding = Binding(
key=key,
action=binding.action,
description=binding.description,
show=binding.show,
key_display=binding.key_display,
universal=binding.universal,
)
yield new_binding
else:
yield binding

self.keys: MutableMapping[str, Binding] = (
{binding.key: binding for binding in make_bindings(bindings)}
Expand Down

0 comments on commit b18842b

Please sign in to comment.