~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/utextwrap.py

  • Committer: INADA Naoki
  • Date: 2011-05-05 03:19:09 UTC
  • mto: This revision was merged to the branch mainline in revision 5874.
  • Revision ID: songofacandy@gmail.com-20110505031909-2x11eyfqf0f32h4j
Default width of UTextWrapper is also osutils.terminal_widtth() and
use osutils.default_terminal_width when it returns None.

Show diffs side-by-side

added added

removed removed

Lines of Context:
78
78
    even if !break_long_words when word contains double width
79
79
    characters.
80
80
    """
 
81
    def __init__(self, width=None, **kwargs):
 
82
        if width is None:
 
83
            width = (osutils.terminal_width() or
 
84
                        osutils.default_terminal_width) - 1
 
85
        textwrap.TextWrapper.__init__(self, width, **kwargs)
81
86
 
82
87
    def _handle_long_word(self, chunks, cur_line, cur_len, width):
83
88
        head, rest = _break_cjkword(chunks[-1], width)
173
178
    space.  See TextWrapper class for available keyword args to customize
174
179
    wrapping behaviour.
175
180
    """
176
 
    if width is None:
177
 
        width = osutils.terminal_width() - 1
178
 
    w = UTextWrapper(width=width, **kwargs)
179
 
    return w.wrap(text)
 
181
    return UTextWrapper(width=width, **kwargs).wrap(text)
180
182
 
181
183
def fill(text, width=None, **kwargs):
182
184
    """Fill a single paragraph of text, returning a new string.
187
189
    whitespace characters converted to space.  See TextWrapper class for
188
190
    available keyword args to customize wrapping behaviour.
189
191
    """
190
 
    if width is None:
191
 
        width = osutils.terminal_width() - 1
192
 
    w = UTextWrapper(width=width, **kwargs)
193
 
    return w.fill(text)
 
192
    return UTextWrapper(width=width, **kwargs).fill(text)
194
193