Repository navigation
Conversation
|
This behavior occurs because stdout is not a terminal .. |
|
Old behavior: $ python2.7 -c 'from blessings import Terminal; term = Terminal(); print(term.move(1, 2))' > /tmp/z && cat /tmp/z With vitek's patch: $ python2.7 -c 'from blessings import Terminal; term = Terminal(); print(term.move(1, 2))' > /tmp/z && cat /tmp/z $ python2.7 -c 'from blessings import Terminal; term = Terminal(); print(term.clear())' > /tmp/z && cat /tmp/z $ python2.7 -c 'from blessings import Terminal; term = Terminal(); print(term.bold("woah dudes"))' > /tmp/z && cat /tmp/z So it seems fine to me. I guess the only place this would fail if multiple arguments were passed where the first argument is non-int. I don't think there is any such use-case. A test case ala the above would be kind. |
Sure, but blessings is supposed to work with a pipe as well as tty.
Not exactly, if it's called with noargs or multiple args it returns empty string. If it's called with one argument the logic is the same: return empty string on integer, argument the same otherwise.
Ok, I'll do it. |
|
I've added testcase. |
|
thats cool. maybe erik is not so busy doing real work that he can accept it :-) what i mean by the use of *args and then returning arg[0] explicitly is for whether TypeError is thrown, they are not in the case of multiple string arguments as they normally would be when a Terminal's _does_styling is True: $ python2.7 -c 'from blessings import Terminal; term = Terminal(); print(term.bold("1"))' > /tmp/z && cat /tmp/z $ python2.7 -c 'from blessings import Terminal; term = Terminal(); print(term.bold("1", "2"))' perhaps you could retain *args, but throw a TypeError manually if arg[0] is non-int and len(args) is greater than 1 ... or not, its a very trivial difference :-) |
|
Actually it's hard to catch. I don't like idea of raising exception it's a hack since def __call__(self, *args):
try:
# Re-encode the cap, because tparm() takes a bytestring in Python
# 3. However, appear to be a plain Unicode string otherwise so
# concats work.
parametrized = tparm(self.encode('utf-8'), *args).decode('utf-8')
return (parametrized if self._normal is None else
FormattingString(parametrized, self._normal))
except curses.error:
# Catch "must call (at least) setupterm() first" errors, as when
# running simply `nosetests` (without progressive) on nose-
# progressive. Perhaps the terminal has gone away between calling
# tigetstr and calling tparm.
return u''
except TypeError:
# If the first non-int (i.e. incorrect) arg was a string, suggest
# something intelligent:
if len(args) == 1 and isinstance(args[0], basestring):
raise TypeError(
'A native or nonexistent capability template received '
'%r when it was expecting ints. You probably misspelled a '
'formatting call like bright_red_on_white(...).' % args)
else:
# Somebody passed a non-string; I don't feel confident
# guessing what they were trying to do.
raiseBut may be you're right, it also raises |
|
Hi, guys! I'm following. I'll have a look in a day or two. |
|
Loading this back into my head now. It looks like only one of the assertions in your test was actually broken: |
There was a problem hiding this comment.
Calling a capability that doesn't take any params is a strange thing to do. Have you encountered a reason to do it? I lean toward not blessing it with support by doing it in a test.
There was a problem hiding this comment.
Sure I can use term.clear('') to clear screen and nothing more but I think that clear() with no arguments is much more convenient. Any way it works with tty version of blessings.
There was a problem hiding this comment.
eq_(t.clear, '') # that is, there is no need to call it
There was a problem hiding this comment.
Thanks, I missed that.
There was a problem hiding this comment.
Ah, now it fails. Thanks. :-) fix fix
|
Okay, loaded the last 4 decades of terminal legacy into my head. Geesh. 3 hours loading, 1 hour coding. :-) I think for now we'll take the inexpensive route and not raise TypeError. The ultimate solution, which I point to in a new TODO, is to retire the dual-purpose |
|
Looks like we have a fair number of minor fixes ready to go out. I'll probably let this bake in for a day and then cut a release. |
…s one actually fails before the #31 fix.
Yeah, that's a good idea) About my PR: you're right my it helps with |
|
The practical part of me agrees with you about making Blessings is, as its description string says, a thin wrapper around terminfo. That gives it a lot of flexibility: for example, @jquast was able to implement a sort of terminal server, resolving capabilities to strings remotely and then sending the bytestrings down to the client. If the server looked at However, I am constantly haunted by the fact that there's a demand for a higher abstraction layer. For example, it'd be great to support Windows, but there's just no terminal there to layer upon; we'd have to limit the API to higher-level primitives like In short, I think that higher abstraction layer is where an exception-throwing So I think, for now, we'll leave it to the user to check Thanks for being tolerant of my philosophizing! I hope I haven't scared you off, as your patches are significantly improving blessings, and I've been enjoying our exchanges. Even this monologue has helped clarify to me what out future directions should be. Cheers! |
|
Actually jquast would have been able to do his thing either way: move would have returned the right thing, since he told Terminal explicitly which term type to use. |
NullCallbableString() doesn't work with things like clear() and move(x, y). This patch fixes this behaviour: