ability to replace text

This commit is contained in:
Gabriel Falcão 2010-04-18 22:45:01 -03:00
parent 3b311e90ef
commit 9d3a8bd290
2 changed files with 10 additions and 1 deletions

View File

@ -36,6 +36,7 @@ class modifiers:
underline = ansify(4)
inverse = ansify(7)
strikethrough = ansify(9)
up = '\r\033[A'
class off:
bold = ansify(22)
@ -119,7 +120,7 @@ class Shell(object):
parts.append("\n")
string = "".join(parts)
return lambda z: sys.stdout.write(string % z)
return lambda z, replace=False: sys.stdout.write((replace and modifiers.up or '') + string % z)
def __getattr__(self, attr):

View File

@ -118,3 +118,11 @@ def test_bold_inline():
sh.print_bold_normal_on_red("World")
assert_stdout('\033[44m\033[1m\033[39mHello\033[0m\033[41m\033[1m\033[39mWorld\033[0m')
@with_setup(prepare_stdout)
def test_update_shell():
"updating the shell, replacing the last output"
sh = Shell(indent=6)
sh.print_yellow("Yellow")
sh.indent()
sh.print_red("Red", True)
assert_stdout('\033[33mYellow\033[0m\r\033[A \033[31mRed\033[0m')