Skip to content

Commit

Permalink
Merge branch 'ecma-48-sgr-aware'
Browse files Browse the repository at this point in the history
  • Loading branch information
jquast committed May 18, 2014
2 parents 8900c08 + dc8ec2d commit aaa303d
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 10 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
include README.rst
include LICENSE
include tox.ini
include blessed/tests/wall.ans
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,8 @@ Version History
* enhancement: include wcwidth_ library support for ``length()``, the
printable width of many kinds of CJK (Chinese, Japanese, Korean) ideographs
are more correctly determined.
* enhancement: better support for detecting the length or sequences of
externally-generated *ecma-48* codes when using ``xterm`` or ``aixterm``.
* bugfix: if ``locale.getpreferredencoding()`` returns empty string or an
encoding that is not a valid codec for ``codecs.getincrementaldecoder``,
fallback to ascii and emit a warning.
Expand Down
27 changes: 21 additions & 6 deletions blessed/sequences.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def _build_numeric_capability(term, cap, optional=False,
if _cap:
args = (base_num,) * nparams
cap_re = re.escape(_cap(*args))
for num in range(base_num-1, base_num+2):
# search for matching ascii, n-1 through n+2
for num in range(base_num - 1, base_num + 2):
# search for matching ascii, n-1 through n+1
if str(num) in cap_re:
# modify & return n to matching digit expression
cap_re = cap_re.replace(str(num), r'(\d+)%s' % (opt,))
Expand Down Expand Up @@ -261,13 +261,28 @@ def init_sequence_patterns(term):

# Build will_move, a list of terminal capabilities that have
# indeterminate effects on the terminal cursor position.
_will_move = _merge_sequences(get_movement_sequence_patterns(term)
) if term.does_styling else set()
_will_move = set()
if term.does_styling:
_will_move = _merge_sequences(get_movement_sequence_patterns(term))

# Build wont_move, a list of terminal capabilities that mainly affect
# video attributes, for use with measure_length().
_wont_move = _merge_sequences(get_wontmove_sequence_patterns(term)
) if term.does_styling else set()
_wont_move = set()
if term.does_styling:
_wont_move = _merge_sequences(get_wontmove_sequence_patterns(term))
_wont_move += [
# some last-ditch match efforts; well, xterm and aixterm is going
# to throw \x1b(B and other oddities all around, so, when given
# input such as ansi art (see test using wall.ans), and well,
# theres no reason a vt220 terminal shouldn't be able to recognize
# blue_on_red, even if it didn't cause it to be generated. these
# are final "ok, i will match this, anyway"
re.escape(u'\x1b') + r'\[(\d+)m',
re.escape(u'\x1b') + r'\[(\d+)\;(\d+)m',
re.escape(u'\x1b') + r'\[(\d+)\;(\d+)\;(\d+)m',
re.escape(u'\x1b') + r'\[(\d+)\;(\d+)\;(\d+)\;(\d+)m',
re.escape(u'\x1b(B'),
]

# compile as regular expressions, OR'd.
_re_will_move = re.compile('(%s)' % ('|'.join(_will_move)))
Expand Down
25 changes: 23 additions & 2 deletions blessed/tests/test_length_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,46 @@


def test_length_cjk():

@as_subprocess
def child():
term = TestTerminal(kind='xterm-256color')

# given,
given = term.bold_red(u'コンニチハ, セカイ!')
expected = sum((2, 2, 2, 2, 2, 1, 1, 2, 2, 2, 1,))

# exercise,
assert term.length(given) == expected

child()


def test_length_ansiart():
@as_subprocess
def child():
import codecs
from blessed.sequences import Sequence
term = TestTerminal(kind='xterm-256color')
# this 'ansi' art contributed by xzip!impure for another project,
# unlike most CP-437 DOS ansi art, this is actually utf-8 encoded.
fname = os.path.join(os.path.dirname(__file__), 'wall.ans')
lines = codecs.open(fname, 'r', 'utf-8').readlines()
assert term.length(lines[0]) == 67 # ^[[64C^[[34m▄▓▄
assert term.length(lines[1]) == 75
assert term.length(lines[2]) == 78
assert term.length(lines[3]) == 78
assert term.length(lines[4]) == 78
assert term.length(lines[5]) == 78
assert term.length(lines[6]) == 77
child()


def test_sequence_length(all_terms):
"""Ensure T.length(string containing sequence) is correct."""
@as_subprocess
def child(kind):
t = TestTerminal(kind=kind)
# Create a list of ascii characters, to be seperated
# Create a list of ascii characters, to be separated
# by word, to be zipped up with a cycling list of
# terminal sequences. Then, compare the length of
# each, the basic plain_text.__len__ vs. the Terminal
Expand Down
7 changes: 7 additions & 0 deletions blessed/tests/wall.ans
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
▄▓▄
░░ █▀▀█▀██▀████████▀█▀▀█ █▀▀█▀██▀▀█▀█xz(imp)
▄▄▄ ▓█████ ▄▄ █▀▀█░ ▀▀▀▀▀ █████▓ ▓█████ ░▓ █▀▀█░ ▓█████ ░▓ █▀▀█░ ░▄ ░░
▐▄░▄▀ ▀▀▀▀▀▀ █▓ ▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀ ██ ▀▀▀▀▀ ▀▀▀▀▀▀ ██ ▀▀▀▀▀ █▄▌▌▄▄
█▓██ ░▓████ ▐ ████░ ░████ ▄█ ████▓░ ░▓████ ██ ████░ ░▓████ ██ ████░ █▐▄▄█░
██▓▀ ░▓████ █ ████░ ░████ ▐ ████▓░ ░▓████ ▄█▌████░ ░▓████ ▄█▌████░ ▌█████
▀ ░▓████▄█▄▄███ ░ ░ ███▄▄▄▄████▓░ ░▓████▄▄▄▄███ ░ ░▓████▄▄▄▄███ ░ ▀▀▀▓
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
# built documents.
#
# The short X.Y version.
version = '1.8.7'
version = '1.8.8'

# The full version, including alpha/beta/rc tags.
release = version
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def main():
here = os.path.dirname(__file__)
setuptools.setup(
name='blessed',
version='1.8.7',
version='1.8.8',
description="A feature-filled fork of Erik Rose's blessings project",
long_description=open(os.path.join(here, 'README.rst')).read(),
author='Jeff Quast',
Expand Down

0 comments on commit aaa303d

Please sign in to comment.