In progress.

This commit is contained in:
Michael Lazar
2015-04-29 22:31:24 -07:00
parent b573afeb2b
commit 49a9147ca6
5 changed files with 13 additions and 14 deletions

View File

@@ -1,17 +1,18 @@
import sys
import os
import textwrap
import subprocess
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 . import config
from .exceptions import ProgramError
__all__ = ['open_browser', 'clean', 'wrap_text', 'strip_textpad',
'strip_subreddit_url', 'humanize_timestamp', 'open_editor']
def open_editor(data=''):
"""
Open a temporary file using the system's default editor.
@@ -74,11 +75,10 @@ def clean(string):
If utf-8 is passed in, addnstr will treat each 'byte' as a single character.
"""
encoding = 'utf-8' if config.unicode else 'ascii'
string = string.encode(encoding, 'replace')
if not config.unicode:
string = string.encode('ascii', 'replace')
return string
def wrap_text(text, width):
"""
Wrap text paragraphs to the given character width while preserving newlines.
@@ -87,7 +87,7 @@ def wrap_text(text, width):
for paragraph in text.splitlines():
# Wrap returns an empty list when paragraph is a newline. In order to
# preserve newlines we substitute a list containing an empty string.
lines = textwrap.wrap(paragraph, width=width) or ['']
lines = wrap(paragraph, width=width) or ['']
out.extend(lines)
return out