From: Guillaume Chazarain Date: Sun, 26 May 2013 17:21:28 +0000 (+0200) Subject: Python3 can print UTF-8 to curses, python2 can't so let's handle both. X-Git-Tag: iotop-0.6~4 X-Git-Url: https://repo.or.cz/w/iotop.git/commitdiff_plain/b3a739757b0c6246514e6ebc9bc02961bfa9ad15 Python3 can print UTF-8 to curses, python2 can't so let's handle both. --- diff --git a/iotop/ui.py b/iotop/ui.py index a104114..18ef227 100644 --- a/iotop/ui.py +++ b/iotop/ui.py @@ -472,7 +472,14 @@ class IOTopUI(object): num_lines = min(len(lines), self.height - 2 - int(bool(status_msg))) for i in range(num_lines): try: - self.win.addstr(i + len(summary) + 1, 0, lines[i]) + def print_line(line): + self.win.addstr(i + len(summary) + 1, 0, line) + try: + print_line(lines[i]) + except UnicodeEncodeError: + # Python2: 'ascii' codec can't encode character ... + # http://bugs.debian.org/708252 + print_line(lines[i].encode('utf-8')) except curses.error: pass if status_msg: