Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/click/_textwrap.py: 12%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1import textwrap
2import typing as t
3from contextlib import contextmanager
6class TextWrapper(textwrap.TextWrapper):
7 def _handle_long_word(
8 self,
9 reversed_chunks: t.List[str],
10 cur_line: t.List[str],
11 cur_len: int,
12 width: int,
13 ) -> None:
14 space_left = max(width - cur_len, 1)
16 if self.break_long_words:
17 last = reversed_chunks[-1]
18 cut = last[:space_left]
19 res = last[space_left:]
20 cur_line.append(cut)
21 reversed_chunks[-1] = res
22 elif not cur_line:
23 cur_line.append(reversed_chunks.pop())
25 @contextmanager
26 def extra_indent(self, indent: str) -> t.Iterator[None]:
27 old_initial_indent = self.initial_indent
28 old_subsequent_indent = self.subsequent_indent
29 self.initial_indent += indent
30 self.subsequent_indent += indent
32 try:
33 yield
34 finally:
35 self.initial_indent = old_initial_indent
36 self.subsequent_indent = old_subsequent_indent
38 def indent_only(self, text: str) -> str:
39 rv = []
41 for idx, line in enumerate(text.splitlines()):
42 indent = self.initial_indent
44 if idx > 0:
45 indent = self.subsequent_indent
47 rv.append(f"{indent}{line}")
49 return "\n".join(rv)