comparison env/lib/python3.7/site-packages/click/_textwrap.py @ 5:9b1c78e6ba9c draft default tip

"planemo upload commit 6c0a8142489327ece472c84e558c47da711a9142"
author shellac
date Mon, 01 Jun 2020 08:59:25 -0400
parents 79f47841a781
children
comparison
equal deleted inserted replaced
4:79f47841a781 5:9b1c78e6ba9c
1 import textwrap
2 from contextlib import contextmanager
3
4
5 class TextWrapper(textwrap.TextWrapper):
6 def _handle_long_word(self, reversed_chunks, cur_line, cur_len, width):
7 space_left = max(width - cur_len, 1)
8
9 if self.break_long_words:
10 last = reversed_chunks[-1]
11 cut = last[:space_left]
12 res = last[space_left:]
13 cur_line.append(cut)
14 reversed_chunks[-1] = res
15 elif not cur_line:
16 cur_line.append(reversed_chunks.pop())
17
18 @contextmanager
19 def extra_indent(self, indent):
20 old_initial_indent = self.initial_indent
21 old_subsequent_indent = self.subsequent_indent
22 self.initial_indent += indent
23 self.subsequent_indent += indent
24 try:
25 yield
26 finally:
27 self.initial_indent = old_initial_indent
28 self.subsequent_indent = old_subsequent_indent
29
30 def indent_only(self, text):
31 rv = []
32 for idx, line in enumerate(text.splitlines()):
33 indent = self.initial_indent
34 if idx > 0:
35 indent = self.subsequent_indent
36 rv.append(indent + line)
37 return "\n".join(rv)