I am trying to write a Python program, which show/edit text from stdin using curses. I cloud implement edit module, but I couldn't stdin as input.
How can I solve this problem?
import curses
def main(stdscr):
while key := stdscr.getkey():
stdscr.addstr(0, 0, key)
if __name__ == '__main__':
curses.wrapper(main)
echo "hello" | python edit.py
Traceback (most recent call last):
File "/path/to/edit.py", line 8, in <module>
curses.wrapper(main)
File "/path/to/.pyenv/versions/3.9.1/lib/python3.9/curses/__init__.py", line 94, in wrapper
return func(stdscr, *args, **kwds)
File "/path/to/edit.py", line 4, in main
while key := stdscr.getkey():
_curses.error: no input
And python edit.py
(without echo "hello") is successfully complete.