Update ptyDriver.py

This commit is contained in:
chrys 2019-08-20 10:51:54 +02:00 committed by GitHub
parent 9af6c410c8
commit a7a0ab0d86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -102,29 +102,29 @@ class driver(screenDriver):
self.env['screen']['autoIgnoreScreens'] = [] self.env['screen']['autoIgnoreScreens'] = []
self.env['general']['prevUser'] = getpass.getuser() self.env['general']['prevUser'] = getpass.getuser()
self.env['general']['currUser'] = getpass.getuser() self.env['general']['currUser'] = getpass.getuser()
def readAll(self, fd, timeout = 9999999, interruptFd = None, len = 8192): def readAll(self, fd, timeout = 1, interruptFd = None, len = 65536):
bytes = b'' valueBytes = b''
fdList = [] fdList = []
fdList += [fd] fdList += [fd]
if interruptFd: if interruptFd:
fdList += [interruptFd] fdList += [interruptFd]
starttime = time.time() starttime = time.time()
while True: while True:
# respect timeout but wait a little bit of time to see if something more is here r = screen_utils.hasMoreWhat(fdList, 0.0001)
if (time.time() - starttime) >= timeout: # nothing more to read
break if not fd in r:
r = screen_utils.hasMoreWhat(fdList, 0.002)
hasmore = fd in r
if not hasmore:
break
# exit on interrupt available
if interruptFd in r:
break break
data = os.read(fd, len) data = os.read(fd, len)
if data == b'': if data == b'':
raise EOFError raise EOFError
bytes += data valueBytes += data
return bytes # exit on interrupt available
if interruptFd in r:
break
# respect timeout but wait a little bit of time to see if something more is here
if (time.time() - starttime) >= timeout:
break
return valueBytes
def openTerminal(self, columns, lines, command): def openTerminal(self, columns, lines, command):
p_pid, master_fd = pty.fork() p_pid, master_fd = pty.fork()
if p_pid == 0: # Child. if p_pid == 0: # Child.
@ -173,18 +173,6 @@ class driver(screenDriver):
os.read(self.signalPipe[0], 1) os.read(self.signalPipe[0], 1)
lines, columns = self.resizeTerminal(self.p_out) lines, columns = self.resizeTerminal(self.p_out)
self.terminal.resize(lines, columns) self.terminal.resize(lines, columns)
# output
if self.p_out in r:
try:
msgBytes = self.readAll(self.p_out.fileno())
except (EOFError, OSError):
active.value = False
break
self.terminal.feed(msgBytes)
os.write(sys.stdout.fileno(), msgBytes)
eventQueue.put({"Type":fenrirEventType.ScreenUpdate,
"Data":screen_utils.createScreenEventData(self.terminal.GetScreenContent())
})
# input # input
if sys.stdin in r: if sys.stdin in r:
try: try:
@ -201,6 +189,18 @@ class driver(screenDriver):
else: else:
eventQueue.put({"Type":fenrirEventType.ByteInput, eventQueue.put({"Type":fenrirEventType.ByteInput,
"Data":msgBytes }) "Data":msgBytes })
# output
if self.p_out in r:
try:
msgBytes = self.readAll(self.p_out.fileno(), interruptFd=sys.stdin.fileno())
except (EOFError, OSError):
active.value = False
break
self.terminal.feed(msgBytes)
os.write(sys.stdout.fileno(), msgBytes)
eventQueue.put({"Type":fenrirEventType.ScreenUpdate,
"Data":screen_utils.createScreenEventData(self.terminal.GetScreenContent())
})
except Exception as e: # Process died? except Exception as e: # Process died?
print(e) print(e)
active.value = False active.value = False