Coverage for typer / _click / _textwrap.py: 100%

29 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-11-18 11:12 +0000

1import textwrap 1abcdefghij

2from collections.abc import Generator 1abcdefghij

3from contextlib import contextmanager 1abcdefghij

4 

5 

6class TextWrapper(textwrap.TextWrapper): 1abcdefghij

7 def _handle_long_word( 1abcdefghij

8 self, 

9 reversed_chunks: list[str], 

10 cur_line: list[str], 

11 cur_len: int, 

12 width: int, 

13 ) -> None: 

14 space_left = max(width - cur_len, 1) 1abcdefghij

15 

16 last = reversed_chunks[-1] 1abcdefghij

17 cut = last[:space_left] 1abcdefghij

18 res = last[space_left:] 1abcdefghij

19 cur_line.append(cut) 1abcdefghij

20 reversed_chunks[-1] = res 1abcdefghij

21 

22 @contextmanager 1abcdefghij

23 def extra_indent(self, indent: str) -> Generator[None]: 1abcdefghij

24 old_initial_indent = self.initial_indent 1abcdefghij

25 old_subsequent_indent = self.subsequent_indent 1abcdefghij

26 self.initial_indent += indent 1abcdefghij

27 self.subsequent_indent += indent 1abcdefghij

28 

29 try: 1abcdefghij

30 yield 1abcdefghij

31 finally: 

32 self.initial_indent = old_initial_indent 1abcdefghij

33 self.subsequent_indent = old_subsequent_indent 1abcdefghij

34 

35 def indent_only(self, text: str) -> str: 1abcdefghij

36 rv = [] 1abcdefghij

37 

38 for idx, line in enumerate(text.splitlines()): 1abcdefghij

39 indent = self.initial_indent 1abcdefghij

40 

41 if idx > 0: 1abcdefghij

42 indent = self.subsequent_indent 1abcdefghij

43 

44 rv.append(f"{indent}{line}") 1abcdefghij

45 

46 return "\n".join(rv) 1abcdefghij