Skip to content

fix encoding issues in urwid and curses #702

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions bpython/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ def __init__(self, scr, interp, statusbar, config, idle=None):
repl.Repl.__init__(self, interp, config)
self.interp.writetb = self.writetb
self.scr = scr
self.stdout_hist = ''
self.stdout_hist = '' # native str (bytes in Py2, unicode in Py3)
self.list_win = newwin(get_colpair(config, 'background'), 1, 1, 1, 1)
self.cpos = 0
self.do_exit = False
Expand Down Expand Up @@ -1066,13 +1066,19 @@ def prompt(self, more):
"""Show the appropriate Python prompt"""
if not more:
self.echo("\x01%s\x03%s" % (self.config.color_scheme['prompt'], self.ps1))
self.stdout_hist += self.ps1
if py3:
self.stdout_hist += self.ps1
else:
self.stdout_hist += self.ps1.encode(getpreferredencoding())
self.s_hist.append('\x01%s\x03%s\x04' %
(self.config.color_scheme['prompt'], self.ps1))
else:
prompt_more_color = self.config.color_scheme['prompt_more']
self.echo("\x01%s\x03%s" % (prompt_more_color, self.ps2))
self.stdout_hist += self.ps2
if py3:
self.stdout_hist += self.ps2
else:
self.stdout_hist += self.ps2.encode(getpreferredencoding())
self.s_hist.append('\x01%s\x03%s\x04' % (prompt_more_color, self.ps2))

def push(self, s, insert_into_history=True):
Expand Down
14 changes: 7 additions & 7 deletions bpython/urwid.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ def __init__(self, event_loop, palette, interpreter, config):
self.tooltip = urwid.ListBox(urwid.SimpleListWalker([]))
self.tooltip.grid = None
self.overlay = Tooltip(self.listbox, self.tooltip)
self.stdout_hist = ''
self.stdout_hist = '' # native str (bytes in Py2, unicode in Py3)

self.frame = urwid.Frame(self.overlay)

Expand Down Expand Up @@ -976,17 +976,17 @@ def prompt(self, more):
# input to be the same type, using ascii as encoding. If the
# caption is bytes this breaks typing non-ascii into bpython.
if not more:
caption = ('prompt', self.ps1)
if py3:
caption = ('prompt', self.ps1)
self.stdout_hist += self.ps1
else:
caption = ('prompt', self.ps1.decode(getpreferredencoding()))
self.stdout_hist += self.ps1
self.stdout_hist += self.ps1.encode(getpreferredencoding())
else:
caption = ('prompt_more', self.ps2)
if py3:
caption = ('prompt_more', self.ps2)
self.stdout_hist += self.ps2
else:
caption = ('prompt_more', self.ps2.decode(getpreferredencoding()))
self.stdout_hist += self.ps2
self.stdout_hist += self.ps2.encode(getpreferredencoding())
self.edit = BPythonEdit(self.config, caption=caption)

urwid.connect_signal(self.edit, 'change', self.on_input_change)
Expand Down