summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Quast <jquast@io.com>2015-01-04 13:32:58 -0800
committerJeff Quast <jquast@io.com>2015-01-04 13:32:58 -0800
commita3c5b7d0b23ecfb55b06e2e600c86d16f6bad4d4 (patch)
tree81909353d546531ddefee5252860de62c9046bab
parentbeaa2907d1dceb9639a7e99d31bb2fd09f43317f (diff)
downloadblessings-a3c5b7d0b23ecfb55b06e2e600c86d16f6bad4d4.tar.gz
bugfix textwrap when a 'word' ends with a sequence
-rw-r--r--.gitignore2
-rw-r--r--.prospector.yaml3
-rw-r--r--blessed/sequences.py34
-rw-r--r--blessed/tests/accessories.py2
-rw-r--r--blessed/tests/test_sequences.py1
-rw-r--r--blessed/tests/test_wrap.py47
6 files changed, 48 insertions, 41 deletions
diff --git a/.gitignore b/.gitignore
index e30e347..06cf26b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
.coverage
+.coverage.*
.cache
.tox
*.egg-info
@@ -10,4 +11,3 @@ dist
docs/_build
htmlcov
.coveralls.yml
-._coverage*
diff --git a/.prospector.yaml b/.prospector.yaml
index 83c0c35..d6714ed 100644
--- a/.prospector.yaml
+++ b/.prospector.yaml
@@ -4,6 +4,9 @@ inherits:
ignore:
- (^|/)\..+
- ^docs/
+ # ignore tests and bin/ for the moment, their quality does not so much matter.
+ - ^bin/
+ - ^blessed/tests/
test-warnings: true
diff --git a/blessed/sequences.py b/blessed/sequences.py
index 8f9ed95..9353da8 100644
--- a/blessed/sequences.py
+++ b/blessed/sequences.py
@@ -389,26 +389,24 @@ class SequenceTextWrapper(textwrap.TextWrapper):
if self.break_long_words:
term = self.term
chunk = reversed_chunks[-1]
- if (space_left == 0 or
- space_left == 1 and chunk == u' '):
- idx = space_left
+ nxt = 0
+ for idx in range(0, len(chunk)):
+ if idx == nxt:
+ # at sequence, point beyond it,
+ nxt = idx + measure_length(chunk[idx:], term)
+ if nxt <= idx:
+ # point beyond next sequence, if any,
+ # otherwise point to next character
+ nxt = idx + measure_length(chunk[idx:], term) + 1
+ if Sequence(chunk[:nxt], term).length() > space_left:
+ break
else:
- nxt = 0
- for idx in range(0, len(chunk)):
- if idx == nxt:
- # at sequence, point beyond it,
- nxt = idx + measure_length(chunk[idx:], term)
- if nxt <= idx:
- # point beyond next sequence, if any,
- # otherwise point to next character
- nxt = idx + measure_length(chunk[idx:], term) + 1
- if Sequence(chunk[:nxt], term).length() > space_left:
- break
- else:
- idx = space_left
+ # our text ends with a sequence, such as in text
+ # u'!\x1b(B\x1b[m', set index at at end (nxt)
+ idx = nxt
- cur_line.append(reversed_chunks[-1][:idx])
- reversed_chunks[-1] = reversed_chunks[-1][idx:]
+ cur_line.append(chunk[:idx])
+ reversed_chunks[-1] = chunk[idx:]
# Otherwise, we have to preserve the long word intact. Only add
# it to the current line if there's nothing already there --
diff --git a/blessed/tests/accessories.py b/blessed/tests/accessories.py
index 408d2e7..f7e2a42 100644
--- a/blessed/tests/accessories.py
+++ b/blessed/tests/accessories.py
@@ -36,7 +36,7 @@ default_all_terms = ['screen', 'vt220', 'rxvt', 'cons25', 'linux', 'ansi']
if os.environ.get('TEST_ALLTERMS'):
try:
available_terms = [
- _term.split(None, 1)[0].decode('ascii') for _term in
+ _term.split(None, 1)[0] for _term in
subprocess.Popen(('toe', '-a'),
stdout=subprocess.PIPE,
close_fds=True)
diff --git a/blessed/tests/test_sequences.py b/blessed/tests/test_sequences.py
index 6de77ec..b15426c 100644
--- a/blessed/tests/test_sequences.py
+++ b/blessed/tests/test_sequences.py
@@ -19,7 +19,6 @@ from .accessories import (
unicode_parm,
many_columns,
unicode_cap,
- many_lines,
)
# 3rd-party
diff --git a/blessed/tests/test_wrap.py b/blessed/tests/test_wrap.py
index 1e12060..e5f7a15 100644
--- a/blessed/tests/test_wrap.py
+++ b/blessed/tests/test_wrap.py
@@ -21,9 +21,9 @@ def test_SequenceWrapper_invalid_width():
@as_subprocess
def child():
- t = TestTerminal()
+ term = TestTerminal()
try:
- my_wrapped = t.wrap(u'------- -------------', WIDTH)
+ my_wrapped = term.wrap(u'------- -------------', WIDTH)
except ValueError as err:
assert err.args[0] == (
"invalid width %r(%s) (must be integer > 0)" % (
@@ -66,33 +66,40 @@ def test_SequenceWrapper(all_terms, many_columns, kwargs):
@as_subprocess
def child(term, width, kwargs):
# build a test paragraph, along with a very colorful version
- t = TestTerminal()
- pgraph = u' '.join((
- 'a', 'bc', 'def', 'ghij', 'klmno', 'pqrstu', 'vwxyz012',
- '34567890A', 'BCDEFGHIJK', 'LMNOPQRSTUV', 'WXYZabcdefgh',
- 'ijklmnopqrstu', 'vwxyz123456789', '0ABCDEFGHIJKLMN '))
+ term = TestTerminal()
+ pgraph = u' Z! a bc defghij klmnopqrstuvw<<>>xyz012345678900 '
+ attributes = ('bright_red', 'on_bright_blue', 'underline', 'reverse',
+ 'red_reverse', 'red_on_white', 'superscript',
+ 'subscript', 'on_bright_white')
+ term.bright_red('x')
+ term.on_bright_blue('x')
+ term.underline('x')
+ term.reverse('x')
+ term.red_reverse('x')
+ term.red_on_white('x')
+ term.superscript('x')
+ term.subscript('x')
+ term.on_bright_white('x')
pgraph_colored = u''.join([
- t.color(idx % 7)(char) if char != ' ' else ' '
+ getattr(term, (attributes[idx % len(attributes)]))(char)
+ if char != u' ' else u' '
for idx, char in enumerate(pgraph)])
internal_wrapped = textwrap.wrap(pgraph, width=width, **kwargs)
- my_wrapped = t.wrap(pgraph, width=width, **kwargs)
- my_wrapped_colored = t.wrap(pgraph_colored, width=width, **kwargs)
+ my_wrapped = term.wrap(pgraph, width=width, **kwargs)
+ my_wrapped_colored = term.wrap(pgraph_colored, width=width, **kwargs)
# ensure we textwrap ascii the same as python
- assert (internal_wrapped == my_wrapped)
+ assert internal_wrapped == my_wrapped
- # ensure our first and last line wraps at its ends
- first_l = internal_wrapped[0]
- last_l = internal_wrapped[-1]
- my_first_l = my_wrapped_colored[0]
- my_last_l = my_wrapped_colored[-1]
- assert (len(first_l) == t.length(my_first_l))
- assert (len(last_l) == t.length(my_last_l))
- assert (len(internal_wrapped[-1]) == t.length(my_wrapped_colored[-1]))
+ # ensure content matches for each line, when the sequences are
+ # stripped back off of each line
+ for line_no, (left, right) in enumerate(
+ zip(internal_wrapped, my_wrapped_colored)):
+ assert left == term.strip_seqs(right)
- # ensure our colored textwrap is the same line length
+ # ensure our colored textwrap is the same paragraph length
assert (len(internal_wrapped) == len(my_wrapped_colored))
child(all_terms, many_columns, kwargs)