Skip to content

Commit 05a6314

Browse files
committed
Refactor theme selection (add search_themes)
1 parent 8905b66 commit 05a6314

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

src/textual/app.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,12 +1536,7 @@ async def run_callback() -> CallThreadReturnType:
15361536

15371537
def action_change_theme(self) -> None:
15381538
"""An [action](/guide/actions) to change the current theme."""
1539-
self.app.push_screen(
1540-
CommandPalette(
1541-
[ThemeProvider],
1542-
placeholder="Search for themes…",
1543-
),
1544-
)
1539+
self.search_themes()
15451540

15461541
def action_screenshot(
15471542
self, filename: str | None = None, path: str | None = None
@@ -1673,6 +1668,18 @@ def search(
16731668
)
16741669
)
16751670

1671+
def search_themes(self) -> None:
1672+
"""Show a fuzzy search command palette containing all registered themes.
1673+
1674+
Selecting a theme in the list will change the app's theme.
1675+
"""
1676+
self.push_screen(
1677+
CommandPalette(
1678+
providers=[ThemeProvider],
1679+
placeholder="Search for themes…",
1680+
),
1681+
)
1682+
16761683
def bind(
16771684
self,
16781685
keys: str,

src/textual/command.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,9 +342,7 @@ class SimpleCommand(NamedTuple):
342342
"""The description of the command."""
343343

344344

345-
CommandListItem: TypeAlias = (
346-
"SimpleCommand | tuple[str, IgnoreReturnCallbackType, str | None] | tuple[str, IgnoreReturnCallbackType]"
347-
)
345+
CommandListItem: TypeAlias = "SimpleCommand | tuple[str, IgnoreReturnCallbackType, str | None] | tuple[str, IgnoreReturnCallbackType]"
348346

349347

350348
class SimpleProvider(Provider):
@@ -357,7 +355,6 @@ def __init__(
357355
) -> None:
358356
# Convert all commands to SimpleCommand instances
359357
super().__init__(screen, None)
360-
print("setting commands")
361358
self._commands: list[SimpleCommand] = []
362359
for command in commands:
363360
if isinstance(command, SimpleCommand):

0 commit comments

Comments
 (0)