/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/utextwrap.py

  • Committer: Jelmer Vernooij
  • Date: 2018-11-16 19:47:19 UTC
  • mfrom: (7178 work)
  • mto: This revision was merged to the branch mainline in revision 7179.
  • Revision ID: jelmer@jelmer.uk-20181116194719-m5ut2wfuze5x9s1p
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 
26
26
from __future__ import absolute_import
27
27
 
28
 
import sys
29
28
import textwrap
30
29
from unicodedata import east_asian_width as _eawidth
31
30
 
33
32
 
34
33
__all__ = ["UTextWrapper", "fill", "wrap"]
35
34
 
 
35
 
36
36
class UTextWrapper(textwrap.TextWrapper):
37
37
    """
38
38
    Extend TextWrapper for Unicode.
60
60
    def __init__(self, width=None, **kwargs):
61
61
        if width is None:
62
62
            width = (osutils.terminal_width() or
63
 
                        osutils.default_terminal_width) - 1
 
63
                     osutils.default_terminal_width) - 1
64
64
 
65
65
        ambi_width = kwargs.pop('ambiguous_width', 1)
66
66
        if ambi_width == 1:
118
118
        to use unicode always.
119
119
        """
120
120
        i = 0
121
 
        L = len(chunks)-1
 
121
        L = len(chunks) - 1
122
122
        patsearch = self.sentence_end_re.search
123
123
        while i < L:
124
 
            if chunks[i+1] == u" " and patsearch(chunks[i]):
125
 
                chunks[i+1] = u"  "
 
124
            if chunks[i + 1] == u" " and patsearch(chunks[i]):
 
125
                chunks[i + 1] = u"  "
126
126
                i += 2
127
127
            else:
128
128
                i += 1
223
223
                if (self.max_lines is None or
224
224
                    len(lines) + 1 < self.max_lines or
225
225
                    (not chunks or
226
 
                     self.drop_whitespace and
 
226
                        self.drop_whitespace and
227
227
                     len(chunks) == 1 and
228
228
                     not chunks[0].strip()) and cur_len <= width):
229
229
                    # Convert current line back to a string and store it in
232
232
                else:
233
233
                    while cur_line:
234
234
                        if (cur_line[-1].strip() and
235
 
                            cur_len + self._width(self.placeholder) <= width):
 
235
                                cur_len + self._width(self.placeholder) <= width):
236
236
                            cur_line.append(self.placeholder)
237
237
                            lines.append(indent + ''.join(cur_line))
238
238
                            break
260
260
                    if prev_pos < pos:
261
261
                        cjk_split_chunks.append(chunk[prev_pos:pos])
262
262
                    cjk_split_chunks.append(char)
263
 
                    prev_pos = pos+1
 
263
                    prev_pos = pos + 1
264
264
            if prev_pos < len(chunk):
265
265
                cjk_split_chunks.append(chunk[prev_pos:])
266
266
        return cjk_split_chunks
271
271
 
272
272
# -- Convenience interface ---------------------------------------------
273
273
 
 
274
 
274
275
def wrap(text, width=None, **kwargs):
275
276
    """Wrap a single paragraph of text, returning a list of wrapped lines.
276
277
 
283
284
    """
284
285
    return UTextWrapper(width=width, **kwargs).wrap(text)
285
286
 
 
287
 
286
288
def fill(text, width=None, **kwargs):
287
289
    """Fill a single paragraph of text, returning a new string.
288
290
 
293
295
    available keyword args to customize wrapping behaviour.
294
296
    """
295
297
    return UTextWrapper(width=width, **kwargs).fill(text)
296