diff --git a/craft_cli/messages.py b/craft_cli/messages.py index c873b96..bc31ef1 100644 --- a/craft_cli/messages.py +++ b/craft_cli/messages.py @@ -29,6 +29,7 @@ import os import pathlib import select +import shutil import sys import threading import traceback @@ -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): diff --git a/examples.py b/examples.py index c842a1a..b5d77d0 100755 --- a/examples.py +++ b/examples.py @@ -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: