Skip to content

Commit

Permalink
[cliptext] squeeze in single-width char when truncating double-width …
Browse files Browse the repository at this point in the history
…char #1918
  • Loading branch information
saulpw committed Oct 19, 2023
1 parent ebd84d9 commit 4ceeb8d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 6 additions & 2 deletions visidata/cliptext.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,12 @@ def _clipstr(s, dispw, trunch='', oddspacech='', combch='', modch=''):

if dispw and w+chlen > dispw:
if trunchlen and dispw > trunchlen:
ret = ret[:-1] + trunch # replace final char with ellipsis
w += trunchlen-1
lastchlen = _dispch(ret[-1])[1]
if w+trunchlen > dispw:
ret = ret[:-1]
w -= lastchlen
ret += trunch # replace final char with ellipsis
w += trunchlen
break

w += chlen
Expand Down
3 changes: 2 additions & 1 deletion visidata/tests/test_cliptext.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ def test_dispwidth(self, s, dispw):
('b to', 4, 'b to', 4),
('abcde', 8, 'abcde', 5),
(' jsonl', 5, ' jso…', 5),
(' で', 6, ' で', 6),
('abcdで', 6, 'abcdで', 6),
('abcdで', 5, 'abcd…', 5),
])
def test_clipstr(self, s, w, clippeds, clippedw):
clips, clipw = visidata.clipstr(s, w)
Expand Down

0 comments on commit 4ceeb8d

Please sign in to comment.