diff --git a/examples/basic.py b/examples/basic.py index 514cf8409..72743ab93 100644 --- a/examples/basic.py +++ b/examples/basic.py @@ -17,7 +17,6 @@ class BasicApp(App): footer=Widget(), sidebar=Widget(), ) - self.panic(self.stylesheet.css) BasicApp.run(css_file="basic.css", watch_css=True, log="textual.log") diff --git a/src/textual/css/_style_properties.py b/src/textual/css/_style_properties.py index 469482925..fd62367b5 100644 --- a/src/textual/css/_style_properties.py +++ b/src/textual/css/_style_properties.py @@ -333,14 +333,20 @@ class StyleProperty: rules.pop("text_background") rules.pop("text_style") elif isinstance(style, Style): - rules_set("text_color", style.color) - rules_set("text_background", style.bgcolor) - rules_set("text_style", style.without_color) + if style.color: + rules_set("text_color", style.color) + if style.bgcolor: + rules_set("text_background", style.bgcolor) + if style.without_color: + rules_set("text_style", style.without_color) elif isinstance(style, str): new_style = Style.parse(style) - rules_set("text_color", new_style.color) - rules_set("text_background", new_style.bgcolor) - rules_set("text_style", new_style.without_color) + if new_style.color: + rules_set("text_color", new_style.color or Color.default()) + if new_style.bgcolor: + rules_set("text_background", new_style.bgcolor or Color.default()) + if new_style.without_color: + rules_set("text_style", new_style.without_color) class SpacingProperty: diff --git a/src/textual/css/_styles_builder.py b/src/textual/css/_styles_builder.py index 2b1cc2456..26f10d67c 100644 --- a/src/textual/css/_styles_builder.py +++ b/src/textual/css/_styles_builder.py @@ -307,7 +307,7 @@ class StylesBuilder: self.styles.important.update( {"text_style", "text_background", "text_color"} ) - self.styles._rules["text"] = style + self.styles.text = style def process_text_color( self, name: str, tokens: list[Token], important: bool diff --git a/src/textual/css/styles.py b/src/textual/css/styles.py index 8261b49e8..18407e215 100644 --- a/src/textual/css/styles.py +++ b/src/textual/css/styles.py @@ -352,6 +352,9 @@ class Styles: rules = self.get_rules() get_rule = rules.get has_rule = rules.__contains__ + from rich import print + + print(rules) if has_rule("display"): append_declaration("display", rules["display"]) @@ -397,9 +400,9 @@ class Styles: append_declaration("text", str(self.text)) else: if has_rule("text_color"): - append_declaration("text-color", str(get_rule("text_color"))) + append_declaration("text-color", get_rule("text_color").name) if has_rule("text_bgcolor"): - append_declaration("text-bgcolor", str(get_rule("text_bgcolor"))) + append_declaration("text-bgcolor", str(get_rule("text_bgcolor").name)) if has_rule("text_style"): append_declaration("text-style", str(get_rule("text_style"))) diff --git a/src/textual/dom.py b/src/textual/dom.py index c6fa68560..47cca1776 100644 --- a/src/textual/dom.py +++ b/src/textual/dom.py @@ -43,9 +43,9 @@ class DOMNode(MessagePump): self._css_styles: Styles = Styles(self) self._inline_styles: Styles = Styles.parse(self.STYLES, repr(self), node=self) self.styles = StylesView(self, self._css_styles, self._inline_styles) - super().__init__() self.default_styles = Styles.parse(self.DEFAULT_STYLES, repr(self)) self._default_rules = self.default_styles.extract_rules((0, 0, 0)) + super().__init__() def __rich_repr__(self) -> rich.repr.Result: yield "name", self._name, None diff --git a/src/textual/view.py b/src/textual/view.py index dc1b0f618..12a10e855 100644 --- a/src/textual/view.py +++ b/src/textual/view.py @@ -15,6 +15,7 @@ from .widget import Widget @rich.repr.auto class View(Widget): + DEFAULT_STYLES = """ layout: dock; """