[英]Python interactive console using curses lib getstr() function dosen't wait for user input
我正在嘗試使用curses lib創建一個交互式控制台。
與此類似:
import curses
if __name__ == '__main__':
stdscr = curses.initscr()
stdscr.nodelay(False)
curses.echo()
curses.nonl()
while True:
stdscr.addstr('#')
stdscr.refresh()
command = stdscr.getstr()
if not command:
continue
if command == b'xys':
stdscr.addstr('Execute xys block and print result')
elif command == b'qwe':
stdscr.addstr('Execute qwe block and print result')
# ...
但是它返回這個:
#xys
Execute xys block and print result#
#qwe
Execute qwe block and print result#
#
#
#
(在Execute qwe block and print result#
行之后,按enter
鍵)
stdscr.getstr()
函數僅等待輸入的一半時間。 另一半command = ''
無需任何輸入。 這就是為什么您在每個輸出的末尾看到雙#
號或#
號的原因。
預期結果應為:
#xys
Execute xys block and print result
#qwe
Execute qwe block and print result
#
有什么建議嗎?
我正在使用pyCharm終端(已選中run
> edit configurations...
> emulate terminal in output console
),但顯然curses lib和pyCharm不兼容。
在普通終端中運行腳本時,它可以完美運行。
希望這會對某人有所幫助!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.