【发布时间】:2020-04-07 22:28:29
【问题描述】:
考虑以下程序:
from time import sleep
from threading import Thread
def speaker():
while True:
sleep(3)
print("[*]I'm speaking........")
if __name__ == "__main__":
my_speaker = Thread(target=speaker)
my_speaker.start()
while True:
msg = input("[Your message]>> ")
print("Your message: " + msg)
如果我没有在输入中输入任何内容,则输出('_' 是光标的位置):
[Your message]>> [*]I'm speaking........
[*]I'm speaking........
[*]I'm speaking........
[*]I'm speaking........
[*]I'm speaking........
[*]I'm speaking........
[*]I'm speaking........
_
我想显示的输出:
[*]I'm speaking........
[*]I'm speaking........
[*]I'm speaking........
[*]I'm speaking........
[*]I'm speaking........
[*]I'm speaking........
[*]I'm speaking........
[Your message]>> _
当 'speaker' 函数执行打印函数时,它应该执行以下步骤:
将当前行的文本移动到下一行
回到上一行的开头
执行打印
返回到下一行的末尾
我看了一下这里:https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences 我发现了一些有用的东西,比如能够使用 '\r' 返回到当前行的开头,但是我不想覆盖文本而是将其移到下一行。
有什么想法吗?
【问题讨论】:
标签: python multithreading ansi-escape