Skip to content

Commit

Permalink
show red character for incorrect <space> presses (closes #90)
Browse files Browse the repository at this point in the history
  • Loading branch information
kraanzu committed Jul 27, 2024
1 parent 5186046 commit 9d7fe80
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions smassh/ui/widgets/typing/space.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,29 @@ def wrapper(space: "Space", *args, **kwargs) -> Style:
return wrapper


def incorrect_spaces(func):
INCORRECT_SPACE_CHARACTER = "░"

def wrapper(space: "Space") -> RenderableType:
text: Text = func(space)
incorrect_style = space.get_match_style(False)

plain_text = text.plain

for span in text.spans:
if span.style == incorrect_style and plain_text[span.start] == " ":
plain_text = (
plain_text[: span.start]
+ INCORRECT_SPACE_CHARACTER
+ plain_text[span.end :]
)

text.plain = plain_text
return text

return wrapper


class Space(Static):
"""
Space Widget to handle keypress and display typing text
Expand Down Expand Up @@ -198,6 +221,7 @@ def reset_components(self) -> None:

@cursor_buddy
@caret
@incorrect_spaces
def render(self) -> RenderableType:
self.paragraph.spans = self.get_colorized()
return self.paragraph
Expand Down

2 comments on commit 9d7fe80

@rhuygen
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the way you handle this with a decorator.

@kraanzu
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! This allows for fast and clean quick additions :D

Please sign in to comment.