ability to replace text
This commit is contained in:
parent
3b311e90ef
commit
9d3a8bd290
|
@ -36,6 +36,7 @@ class modifiers:
|
||||||
underline = ansify(4)
|
underline = ansify(4)
|
||||||
inverse = ansify(7)
|
inverse = ansify(7)
|
||||||
strikethrough = ansify(9)
|
strikethrough = ansify(9)
|
||||||
|
up = '\r\033[A'
|
||||||
|
|
||||||
class off:
|
class off:
|
||||||
bold = ansify(22)
|
bold = ansify(22)
|
||||||
|
@ -119,7 +120,7 @@ class Shell(object):
|
||||||
parts.append("\n")
|
parts.append("\n")
|
||||||
|
|
||||||
string = "".join(parts)
|
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):
|
def __getattr__(self, attr):
|
||||||
|
|
|
@ -118,3 +118,11 @@ def test_bold_inline():
|
||||||
sh.print_bold_normal_on_red("World")
|
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')
|
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')
|
||||||
|
|
Loading…
Reference in New Issue