Clear和exit_fullscreen似乎不起作用

时间:2013-04-22 20:14:24

标签: python python-blessings

我开始玩祝福了 - 到目前为止,我很喜欢它,因为它确实让事情变得容易多了。 但是我试图清除屏幕但没有成功... enter_fullscreen似乎工作起来因为“清除”它 - 但exit_fullscreen并没有让我回到原始视图。

term = blessings.Terminal()
term.enter_fullscreen

with term.location():
    print(term.move(0,(term.width/2)-7) + term.bold_green("Test Test Test"))
    print(term.move(5,(term.width/2)-7) + term.bold_red("Test Test Test"))

time.sleep(5)
term.clear
term.exit_fullscreen

除了清除和exit_fullscreen之外,它的工作正常。没有错误消息或任何东西,它似乎什么也没做。

有谁知道它是如何工作的?

编辑:不是

term.clear

,也不

term.clear()

似乎有用......

EDIT2:

我几乎可以这样做,结果与上面相同。它可以进行着色和放置,但不会清除或其他任何内容。

term = blessings.Terminal()

with term.location():
    print(term.move(0,(term.width/2)-7) + term.bold_green("Test Test Test"))
    print(term.move(5,(term.width/2)-7) + term.bold_red("Test Test Test"))

2 个答案:

答案 0 :(得分:6)

正如祝福所揭示的所有其他能力一样,你必须print他们才能发挥作用。在幕后发生的事情是您的终端仿真器正在“监听”某些序列,然后它通过采取诸如切换到全屏模式的操作来响应。所以,在你的情况下,说print term.enter_fullscreen应该做的伎俩。如果您还有其他问题,请告诉我们!

答案 1 :(得分:1)

当我读完你的问题(我自己面对同一个问题)时,我意识到我忘记了所有term.some_formatting()次调用都返回了一个你必须打印的值。 clear函数只返回适当的转义序列。

如果你添加: print(term.clear()) 当你想要它清除它应该工作。

另外,我遇​​到了ex_fullscreen的问题,所以我使用了全屏的包装样式调用:

with term.fullscreen():
    a_function_or_some_code()

这应该在退出代码块时返回到您之前的状态。