1
0
mirror of https://github.com/HorlogeSkynet/archey4 synced 2025-04-11 00:00:19 +02:00

[FIX] Prevents TextWrapper output truncation when not a TTY

This commit is contained in:
Samuel FORESTIER 2021-04-12 18:45:18 +02:00
parent ace23a926d
commit 9f637cf0aa
3 changed files with 16 additions and 5 deletions

@ -10,6 +10,7 @@ and this project (partially) adheres to [Semantic Versioning](https://semver.org
- CHANGELOG.md file
### Changed
- Prevent text truncation when writing output to a pipe
- `distro` & `netifaces` Python dependencies are now "frozen" to allow upstream breakages
## [v4.11.0] - 2021-03-21

@ -3,11 +3,11 @@ Output class file.
It supports entries lazy-insertion, logo detection, and final printing.
"""
from textwrap import TextWrapper
from shutil import get_terminal_size
import os
import sys
from shutil import get_terminal_size
from textwrap import TextWrapper
from typing import Type
from archey.api import API
@ -101,8 +101,14 @@ class Output:
self._logo[0:0] = colored_empty_line * (-height_diff // 2)
self._logo.extend(colored_empty_line * (len(self._results) - len(self._logo)))
# When writing to a pipe (for instance), prevent `TextWrapper` from truncating output.
if not sys.stdout.isatty():
text_width = float('inf')
else:
text_width = get_terminal_size().columns - logo_width
text_wrapper = TextWrapper(
width=(get_terminal_size().columns - logo_width),
width=text_width,
expand_tabs=False,
replace_whitespace=False,
drop_whitespace=False,

@ -295,12 +295,16 @@ FAKE_COLOR 22\x1b[0m\
]
)
)
@patch(
'archey.output.sys.stdout.isatty',
return_value=True
)
@patch('archey.output.get_terminal_size')
@patch(
'archey.output.print',
return_value=None # Let's nastily mute class' outputs.
)
def test_line_wrapping(self, print_mock, termsize_mock, _, __, ___):
def test_line_wrapping(self, print_mock, termsize_mock, _, __, ___, ____):
"""Test how the `output` method handles wrapping lines that are too long"""
output = Output()