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: clean ephemeral line before carriage return #265

Closed
wants to merge 2 commits into from
Closed
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
5 changes: 5 additions & 0 deletions craft_cli/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import os
import pathlib
import select
import shutil
import sys
import threading
import traceback
Expand Down Expand Up @@ -720,6 +721,10 @@ def _report_error(self, error: errors.CraftError) -> None:
full_stream = sys.stderr

# the initial message
self._printer.spinner.stop()
cleaner = " " * (shutil.get_terminal_size().columns - 1)
line = "\r" + cleaner + "\r"
print(line, end="", flush=True, file=sys.stderr)
self._printer.show(sys.stderr, str(error), use_timestamp=use_timestamp, end_line=True)

if isinstance(error, errors.CraftCommandError):
Expand Down
28 changes: 28 additions & 0 deletions examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,34 @@ def example_30():
time.sleep(0.001)


def example_31():
"""Longer progress messages do not stray."""
emit.progress("Setting up computer for build...")
time.sleep(6)
emit.progress("Building computer...")
time.sleep(6)
emit.message("Done")

def example_32():
"""Multiline error message."""
emit.progress("Setting up computer for build...")
time.sleep(1)
emit.progress("Building computer...")
time.sleep(6)
raise CraftError("Setup failed\nfoo")


def example_33():
"""Stream messages don't clobber."""
emit.progress("Running multiple commands...")
emit.progress("Running multiple commands...")
with emit.open_stream() as stream:
subprocess.run(["ls", "-l"], stdout=stream, stderr=stream)
time.sleep(1)
emit.progress("Almost...")
time.sleep(1)
emit.message("Great!")

# -- end of test cases

if len(sys.argv) < 2:
Expand Down
Loading