comparison env/lib/python3.7/site-packages/click/_textwrap.py @ 2:6af9afd405e9 draft

"planemo upload commit 0a63dd5f4d38a1f6944587f52a8cd79874177fc1"
author shellac
date Thu, 14 May 2020 14:56:58 -0400
parents 26e78fe6e8c4
children
comparison
equal deleted inserted replaced
1:75ca89e9b81c 2:6af9afd405e9
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)