Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug when line getting wrapped #15

Merged
merged 1 commit into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ publish: build
poetry publish

format:
poetry run ruff --fix rexi/ tests/
poetry run ruff format rexi/ tests/
poetry run ruff --fix rexi/ tests/

lint:
poetry run ruff rexi/ tests/
poetry run mypy rexi/ tests/

bump:
poetry run bump-my-version bump $(BUMP_PART)
poetry run bump-my-version bump $(BUMP_PART)
14 changes: 9 additions & 5 deletions rexi/rexi.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ class GroupMatch:
def __eq__(self, other: object) -> bool:
if not isinstance(other, GroupMatch):
return False
return self.start == other.start and self.end == other.end
return (
self.start == other.start
and self.end == other.end
and self.is_first == other.is_first
)

def __repr__(self) -> str:
return f"Group \"{'|'.join(map(str, self.keys))}\": \"{self.value}\""
Expand Down Expand Up @@ -117,13 +121,13 @@ def create_highlighted_output(self, groups_matches: list["GroupMatch"]) -> str:
first_ends = {group.end for group in groups_matches if group.is_first}
input_length = len(self.input_content)
for character in range(input_length):
if character in first_starts:
if character in first_starts and character not in first_ends:
output += UNDERLINE
if character in starts:
if character in starts and character not in ends:
output += Fore.RED
if character in ends:
if character in ends and character not in starts:
output += Fore.RESET
if character in first_ends:
if character in first_ends and character not in first_starts:
output += RESET_UNDERLINE
output += self.input_content[character]

Expand Down
4 changes: 2 additions & 2 deletions tests/test_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ def test_group_match_equals(
".*(aTe).*",
"This iS! aTe xt2 F0r T3sT!ng",
[
GroupMatch([0], "This iS! aTe xt2 F0r T3sT!ng", 0, 28),
GroupMatch([0], "This iS! aTe xt2 F0r T3sT!ng", 0, 28, True),
GroupMatch([1], "aTe", 9, 12),
],
],
[
".*(?P<name>aTe).*",
"This iS! aTe xt2 F0r T3sT!ng",
[
GroupMatch([0], "This iS! aTe xt2 F0r T3sT!ng", 0, 28),
GroupMatch([0], "This iS! aTe xt2 F0r T3sT!ng", 0, 28, True),
GroupMatch([1, "name"], "aTe", 9, 12),
],
],
Expand Down
Loading