summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjquast <contact@jeffquast.com>2014-09-08 07:08:21 -0700
committerjquast <contact@jeffquast.com>2014-09-08 07:08:21 -0700
commit1e22efd601f080eaa62e3bd021083b9dae7025d4 (patch)
tree0a4d175dcff10764b4c0696a777784743503d02f
parentcec390ae3ab9f3aff1dccced4d775af8da69438c (diff)
downloadblessings-1e22efd601f080eaa62e3bd021083b9dae7025d4.tar.gz
only provide proxy where db is unmatched (u'')
and, proxy hpa and vpa for 'ansi' terminals. I've noticed on OSX, 'ansi' *does* provide hpa and vpa, but on linux, it does not. This change covers both.
-rw-r--r--blessed/formatters.py21
-rw-r--r--blessed/tests/test_sequences.py12
2 files changed, 21 insertions, 12 deletions
diff --git a/blessed/formatters.py b/blessed/formatters.py
index 7070323..e77adcd 100644
--- a/blessed/formatters.py
+++ b/blessed/formatters.py
@@ -131,8 +131,8 @@ def get_proxy_string(term, attr):
""" Proxy and return callable StringClass for proxied attributes.
We know that some kinds of terminal kinds support sequences that the
- terminfo database often doesn't report -- such as the 'move_x' attribute
- for terminal type 'screen', or 'hide_cursor' for 'ansi'.
+ terminfo database always report -- such as the 'move_x' attribute for
+ terminal type 'screen' and 'ansi', or 'hide_cursor' for 'ansi'.
Returns instance of ParameterizingProxyString or NullCallableString.
"""
@@ -153,6 +153,10 @@ def get_proxy_string(term, attr):
(u'\x1b[?25l', lambda *arg: ()), term.normal, attr),
'cnorm': ParameterizingProxyString(
(u'\x1b[?25h', lambda *arg: ()), term.normal, attr),
+ 'hpa': ParameterizingProxyString(
+ (u'\x1b[{0}G', lambda *arg: (arg[0] + 1,)), term.normal, attr),
+ 'vpa': ParameterizingProxyString(
+ (u'\x1b[{0}d', lambda *arg: (arg[0] + 1,)), term.normal, attr),
}
}.get(term_kind, {}).get(attr, None)
@@ -313,15 +317,16 @@ def resolve_attribute(term, attr):
resolution = (resolve_attribute(term, fmt) for fmt in formatters)
return FormattingString(u''.join(resolution), term.normal)
else:
- # and, for special terminals, such as 'screen', provide a Proxy
- # ParameterizingString for attributes they do not claim to support,
- # but actually do! (such as 'hpa' and 'vpa').
- proxy = get_proxy_string(term, term._sugar.get(attr, attr))
- if proxy is not None:
- return proxy
# otherwise, this is our end-game: given a sequence such as 'csr'
# (change scrolling region), return a ParameterizingString instance,
# that when called, performs and returns the final string after curses
# capability lookup is performed.
tparm_capseq = resolve_capability(term, attr)
+ if not tparm_capseq:
+ # and, for special terminals, such as 'screen', provide a Proxy
+ # ParameterizingString for attributes they do not claim to support,
+ # but actually do! (such as 'hpa' and 'vpa').
+ proxy = get_proxy_string(term, term._sugar.get(attr, attr))
+ if proxy is not None:
+ return proxy
return ParameterizingString(tparm_capseq, term.normal, attr)
diff --git a/blessed/tests/test_sequences.py b/blessed/tests/test_sequences.py
index ff010f7..7a14ba0 100644
--- a/blessed/tests/test_sequences.py
+++ b/blessed/tests/test_sequences.py
@@ -206,8 +206,8 @@ def test_vertical_location(all_standard_terms):
child(all_standard_terms)
-def test_inject_move_x_for_screen():
- """Test injection of hpa attribute for screen (issue #55)."""
+def test_inject_move_x():
+ """Test injection of hpa attribute for screen/ansi (issue #55)."""
@as_subprocess
def child(kind):
t = TestTerminal(kind=kind, stream=StringIO(), force_styling=True)
@@ -219,13 +219,15 @@ def test_inject_move_x_for_screen():
u'\x1b[{0}G'.format(COL + 1),
unicode_cap('rc')))
assert (t.stream.getvalue() == expected_output)
+ assert (t.move_x(COL) == u'\x1b[{0}G'.format(COL + 1))
child('screen')
child('screen-256color')
+ child('ansi')
-def test_inject_move_y_for_screen():
- """Test injection of vpa attribute for screen (issue #55)."""
+def test_inject_move_y():
+ """Test injection of vpa attribute for screen/ansi (issue #55)."""
@as_subprocess
def child(kind):
t = TestTerminal(kind=kind, stream=StringIO(), force_styling=True)
@@ -237,9 +239,11 @@ def test_inject_move_y_for_screen():
u'\x1b[{0}d'.format(ROW + 1),
unicode_cap('rc')))
assert (t.stream.getvalue() == expected_output)
+ assert (t.move_y(ROW) == u'\x1b[{0}d'.format(ROW + 1))
child('screen')
child('screen-256color')
+ child('ansi')
def test_inject_civis_and_cnorm_for_ansi():