I am writing a python application that is intended to be used interactively inside unix pipelines. The application should fire up a curses based terminal UI, and based on user interaction, write to the standard output only right before exiting.
Typical usage would be that of a typical pipeline:
foo_command | my_application | sink_app
The problem I am having is that python curses library sends all sorts of things to stdout while the app is running. Furthermore, sink_app
starts executing while my_application
is running.
- How to I prevent curses from polluting stdout?
- How do I buffer the output and control when I want to flush it?
- Is it possible to control when
sink_app
starts executing and when it stops accepting input?
From what I gather, I need to save a reference to the stdout file descriptor so I can later write to it. And pass another fd (which one?) to ncurses. Supposedly through newterm(), but this isn't available on python curses binding.