Skip to content
This repository has been archived by the owner on Aug 19, 2019. It is now read-only.

Commit

Permalink
Still not working.
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-lazar committed May 11, 2015
1 parent 3fb3f58 commit d1e3dbc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
3 changes: 2 additions & 1 deletion rtv/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
12 changes: 3 additions & 9 deletions rtv/curses_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
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
Expand Down Expand Up @@ -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):
Expand Down
19 changes: 15 additions & 4 deletions rtv/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
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
Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand Down

0 comments on commit d1e3dbc

Please sign in to comment.