I am experimenting with Godot and CataclysmDDA. I think that the structure is:
CDDA ncurses <- (stdout + keys pressed ) -> python script <- (stdin + stdout, as api) -> Godot
But the scripts of proof of concept does not run fine…well I put the scripts:
the script to simulate ncurses:
#! /usr/bin/python3
import sys,os
import curses
def draw_menu(stdscr):
k = 0
while (k != ord('q')):
stdscr.clear()
height, width = stdscr.getmaxyx()
stdscr.addstr(0, 0, "HOLA {}".format(k))
stdscr.refresh()
k = stdscr.getch()
def main():
curses.wrapper(draw_menu)
if __name__ == "__main__":
main()
the script to analize the stdout and send keys (there are a lot of proofs disabled with comments):
#! /usr /bin/python3
"""
ps -A | grep cata
xdotool search --pid 3819
xdotool key --window 50331670 q
"""
"""
from subprocess import Popen, PIPE
#p = Popen('./test5.py', stdin=PIPE, stdout=PIPE, shell=True)
#p = Popen('./test5.py', shell=True)
p = Popen('./test2.py')
print(p.pid)
sleep(100)
# p.stdin.close()
# p.stdout.close()
# p.wait()
"""
# ~ import pexpect
# ~ child = pexpect.spawn("./test5.py")
# ~ child.send('a')
# ~ child.send('b')
# ~ child.interact()
# ~ import sys
# ~ import pexpect
# ~ child = pexpect.spawn('./test5.py', logfile=open("/tmp/file", "wb"))
# ~ child.logfile = open("/tmp/file", "wb")
# ~ child.expect(pexpect.EOF)
# ~ child.send('a')
# ~ child.send('q')
# ~ child.interact()
"""
https://stackoverflow.com/questions/2575528/simulating-key-press-event-using-python-for-linux
spawn
fout = file('output.txt', 'w') child.logfile = fout
"""
import sys
from time import sleep
import pexpect
child = pexpect.spawn('./test5.py')
child.logfile = open("/tmp/file", "wb")
sleep(2)
child.send('a')
print(child.read())
# ~ child.send('q')
Someone can help me.