[#3199|Console] Fix UnicodeEncodeError in addstr

The following error was encountered by user:

   ...deluge/ui/console/modes/basemode.py, line 290, in add_string
       screen.addstr(row, col, string, color)
   UnicodeEncodeError: 'ascii' codec can't encode character...

The `add_str` method is defaulting to using the Python 2 ascii
encoding with a unicode string so use the encoding passed to the
function.
This commit is contained in:
Calum Lind 2018-10-22 15:59:12 +01:00
parent 9e7c9fc1d3
commit 1838403e3b
2 changed files with 2 additions and 2 deletions

View File

@ -299,7 +299,7 @@ def add_string(
string = string[0:remaining_chrs]
try:
screen.addstr(row, col, string, color)
screen.addstr(row, col, string.encode(encoding), color)
except curses.error as ex:
# Ignore exception for writing offscreen.
pass

View File

@ -548,7 +548,7 @@ class CmdLine(BaseMode, Commander):
# This is the last string so lets append some " " to it
s += ' ' * (self.cols - (col + strwidth(s)) - 1)
try:
self.stdscr.addstr(row, col, s, color)
self.stdscr.addstr(row, col, s.encode(self.encoding), color)
except curses.error:
pass