Show More
@@ -511,17 +511,21 b" def trim(s, width, ellipsis=b'', leftsid" | |||
|
511 | 511 | if width <= 0: # no enough room even for ellipsis |
|
512 | 512 | return ellipsis[: width + len(ellipsis)] |
|
513 | 513 | |
|
514 | chars = list(u) | |
|
514 | 515 | if leftside: |
|
515 | uslice = lambda i: u[i:] | |
|
516 | concat = lambda s: ellipsis + s | |
|
517 | else: | |
|
518 | uslice = lambda i: u[:-i] | |
|
519 | concat = lambda s: s + ellipsis | |
|
520 | for i in pycompat.xrange(1, len(u)): | |
|
521 | usub = uslice(i) | |
|
522 | if ucolwidth(usub) <= width: | |
|
523 | return concat(usub.encode(_sysstr(encoding))) | |
|
524 | return ellipsis # no enough room for multi-column characters | |
|
516 | chars.reverse() | |
|
517 | width_so_far = 0 | |
|
518 | for i, c in enumerate(chars): | |
|
519 | width_so_far += ucolwidth(c) | |
|
520 | if width_so_far > width: | |
|
521 | break | |
|
522 | chars = chars[:i] | |
|
523 | if leftside: | |
|
524 | chars.reverse() | |
|
525 | u = u''.join(chars).encode(_sysstr(encoding)) | |
|
526 | if leftside: | |
|
527 | return ellipsis + u | |
|
528 | return u + ellipsis | |
|
525 | 529 | |
|
526 | 530 | |
|
527 | 531 | class normcasespecs(object): |
General Comments 0
You need to be logged in to leave comments.
Login now