Goal: In Python have a parent terminal start a program in a child pseudo-terminal (PTY), see its outputs and provide its inputs. At any given time, the parent terminal should be able to query what's on the child's screen at any character index
So in pseudocode the parent would do:
child_terminal = pty.openpty()
child_terminal.exec(my_program)
child_terminal.charAt(2, 4) # Returns "@"
child_terminal.submitInput("A")
child_terminal.charAt(2, 4) # Returns "!" now because the contents of the screen changed per the input submitted
Is this a workable task or is there something about command line rendering/state that makes it unfeasible? I thought it would be a common use case for scraping/automation but am not seeing much for this
There is nothing in the standard library that will do this.
"terminals" in the operating system do not know what a terminal type is. that is controlled by what is on the "other end" of the terminal - either the physical terminal device or the terminal emulator (such as xterm, putty, MacTerm, cmd, powershell, etc.)
To accomplish the task you're asking, you need to make sure the environment of the sub-program includes an appropriate terminal type, then interpret the output of the sub-program according to that terminal type to track what's on the screen, including translating terminal command codes into screen movements, scrolling where appropriate, etc. This is a decidedly non-trivial task.