Skip to content

Commit

Permalink
Fix handling of unicode source (reported by Morten Nielsen)
Browse files Browse the repository at this point in the history
  • Loading branch information
inducer committed Feb 27, 2014
1 parent 254630e commit e12d421
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
1 change: 1 addition & 0 deletions pudb/debugger.py
Expand Up @@ -1939,6 +1939,7 @@ def event_loop(self, toplevel=None):
"\nChanges in version 2014.1:\n\n"
"- Make prompt-on-quit optional (Mike Burr)\n"
"- Make tab completion in the built-in shell saner\n"
"- Fix handling of unicode source (reported by Morten Nielsen)\n"

"\nChanges in version 2013.5.1:\n\n"
"- Fix loading of saved breakpoint conditions "
Expand Down
26 changes: 23 additions & 3 deletions pudb/source_view.py
Expand Up @@ -38,7 +38,10 @@ def render(self, size, focus=False):

maxcol = size[0]
hscroll = self.dbg_ui.source_hscroll_start

# attrs is a list of words like 'focused' and 'breakpoint'
attrs = []

if self.is_current:
crnt = ">"
attrs.append("current")
Expand Down Expand Up @@ -86,11 +89,28 @@ def render(self, size, focus=False):
text = text[:maxcol]
attr = rle_subseg(attr, 0, maxcol)

# shipout -------------------------------------------------------------
# shipout, encoding ---------------------------------------------------
cs = []
encoded_text_segs = []
encoded_attr = []

from urwid.util import apply_target_encoding
txt, cs = apply_target_encoding(text)

return urwid.TextCanvas([txt], [attr], [cs], maxcol=maxcol)
i = 0
for seg_attr, seg_len in attr:
unencoded_seg_text = text[i:i+seg_len]
encoded_seg_text, seg_cs = apply_target_encoding(unencoded_seg_text)

adjustment = len(encoded_seg_text) - len(unencoded_seg_text)

encoded_attr.append((seg_attr, seg_len + adjustment))
encoded_text_segs.append(encoded_seg_text)
cs.extend(seg_cs)

i += seg_len

return urwid.TextCanvas([
b"".join(encoded_text_segs)], [encoded_attr], [cs], maxcol=maxcol)

def keypress(self, size, key):
return key
Expand Down

0 comments on commit e12d421

Please sign in to comment.