Explorar el Código

support unicode chars in curses env

Fabian Peter Hammerle hace 9 años
padre
commit
b2600b5405
Se han modificado 2 ficheros con 7 adiciones y 2 borrados
  1. 2 0
      ioex/__init__.py
  2. 5 2
      ioex/selector.py

+ 2 - 0
ioex/__init__.py

@@ -1,5 +1,6 @@
 import os
 import sys
+import locale
 
 def curses_tty_wrapper(function, *args, **kwargs):
     stdin_fd = os.dup(sys.stdin.fileno())
@@ -11,6 +12,7 @@ def curses_tty_wrapper(function, *args, **kwargs):
     tty_out = open('/dev/tty', 'w')
     os.dup2(tty_out.fileno(), sys.stdout.fileno())
     # os.system('ls -l /proc/self/fd/')
+    locale.setlocale(locale.LC_ALL, '')
     import curses
     result = curses.wrapper(function, *args, **kwargs)
     # reset stdin and stdout

+ 5 - 2
ioex/selector.py

@@ -4,6 +4,8 @@ import os
 import curses
 import curses.textpad
 import curses.wrapper
+import locale
+import pprint
 import textwrap
 
 KEY_ESC = 27
@@ -83,10 +85,11 @@ class SelectionPad(object):
         self._pad.refresh(pminrow, 0, 0, 0, smaxrow, smaxcol)
 
     def addstr(self, line_index, col_index, text, attr = 0):
+        text_encoded = text.encode(locale.getpreferredencoding())
         try:
-            self._pad.addstr(line_index, col_index, text, attr)
+            self._pad.addstr(line_index, col_index, text_encoded, attr)
         except Exception, ex:
-            raise Exception('pad(width=%d, height=%d).addstr(%d, %d, "%s", %d) failed' % (self.get_width(), self.get_height(), line_index, col_index, text, attr))
+            raise Exception('pad(width=%d, height=%d).addstr(%d, %d, "%s", %d) failed' % (self.get_width(), self.get_height(), line_index, col_index, text_encoded, attr))
 
     def clear(self):
         self._pad.clear()