Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #174 from pquentin/unicode-var-view
Ensure var view never splits Unicode chars
  • Loading branch information
inducer committed Mar 29, 2016
2 parents 51d52d8 + 6ae5724 commit 20e181d
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions pudb/ui_tools.py
@@ -1,4 +1,5 @@
import urwid
from urwid.util import _target_encoding


# generic urwid helpers -------------------------------------------------------
Expand All @@ -22,9 +23,20 @@ def make_canvas(txt, attr, maxcol, fill_attr=None):
line_attr = rle_subseg(line_attr, 0, maxcol)

from urwid.util import apply_target_encoding
line, line_cs = apply_target_encoding(line)
encoded_line, line_cs = apply_target_encoding(line)

processed_txt.append(line)
# line_cs contains byte counts as requested by TextCanvas, but
# line_attr still contains column counts at this point: let's fix this.
def get_byte_line_attr(line, line_attr):
i = 0
for label, column_count in line_attr:
byte_count = len(line[i:column_count].encode(_target_encoding))
i += column_count
yield label, byte_count

line_attr = list(get_byte_line_attr(line, line_attr))

processed_txt.append(encoded_line)
processed_attr.append(line_attr)
processed_cs.append(line_cs)

Expand Down

0 comments on commit 20e181d

Please sign in to comment.