mirror of
https://github.com/espressif/esp-idf.git
synced 2025-07-29 18:27:20 +02:00
Merge branch 'bugfix/asyncio_progress_term_width_v5.0' into 'release/v5.0'
tools: fix progress output in asyncio.run with zero terminal width (v5.0) See merge request espressif/esp-idf!23219
This commit is contained in:
@ -153,6 +153,8 @@ def fit_text_in_terminal(out: str) -> str:
|
||||
"""Fit text in terminal, if the string is not fit replace center with `...`"""
|
||||
space_for_dots = 3 # Space for "..."
|
||||
terminal_width, _ = os.get_terminal_size()
|
||||
if not terminal_width:
|
||||
return out
|
||||
if terminal_width <= space_for_dots:
|
||||
# if the wide of the terminal is too small just print dots
|
||||
return '.' * terminal_width
|
||||
@ -246,9 +248,8 @@ class RunTool:
|
||||
|
||||
def print_progression(output: str) -> None:
|
||||
# Print a new line on top of the previous line
|
||||
sys.stdout.write('\x1b[K')
|
||||
print('\r', end='')
|
||||
print(fit_text_in_terminal(output.strip('\n\r')), end='', file=output_stream)
|
||||
print('\r' + fit_text_in_terminal(output.strip('\n\r')) + '\x1b[K', end='', file=output_stream)
|
||||
output_stream.flush()
|
||||
|
||||
async def read_stream() -> Optional[str]:
|
||||
try:
|
||||
|
Reference in New Issue
Block a user