-
Notifications
You must be signed in to change notification settings - Fork 432
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 animation of long lines #247
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
a26b2bb
Truncate long lines with animation, to prevent multi-line.
itsayellow 0fefbf2
Remove unused TERM_ROWS.
itsayellow 4bcce89
Tailor truncation depending on animate_at_beginning_of_line.
itsayellow 6bfe12c
Make if test correspond to string format precision.
itsayellow c7ef9d8
Move get_terminal_size() inside of animate().
itsayellow 4f31d46
Fix bug from last commit.
itsayellow 58cbefb
Make max message length method a bit clearer.
itsayellow 9fdf83f
Add tests for message truncation.
itsayellow aec4c98
Deleted unused import sys.
itsayellow 9e1eb97
Add HIDE_CURSOR, SHOW_CURSOR, CLEAR_LINE global strings to animate.py.
itsayellow 29a058a
Add EMOJI_ANIMATION_FRAMES, NONEMOJI_ANIMATION_FRAMES globals to anim…
itsayellow f3aa77a
Add EMOJI_ANIMATION_PERIOD, NONEMOJI_ANIMATION_PERIOD globals to anim…
itsayellow c9be0a7
Remove python shebang.
itsayellow 73b861f
Implement teardown to re-do original terminal state.
itsayellow 49228e5
Use monkeypatch instead of terminal_state fixture.
itsayellow 9f60dc5
Refactor and remove unused import pytest.
itsayellow 443b621
Increase sleep time to ensure all frames print.
itsayellow f60e310
Merge remote-tracking branch 'upstream/master' into animate_long_lines
itsayellow 8f89f97
Merge branch 'animate_long_lines' of github.com:itsayellow/pipx into …
itsayellow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import time | ||
|
||
import pipx.animate | ||
from pipx.animate import ( | ||
HIDE_CURSOR, | ||
CLEAR_LINE, | ||
EMOJI_ANIMATION_FRAMES, | ||
NONEMOJI_ANIMATION_FRAMES, | ||
EMOJI_FRAME_PERIOD, | ||
NONEMOJI_FRAME_PERIOD, | ||
) | ||
|
||
|
||
def check_animate_output( | ||
capsys, test_string, frame_strings, frame_period, frames_to_test | ||
): | ||
expected_string = f"{HIDE_CURSOR}" + "".join(frame_strings) | ||
|
||
chars_to_test = 1 + len("".join(frame_strings[:frames_to_test])) | ||
|
||
with pipx.animate.animate(test_string, do_animation=True): | ||
time.sleep(frame_period * (frames_to_test - 1) + 0.2) | ||
captured = capsys.readouterr() | ||
|
||
assert captured.err[:chars_to_test] == expected_string[:chars_to_test] | ||
|
||
|
||
def test_line_lengths_emoji(capsys, monkeypatch): | ||
# emoji_support and stderr_is_tty is set only at import animate.py | ||
# since we are already after that, we must override both here | ||
monkeypatch.setattr(pipx.animate, "stderr_is_tty", True) | ||
monkeypatch.setattr(pipx.animate, "emoji_support", True) | ||
|
||
frames_to_test = 4 | ||
|
||
# 40-char test_string counts columns e.g.: "0204060810 ... 363840" | ||
test_string = "".join([f"{x:02}" for x in range(2, 41, 2)]) | ||
|
||
columns_to_test = [45, 46, 47] | ||
expected_message = [f"{test_string:.{45-6}}...", f"{test_string}", f"{test_string}"] | ||
|
||
for i, columns in enumerate(columns_to_test): | ||
monkeypatch.setenv("COLUMNS", str(columns)) | ||
|
||
frame_strings = [ | ||
f"{CLEAR_LINE}\r{x} {expected_message[i]}" for x in EMOJI_ANIMATION_FRAMES | ||
] | ||
check_animate_output( | ||
capsys, test_string, frame_strings, EMOJI_FRAME_PERIOD, frames_to_test | ||
) | ||
|
||
|
||
def test_line_lengths_no_emoji(capsys, monkeypatch): | ||
# emoji_support and stderr_is_tty is set only at import animate.py | ||
# since we are already after that, we must override both here | ||
monkeypatch.setattr(pipx.animate, "stderr_is_tty", True) | ||
monkeypatch.setattr(pipx.animate, "emoji_support", False) | ||
|
||
frames_to_test = 2 | ||
|
||
# 40-char test_string counts columns e.g.: "0204060810 ... 363840" | ||
test_string = "".join([f"{x:02}" for x in range(2, 41, 2)]) | ||
|
||
columns_to_test = [43, 44, 45] | ||
expected_message = [f"{test_string:.{43-4}}", f"{test_string}", f"{test_string}"] | ||
|
||
for i, columns in enumerate(columns_to_test): | ||
monkeypatch.setenv("COLUMNS", str(columns)) | ||
|
||
frame_strings = [ | ||
f"{CLEAR_LINE}\r{expected_message[i]}{x}" for x in NONEMOJI_ANIMATION_FRAMES | ||
] | ||
|
||
check_animate_output( | ||
capsys, test_string, frame_strings, NONEMOJI_FRAME_PERIOD, frames_to_test | ||
) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great! Thanks for adding these tests.