Skip to content

Commit 9f32476

Browse files
authored
Theme tweaks (#5232)
* theme tweaks * style tweaks * snapshots * demo tweaks * projects tweaks
1 parent 365abe6 commit 9f32476

File tree

101 files changed

+6293
-6249
lines changed

Some content is hidden

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

101 files changed

+6293
-6249
lines changed

examples/calculator.tcss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Button {
2727
column-span: 4;
2828
padding: 0 1;
2929
height: 100%;
30-
background: $primary-lighten-2;
30+
background: $panel;
3131
color: $text;
3232
content-align: center middle;
3333
text-align: right;

examples/code_browser.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
from textual.app import App, ComposeResult
1515
from textual.containers import Container, VerticalScroll
16-
from textual.reactive import var
16+
from textual.reactive import reactive, var
1717
from textual.widgets import DirectoryTree, Footer, Header, Static
1818

1919

@@ -27,6 +27,7 @@ class CodeBrowser(App):
2727
]
2828

2929
show_tree = var(True)
30+
path: reactive[str | None] = reactive(None)
3031

3132
def watch_show_tree(self, show_tree: bool) -> None:
3233
"""Called when show_tree is modified."""
@@ -45,27 +46,40 @@ def compose(self) -> ComposeResult:
4546
def on_mount(self) -> None:
4647
self.query_one(DirectoryTree).focus()
4748

49+
def theme_change(_signal) -> None:
50+
"""Force the syntax to use a different theme."""
51+
self.watch_path(self.path)
52+
53+
self.theme_changed_signal.subscribe(self, theme_change)
54+
4855
def on_directory_tree_file_selected(
4956
self, event: DirectoryTree.FileSelected
5057
) -> None:
5158
"""Called when the user click a file in the directory tree."""
5259
event.stop()
60+
self.path = str(event.path)
61+
62+
def watch_path(self, path: str | None) -> None:
63+
"""Called when path changes."""
5364
code_view = self.query_one("#code", Static)
65+
if path is None:
66+
code_view.update("")
67+
return
5468
try:
5569
syntax = Syntax.from_path(
56-
str(event.path),
70+
path,
5771
line_numbers=True,
5872
word_wrap=False,
5973
indent_guides=True,
60-
theme="github-dark",
74+
theme="github-dark" if self.current_theme.dark else "github-light",
6175
)
6276
except Exception:
6377
code_view.update(Traceback(theme="github-dark", width=None))
6478
self.sub_title = "ERROR"
6579
else:
6680
code_view.update(syntax)
6781
self.query_one("#code-view").scroll_home(animate=False)
68-
self.sub_title = str(event.path)
82+
self.sub_title = path
6983

7084
def action_toggle_files(self) -> None:
7185
"""Called in response to key binding."""

examples/code_browser.tcss

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
Screen {
2-
background: $surface-darken-1;
32
&:inline {
43
height: 50vh;
54
}
@@ -23,7 +22,7 @@ CodeBrowser.-show-tree #tree-view {
2322
#code-view {
2423
overflow: auto scroll;
2524
min-width: 100%;
26-
hatch: right $primary;
25+
hatch: right $panel;
2726
}
2827
#code {
2928
width: auto;

examples/dictionary.tcss

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ Input#dictionary-search {
1313
}
1414

1515
#results-container {
16-
background: $background 50%;
16+
background: $surface;
1717
margin: 0 0 1 0;
1818
height: 100%;
1919
overflow: hidden auto;
20-
border: tall $background;
20+
border: tall transparent;
2121
}
2222

2323
#results-container:focus {
24-
border: tall $accent;
24+
border: tall $border;
2525
}

examples/merlin.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ class Timer(Digits):
7777
width: auto;
7878
margin: 2 8;
7979
color: $warning;
80+
&:light {
81+
color: $secondary;
82+
}
8083
}
8184
"""
8285
start_time = var(0.0)
@@ -115,7 +118,7 @@ class MerlinApp(App):
115118
Grid {
116119
width: auto;
117120
height: auto;
118-
border: thick $primary;
121+
border: thick $border;
119122
padding: 1 2;
120123
grid-size: 3 3;
121124
grid-rows: auto;
@@ -162,6 +165,7 @@ def on_switch_changed(self, event: Switch.Changed) -> None:
162165
if self.check_win():
163166
self.query_one("Screen").add_class("-win")
164167
self.query_one(Timer).running = False
168+
self.notify("You win!", title="congratulations", severity="information")
165169

166170
def on_key(self, event: events.Key) -> None:
167171
"""Maps switches to keys, so we can use the keyboard as well."""

examples/mother.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
try:
2323
import llm
2424
except ImportError:
25-
raise ImportError("install the 'llm' package or run with 'uv run mother.py'")
25+
raise ImportError(
26+
"install the 'llm' package or run with 'uv run mother.py'"
27+
) from None
2628

2729
# The system prompt
2830
SYSTEM = """Formulate all responses as if you where the sentient AI named Mother from the Alien movies."""

src/textual/command.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ class CommandList(OptionList, can_focus=False):
467467
CommandList > .option-list--option {
468468
padding: 0 2;
469469
color: $foreground;
470+
text-style: bold;
470471
}
471472
"""
472473

@@ -551,21 +552,15 @@ class CommandPalette(SystemModalScreen[None]):
551552
}
552553
}
553554
554-
CommandPalette > .command-palette--help-text {
555-
color: auto 50%;
555+
CommandPalette > .command-palette--help-text {
556+
color: $text-muted;
556557
background: transparent;
557-
text-style: not bold;
558-
}
559-
560-
CommandPalette:dark > .command-palette--highlight {
561-
text-style: bold;
562-
color: $warning;
558+
text-style: not bold dim;
563559
}
560+
564561
CommandPalette > .command-palette--highlight {
565-
text-style: bold;
566-
color: $warning-darken-2;
567-
568-
}
562+
text-style: bold underline;
563+
}
569564
570565
CommandPalette:nocolor > .command-palette--highlight {
571566
text-style: underline;
@@ -806,7 +801,9 @@ def _on_mount(self, _: Mount) -> None:
806801
self.app.post_message(CommandPalette.Opened())
807802
self._calling_screen = self.app.screen_stack[-2]
808803

809-
match_style = self.get_component_rich_style("command-palette--highlight")
804+
match_style = self.get_component_rich_style(
805+
"command-palette--highlight", partial=True
806+
)
810807

811808
assert self._calling_screen is not None
812809
self._providers = [

src/textual/demo/home.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ class StarCount(Vertical):
142142
layout: horizontal;
143143
background: $boost;
144144
padding: 0 1;
145-
color: $warning;
145+
color: $text-warning;
146146
#stars { align: center top; }
147147
#forks { align: right top; }
148148
Label { text-style: bold; }

src/textual/demo/projects.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,12 @@ class Project(Vertical, can_focus=True, can_focus_children=False):
137137
padding: 0 1;
138138
border: tall transparent;
139139
box-sizing: border-box;
140-
&:focus {
141-
border: tall $accent;
142-
background: $primary 40%;
143-
opacity: 1.0;
140+
&:focus {
141+
border: tall $text-primary;
142+
background: $primary 20%;
143+
&.link {
144+
color: red !important;
145+
}
144146
}
145147
#title { text-style: bold; width: 1fr; }
146148
#author { text-style: italic; }
@@ -152,7 +154,7 @@ class Project(Vertical, can_focus=True, can_focus_children=False):
152154
}
153155
.header { height: 1; }
154156
.link {
155-
color: $accent;
157+
color: $text-accent;
156158
text-style: underline;
157159
}
158160
.description { color: $text-muted; }
@@ -205,9 +207,9 @@ class ProjectsScreen(PageScreen):
205207
height: auto;
206208
grid-gutter: 1 1;
207209
grid-rows: auto;
208-
keyline:thin $foreground 50%;
210+
keyline:thin $foreground 30%;
209211
}
210-
Markdown { margin: 0; padding: 0 2; max-width: 100;}
212+
Markdown { margin: 0; padding: 0 2; max-width: 100; background: transparent; }
211213
}
212214
"""
213215

src/textual/demo/widgets.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,9 @@ class WidgetsScreen(PageScreen):
441441
CSS = """
442442
WidgetsScreen {
443443
align-horizontal: center;
444+
Markdown {
445+
background: transparent;
446+
}
444447
& > VerticalScroll {
445448
scrollbar-gutter: stable;
446449
&> * {

0 commit comments

Comments
 (0)