mercurial/util.py
changeset 15031 0cb27eda3a1e
parent 15028 eb97a3e38656
child 15049 79a861b8f553
equal deleted inserted replaced
15030:261482576c1e 15031:0cb27eda3a1e
  1169         representation, or encoding of the underlying string)
  1169         representation, or encoding of the underlying string)
  1170         """
  1170         """
  1171         def __init__(self, **kwargs):
  1171         def __init__(self, **kwargs):
  1172             textwrap.TextWrapper.__init__(self, **kwargs)
  1172             textwrap.TextWrapper.__init__(self, **kwargs)
  1173 
  1173 
  1174         def _cutdown(self, str, space_left):
  1174         def _cutdown(self, ucstr, space_left):
  1175             l = 0
  1175             l = 0
  1176             ucstr = unicode(str, encoding.encoding)
       
  1177             colwidth = unicodedata.east_asian_width
  1176             colwidth = unicodedata.east_asian_width
  1178             for i in xrange(len(ucstr)):
  1177             for i in xrange(len(ucstr)):
  1179                 l += colwidth(ucstr[i]) in 'WFA' and 2 or 1
  1178                 l += colwidth(ucstr[i]) in 'WFA' and 2 or 1
  1180                 if space_left < l:
  1179                 if space_left < l:
  1181                     return (ucstr[:i].encode(encoding.encoding),
  1180                     return (ucstr[:i], ucstr[i:])
  1182                             ucstr[i:].encode(encoding.encoding))
  1181             return ucstr, ''
  1183             return str, ''
       
  1184 
  1182 
  1185         # overriding of base class
  1183         # overriding of base class
  1186         def _handle_long_word(self, reversed_chunks, cur_line, cur_len, width):
  1184         def _handle_long_word(self, reversed_chunks, cur_line, cur_len, width):
  1187             space_left = max(width - cur_len, 1)
  1185             space_left = max(width - cur_len, 1)
  1188 
  1186 
  1200 def wrap(line, width, initindent='', hangindent=''):
  1198 def wrap(line, width, initindent='', hangindent=''):
  1201     maxindent = max(len(hangindent), len(initindent))
  1199     maxindent = max(len(hangindent), len(initindent))
  1202     if width <= maxindent:
  1200     if width <= maxindent:
  1203         # adjust for weird terminal size
  1201         # adjust for weird terminal size
  1204         width = max(78, maxindent + 1)
  1202         width = max(78, maxindent + 1)
       
  1203     line = line.decode(encoding.encoding, encoding.encodingmode)
       
  1204     initindent = initindent.decode(encoding.encoding, encoding.encodingmode)
       
  1205     hangindent = hangindent.decode(encoding.encoding, encoding.encodingmode)
  1205     wrapper = MBTextWrapper(width=width,
  1206     wrapper = MBTextWrapper(width=width,
  1206                             initial_indent=initindent,
  1207                             initial_indent=initindent,
  1207                             subsequent_indent=hangindent)
  1208                             subsequent_indent=hangindent)
  1208     return wrapper.fill(line)
  1209     return wrapper.fill(line).encode(encoding.encoding)
  1209 
  1210 
  1210 def iterlines(iterator):
  1211 def iterlines(iterator):
  1211     for chunk in iterator:
  1212     for chunk in iterator:
  1212         for line in chunk.splitlines():
  1213         for line in chunk.splitlines():
  1213             yield line
  1214             yield line