Still not working.

This commit is contained in:
Michael Lazar
2015-05-10 21:55:54 -07:00
parent 3fb3f58975
commit d1e3dbc65e
3 changed files with 20 additions and 14 deletions

View File

@@ -59,7 +59,8 @@ def command_line():
parser.add_argument('-s', dest='subreddit', help='subreddit name')
parser.add_argument('-l', dest='link', help='full link to a submission')
parser.add_argument('--unicode', help='enable unicode (experimental)')
parser.add_argument('--unicode', action='store_const', const=False,
help='enable unicode (experimental)')
parser.add_argument('--log', metavar='FILE', action='store',
help='Log HTTP requests')

View File

@@ -5,8 +5,6 @@ import curses
from curses import textpad, ascii
from contextlib import contextmanager
from kitchen.text.display import textual_width, textual_width_chop
from .docs import HELP
from .helpers import strip_textpad, clean
from .exceptions import EscapeInterrupt
@@ -66,13 +64,9 @@ def add_line(window, text, row=None, col=None, attr=None):
# Trying to draw outside of the screen bounds
return
text = clean(text)
text = textual_width_chop(text, n_cols)
if attr is None:
window.addnstr(row, col, text, n_cols)
else:
window.addnstr(row, col, text, n_cols, attr)
text = clean(text, n_cols)
params = [] if attr is None else [attr]
window.addstr(row, col, text, *params)
def show_notification(stdscr, message):

View File

@@ -5,7 +5,8 @@ from datetime import datetime
from tempfile import NamedTemporaryFile
# kitchen solves deficiencies in textwrap's handling of unicode characters
from kitchen.text.display import wrap
from kitchen.text.display import wrap, textual_width_chop
import six
from . import config
from .exceptions import ProgramError
@@ -56,7 +57,7 @@ def open_browser(url):
subprocess.check_call(args, stdout=null, stderr=null)
def clean(string):
def clean(string, n_cols=None):
"""
Required reading!
http://nedbatchelder.com/text/unipain.html
@@ -75,9 +76,19 @@ def clean(string):
If utf-8 is passed in, addnstr will treat each 'byte' as a single character.
"""
if n_cols is not None and n_cols <= 0:
return ''
if not config.unicode:
string = string.encode('ascii', 'replace')
return string
if six.PY3 or isinstance(string, unicode):
string = string.encode('ascii', 'replace')
return string[:n_cols] if n_cols else string
else:
if n_cols:
string = textual_width_chop(string, n_cols)
if six.PY3 or isinstance(string, unicode):
string = string.encode('utf-8')
return string
def wrap_text(text, width):