I'm trying to do an interactive console using the curses lib.
similar to this :
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')
# ...
But it return this :
#xys
Execute xys block and print result#
#qwe
Execute qwe block and print result#
#
#
#
(after the Execute qwe block and print result#
line I pressed the enter
key)
The stdscr.getstr()
function only wait for input half the time. The other half command = ''
without any input. This is why you see the double #
sign or the #
sign at the end of each output.
The expecting result should be :
#xys
Execute xys block and print result
#qwe
Execute qwe block and print result
#
Any recommendation ?