-
Notifications
You must be signed in to change notification settings - Fork 378
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tui: Work around changes in Textual's bindings API
In Textual 0.61, `App.namespace_bindings` was removed in favor of `Screen.active_bindings`. Update our implementation to work for both, since we still support Textual versions below 0.61. Signed-off-by: Matt Wozniski <mwozniski@bloomberg.net>
- Loading branch information
Showing
4 changed files
with
72 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fix dynamic toggling between descriptions like "Pause" vs "Unpause" or "Show" vs "Hide" in the footer of the live-mode TUI and tree reporter. This was broken by changes introduced in Textual 0.61. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import dataclasses | ||
from typing import Dict | ||
from typing import Tuple | ||
from typing import Union | ||
|
||
from textual import binding | ||
from textual.binding import Binding | ||
from textual.dom import DOMNode | ||
|
||
# In Textual 0.61, `App.namespace_bindings` was removed in favor of | ||
# `Screen.active_bindings`. The two have a slightly different interface: | ||
# a 2 item `tuple` was updated to a 3 item `namedtuple`. | ||
# The `Bindings` type alias shows the two possible structures. | ||
# The `update_key_description` implementation works for both, | ||
# since we still support Textual versions below 0.61. | ||
|
||
Bindings = Union[Dict[str, "binding.ActiveBinding"], Dict[str, Tuple[DOMNode, Binding]]] | ||
|
||
|
||
def update_key_description(bindings: Bindings, key: str, description: str) -> None: | ||
val = bindings[key] | ||
binding = dataclasses.replace(val[1], description=description) | ||
if type(val) is tuple: | ||
bindings[key] = val[:1] + (binding,) + val[2:] # type: ignore | ||
else: | ||
bindings[key] = val._replace(binding=binding) # type: ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters