Skip to content

Commit 7925273

Browse files
authored
Merge pull request Textualize#4606 from Textualize/hatch-fix
hatch hotfix
2 parents 3291b02 + 8bc3810 commit 7925273

File tree

7 files changed

+137
-101
lines changed

7 files changed

+137
-101
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

8+
## [0.65.1] - 2024-06-05
9+
10+
### Fixed
11+
12+
- Fixed hot reloading with hatch rule https://github.com/Textualize/textual/pull/4606
13+
- Fixed hatch style parsing https://github.com/Textualize/textual/pull/4606
14+
815
## [0.65.0] - 2024-06-05
916

1017
### Added
@@ -2062,6 +2069,7 @@ https://textual.textualize.io/blog/2022/11/08/version-040/#version-040
20622069
- New handler system for messages that doesn't require inheritance
20632070
- Improved traceback handling
20642071

2072+
[0.65.1]: https://github.com/Textualize/textual/compare/v0.65.0...v0.65.1
20652073
[0.65.0]: https://github.com/Textualize/textual/compare/v0.64.0...v0.65.0
20662074
[0.64.0]: https://github.com/Textualize/textual/compare/v0.63.6...v0.64.0
20672075
[0.63.6]: https://github.com/Textualize/textual/compare/v0.63.5...v0.63.6

docs/examples/styles/hatch.tcss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.hatch {
22
height: 1fr;
33
border: solid $secondary;
4+
45
&.cross {
56
hatch: cross $success;
67
}

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "textual"
3-
version = "0.65.0"
3+
version = "0.65.1"
44
homepage = "https://github.com/Textualize/textual"
55
repository = "https://github.com/Textualize/textual"
66
documentation = "https://textual.textualize.io/"

src/textual/css/_style_properties.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1148,7 +1148,11 @@ class HatchProperty:
11481148
def __get__(self, obj: StylesBase, type: type[StylesBase]) -> tuple[str, Color]:
11491149
return cast("tuple[str, Color]", obj.get_rule("hatch", (" ", TRANSPARENT)))
11501150

1151-
def __set__(self, obj: StylesBase, value: tuple[str, Color | str]) -> None:
1151+
def __set__(self, obj: StylesBase, value: tuple[str, Color | str] | None) -> None:
1152+
_rich_traceback_omit = True
1153+
if value is None:
1154+
obj.clear_rule("hatch")
1155+
return
11521156
character, color = value
11531157
if len(character) != 1:
11541158
try:

src/textual/css/_styles_builder.py

Lines changed: 59 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,51 +1058,73 @@ def process_constrain(self, name: str, tokens: list[Token]) -> None:
10581058
self.styles._rules[name] = value # type: ignore
10591059

10601060
def process_hatch(self, name: str, tokens: list[Token]) -> None:
1061-
character = " "
1061+
if not tokens:
1062+
return
1063+
character: str | None = None
10621064
color = TRANSPARENT
10631065
opacity = 1.0
10641066

1065-
for token in tokens:
1066-
if token.name == "token":
1067-
if token.value not in VALID_HATCH:
1068-
self.error(
1069-
name,
1070-
tokens[0],
1071-
string_enum_help_text(name, VALID_HATCH, context="css"),
1072-
)
1073-
character = HATCHES[token.value]
1074-
elif token.name == "string":
1075-
character = token.value[1:-1]
1076-
if len(character) != 1:
1077-
self.error(
1078-
name,
1079-
token,
1080-
f"Hatch requires a string of length 1; got {token.value}",
1081-
)
1082-
if cell_len(character) != 1:
1083-
self.error(
1084-
name,
1085-
token,
1086-
f"Hatch requires a string with a *cell length* of 1; got {token.value}",
1087-
)
1088-
elif token.name == "color":
1089-
try:
1090-
color = Color.parse(token.value)
1091-
except Exception as error:
1092-
self.error(
1093-
name,
1094-
token,
1095-
color_property_help_text(name, context="css", error=error),
1096-
)
1097-
elif token.name == "scalar":
1098-
opacity_scalar = opacity = Scalar.parse(token.value)
1067+
if len(tokens) not in (2, 3):
1068+
self.error(name, tokens[0], "2 or 3 values expected here")
1069+
1070+
character_token, color_token, *opacity_tokens = tokens
1071+
1072+
if character_token.name == "token":
1073+
if character_token.value not in VALID_HATCH:
1074+
self.error(
1075+
name,
1076+
tokens[0],
1077+
string_enum_help_text(name, VALID_HATCH, context="css"),
1078+
)
1079+
character = HATCHES[character_token.value]
1080+
elif character_token.name == "string":
1081+
character = character_token.value[1:-1]
1082+
if len(character) != 1:
1083+
self.error(
1084+
name,
1085+
character_token,
1086+
f"Hatch type requires a string of length 1; got {character_token.value}",
1087+
)
1088+
if cell_len(character) != 1:
1089+
self.error(
1090+
name,
1091+
character_token,
1092+
f"Hatch type requires a string with a *cell length* of 1; got {character_token.value}",
1093+
)
1094+
1095+
if color_token.name in ("color", "token"):
1096+
try:
1097+
color = Color.parse(color_token.value)
1098+
except Exception as error:
1099+
self.error(
1100+
name,
1101+
color_token,
1102+
color_property_help_text(name, context="css", error=error),
1103+
)
1104+
else:
1105+
self.error(
1106+
name, color_token, f"Expected a color; found {color_token.value!r}"
1107+
)
1108+
1109+
if opacity_tokens:
1110+
opacity_token = opacity_tokens[0]
1111+
if opacity_token.name == "scalar":
1112+
opacity_scalar = opacity = Scalar.parse(opacity_token.value)
10991113
if opacity_scalar.unit != Unit.PERCENT:
11001114
self.error(
1101-
name, token, "hatch alpha must be given as a percentage."
1115+
name,
1116+
opacity_token,
1117+
"hatch alpha must be given as a percentage.",
11021118
)
11031119
opacity = clamp(opacity_scalar.value / 100.0, 0, 1.0)
1120+
else:
1121+
self.error(
1122+
name,
1123+
opacity_token,
1124+
f"expected a percentage here; found {opacity_token.value!r}",
1125+
)
11041126

1105-
self.styles._rules[name] = (character, color.multiply_alpha(opacity))
1127+
self.styles._rules[name] = (character or " ", color.multiply_alpha(opacity))
11061128

11071129
def _get_suggested_property_name_for_rule(self, rule_name: str) -> str | None:
11081130
"""

tests/snapshot_tests/__snapshots__/test_snapshots.ambr

Lines changed: 62 additions & 61 deletions
Large diffs are not rendered by default.

tests/snapshot_tests/snapshot_apps/hatch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
class HatchApp(App):
77
CSS = """
88
Screen {
9-
hatch: right $primary;
9+
hatch: right slateblue;
1010
}
1111
#one {
1212
hatch: left $success;

0 commit comments

Comments
 (0)