summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErik Rose <erik@mozilla.com>2011-11-29 13:18:12 -0800
committerErik Rose <erik@mozilla.com>2011-11-29 13:18:12 -0800
commit5e4486301e9fa5e0be1e27335ba315e72d51a664 (patch)
tree659b1e1cd51bcbff299b7da3ef81c9e691a9d1ed
parente7665f8209e417bf962e113cb26edc0b6d7e5802 (diff)
downloadblessings-5e4486301e9fa5e0be1e27335ba315e72d51a664.tar.gz
Get rid of reference cycle between Terminals and FormattingStrings. Closes #11.
-rw-r--r--blessings/__init__.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/blessings/__init__.py b/blessings/__init__.py
index c34ab81..5f43ae4 100644
--- a/blessings/__init__.py
+++ b/blessings/__init__.py
@@ -316,7 +316,7 @@ class FormattingString(unicode):
"""A Unicode string which can be called upon a piece of text to wrap it in formatting"""
def __new__(cls, formatting, term):
new = unicode.__new__(cls, formatting)
- new._term = term # TODO: Kill cycle.
+ new._normal = term.normal
return new
def __call__(self, text):
@@ -327,7 +327,7 @@ class FormattingString(unicode):
back to defaults. The return value is always a Unicode.
"""
- return self + text + self._term.normal
+ return self + text + self._normal
class NullCallableString(unicode):
@@ -390,4 +390,5 @@ class Location(object):
self.term.stream.write(self.term.move_y(self.y))
def __exit__(self, type, value, tb):
- self.term.stream.write(self.term.restore) # restore position
+ """Restore original cursor position."""
+ self.term.stream.write(self.term.restore)