Implemented unicode sandwich.

This commit is contained in:
Michael Lazar
2015-03-12 19:02:22 -07:00
parent 47ad49a189
commit 17a1c27a2c
6 changed files with 70 additions and 58 deletions

View File

@@ -7,10 +7,12 @@ import threading
from curses import textpad, ascii
from contextlib import contextmanager
import six
from six.moves import configparser
from .errors import EscapePressed
FORCE_ASCII = True
ESCAPE = 27
HELP = """
@@ -30,6 +32,31 @@ Submission Mode
`RIGHT` or `l` : Fold the selected comment, or load additional comments
"""
def clean(string):
"""
Required reading!
http://nedbatchelder.com/text/unipain.html
Python 2 input string will be a unicode type (unicode code points). Curses
will accept that if all of the points are in the ascii range. However, if
any of the code points are not valid ascii curses will throw a
UnicodeEncodeError: 'ascii' codec can't encode character, ordinal not in
range(128). However, if we encode the unicode to a utf-8 byte string and
pass that to curses, curses will render correctly.
Python 3 input string will be a string type (unicode code points). Curses
will accept that in all cases. However, the n character count in addnstr
will get screwed up.
"""
if six.PY2:
string = string.encode('utf-8', 'replace')
else:
string = string.encode('utf-8', 'replace')
pass
return string
class Color(object):
COLORS = {