Skip to content

Commit 0e9e320

Browse files
authored
Merge pull request #5235 from Textualize/theme-fixes
Theme fixes
2 parents 9f32476 + d942e52 commit 0e9e320

File tree

63 files changed

+3039
-3119
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+3039
-3119
lines changed

docs/guide/design.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ For example, `$secondary-darken-1` is a slightly darkened `$secondary`, and `$er
138138

139139
## Light and dark themes
140140

141-
Themes can be either "light" or "dark".
141+
Themes can be either *light* or *dark*.
142142
This setting is specified in the `Theme` constructor via the `dark` argument, and influences how Textual
143143
generates variables.
144144
Built-in widgets may also use the value of `dark` to influence their appearance.

examples/theme_sandbox.py

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ def action_invalid_theme(self) -> None:
302302
self.theme = "not-a-theme"
303303

304304
def action_widget_search(self) -> None:
305-
self.search(
305+
self.search_commands(
306306
[
307307
(
308308
widget.__class__.__name__,
@@ -363,8 +363,31 @@ def compose(self) -> ComposeResult:
363363

364364
yield Header(show_clock=True, icon="🐟")
365365
yield ThemeList(id="theme-list")
366-
with VerticalScroll(id="widget-list") as container:
367-
container.can_focus = False
366+
with VerticalScroll(id="widget-list", can_focus=False) as container:
367+
yield Switch()
368+
yield ToggleButton(label="Toggle Button")
369+
yield SelectionList[int](
370+
("Falken's Maze", 0, True),
371+
("Black Jack", 1),
372+
("Gin Rummy", 2),
373+
("Hearts", 3),
374+
("Bridge", 4),
375+
("Checkers", 5),
376+
("Chess", 6, True),
377+
("Poker", 7),
378+
("Fighter Combat", 8, True),
379+
)
380+
yield RadioSet(
381+
"Amanda",
382+
"Connor MacLeod",
383+
"Duncan MacLeod",
384+
"Heather MacLeod",
385+
"Joe Dawson",
386+
"Kurgan, [bold italic red]The[/]",
387+
"Methos",
388+
"Rachel Ellenstein",
389+
"Ramírez",
390+
)
368391

369392
yield Select(
370393
[("foo", "foo"), ("bar", "bar"), ("baz", "baz"), ("qux", "qux")]
@@ -459,36 +482,10 @@ def compose(self) -> ComposeResult:
459482
"Virgon",
460483
)
461484

462-
yield Switch()
463-
yield ToggleButton(label="Toggle Button")
464-
465-
yield SelectionList[int](
466-
("Falken's Maze", 0, True),
467-
("Black Jack", 1),
468-
("Gin Rummy", 2),
469-
("Hearts", 3),
470-
("Bridge", 4),
471-
("Checkers", 5),
472-
("Chess", 6, True),
473-
("Poker", 7),
474-
("Fighter Combat", 8, True),
475-
)
476-
yield RadioSet(
477-
"Amanda",
478-
"Connor MacLeod",
479-
"Duncan MacLeod",
480-
"Heather MacLeod",
481-
"Joe Dawson",
482-
"Kurgan, [bold italic red]The[/]",
483-
"Methos",
484-
"Rachel Ellenstein",
485-
"Ramírez",
486-
)
487-
488485
yield Footer()
489486

490487
def on_mount(self) -> None:
491-
self.theme = "textual-ansi"
488+
self.theme = "textual-light"
492489
text_area = self.query_one(TextArea)
493490
text_area.selection = Selection((0, 0), (1, 10))
494491

src/textual/app.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,9 @@ def __init__(
768768
self._css_update_count: int = 0
769769
"""Incremented when CSS is invalidated."""
770770

771+
self.theme_variables: dict[str, str] = {}
772+
"""Variables generated from the current theme."""
773+
771774
if self.ENABLE_COMMAND_PALETTE:
772775
for _key, binding in self._bindings:
773776
if binding.action in {"command_palette", "app.command_palette"}:
@@ -1180,7 +1183,10 @@ def get_css_variables(self) -> dict[str, str]:
11801183
# Apply the additional variables from the theme
11811184
variables = {**variables, **(theme.variables)}
11821185
theme_variables = self.get_theme_variable_defaults()
1183-
return {**theme_variables, **variables}
1186+
1187+
combined_variables = {**theme_variables, **variables}
1188+
self.theme_variables = combined_variables
1189+
return combined_variables
11841190

11851191
def get_theme(self, theme_name: str) -> Theme | None:
11861192
"""Get a theme by name.
@@ -1662,7 +1668,7 @@ def deliver_screenshot(
16621668
name="screenshot",
16631669
)
16641670

1665-
def search(
1671+
def search_commands(
16661672
self,
16671673
commands: Sequence[CommandListItem],
16681674
placeholder: str = "Search for commands…",
@@ -1671,6 +1677,7 @@ def search(
16711677
16721678
Args:
16731679
commands: A list of SimpleCommand instances.
1680+
placeholder: Placeholder text for the search field.
16741681
16751682
Returns:
16761683
AwaitMount: An awaitable that resolves when the commands are shown.

src/textual/command.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ class CommandPalette(SystemModalScreen[None]):
570570
margin-top: 3;
571571
height: 100%;
572572
visibility: hidden;
573-
background: $panel-darken-1;
573+
background: $surface;
574574
}
575575
576576
CommandPalette #--input {

src/textual/drivers/linux_driver.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,6 @@ def on_terminal_resize(signum, stack) -> None:
267267
self.write("\x1b[?25l") # Hide cursor
268268
self.write("\x1b[?1004h") # Enable FocusIn/FocusOut.
269269
self.write("\x1b[>1u") # https://sw.kovidgoyal.net/kitty/keyboard-protocol/
270-
# Disambiguate escape codes https://sw.kovidgoyal.net/kitty/keyboard-protocol/#progressive-enhancement
271-
self.write("\x1b[=1;u")
272270

273271
self.flush()
274272
self._key_thread = Thread(target=self._run_input_thread)

src/textual/theme.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ def to_color_system(self) -> ColorSystem:
7272
error="#ba3c5b",
7373
success="#4EBF71",
7474
foreground="#e0e0e0",
75-
dark=True,
7675
),
7776
"textual-light": Theme(
7877
name="textual-light",
@@ -82,7 +81,13 @@ def to_color_system(self) -> ColorSystem:
8281
warning="#ffa62b",
8382
error="#ba3c5b",
8483
success="#4EBF71",
84+
surface="#D8D8D8",
85+
panel="#D0D0D0",
86+
background="#E0E0E0",
8587
dark=False,
88+
variables={
89+
"footer-key-foreground": "#0178D4",
90+
},
8691
),
8792
"nord": Theme(
8893
name="nord",
@@ -96,7 +101,6 @@ def to_color_system(self) -> ColorSystem:
96101
error="#BF616A",
97102
surface="#3B4252",
98103
panel="#434C5E",
99-
dark=True,
100104
variables={
101105
"block-cursor-background": "#88C0D0",
102106
"block-cursor-foreground": "#2E3440",
@@ -119,7 +123,6 @@ def to_color_system(self) -> ColorSystem:
119123
background="#282828",
120124
surface="#3c3836",
121125
panel="#504945",
122-
dark=True,
123126
variables={
124127
"block-cursor-foreground": "#fbf1c7",
125128
"input-selection-background": "#689d6a40",
@@ -138,7 +141,6 @@ def to_color_system(self) -> ColorSystem:
138141
background="#181825",
139142
surface="#313244",
140143
panel="#45475a",
141-
dark=True,
142144
variables={
143145
"input-cursor-foreground": "#11111b",
144146
"input-cursor-background": "#f5e0dc",
@@ -188,7 +190,6 @@ def to_color_system(self) -> ColorSystem:
188190
surface="#2B2E3B",
189191
panel="#313442",
190192
foreground="#F8F8F2",
191-
dark=True,
192193
variables={
193194
"button-color-foreground": "#282A36",
194195
},
@@ -205,7 +206,6 @@ def to_color_system(self) -> ColorSystem:
205206
background="#1A1B26", # Background
206207
surface="#24283B", # Surface
207208
panel="#414868", # Panel
208-
dark=True,
209209
variables={
210210
"button-color-foreground": "#24283B",
211211
},
@@ -222,7 +222,6 @@ def to_color_system(self) -> ColorSystem:
222222
background="#272822",
223223
surface="#2e2e2e",
224224
panel="#3E3D32",
225-
dark=True,
226225
variables={
227226
"foreground-muted": "#797979",
228227
"input-selection-background": "#575b6190",
@@ -241,7 +240,6 @@ def to_color_system(self) -> ColorSystem:
241240
surface="#1C1B1A", # base.950
242241
panel="#282726", # base.900
243242
foreground="#FFFCF0", # base.paper
244-
dark=True,
245243
variables={
246244
"input-cursor-foreground": "#5E409D",
247245
"input-cursor-background": "#FFFCF0",

src/textual/widgets/_data_table.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ class DataTable(ScrollView, Generic[CellType], can_focus=True):
360360
}
361361
362362
& > .datatable--fixed {
363-
background: $secondary 50%;
363+
background: $secondary-muted;
364364
color: $foreground;
365365
}
366366

src/textual/widgets/_option_list.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,9 @@ class OptionList(ScrollView, can_focus=True):
146146
max-height: 100%;
147147
color: $foreground;
148148
overflow-x: hidden;
149-
border: tall transparent;
149+
border: tall $border-blurred;
150150
padding: 0 1;
151151
background: $surface;
152-
153152
& > .option-list--option-highlighted {
154153
color: $block-cursor-blurred-foreground;
155154
background: $block-cursor-blurred-background;

src/textual/widgets/_radio_set.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class RadioSet(VerticalScroll, can_focus=True, can_focus_children=False):
3939
padding: 0;
4040
4141
& > .toggle--button {
42-
color: $surface;
42+
color: $panel-darken-2;
4343
background: $panel;
4444
}
4545
@@ -49,7 +49,7 @@ class RadioSet(VerticalScroll, can_focus=True, can_focus_children=False):
4949
}
5050
5151
& > RadioButton.-on .toggle--button {
52-
color: $success;
52+
color: $text-success;
5353
}
5454
5555
&:focus {
@@ -58,17 +58,6 @@ class RadioSet(VerticalScroll, can_focus=True, can_focus_children=False):
5858
*/
5959
border: tall $border;
6060
background-tint: $foreground 5%;
61-
62-
& > RadioButton {
63-
& > .toggle--button {
64-
color: $surface;
65-
background: $panel-lighten-1;
66-
}
67-
&.-on > .toggle--button {
68-
color: $success;
69-
}
70-
}
71-
7261
& > RadioButton.-selected {
7362
color: $block-cursor-foreground;
7463
text-style: $block-cursor-text-style;

src/textual/widgets/_select.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class SelectCurrent(Horizontal):
9494

9595
DEFAULT_CSS = """
9696
SelectCurrent {
97-
border: tall transparent;
97+
border: tall $border-blurred;
9898
color: $foreground;
9999
background: $surface;
100100
width: 1fr;

0 commit comments

Comments
 (0)