sync pty driver
This commit is contained in:
parent
be19a67fcd
commit
152c4c2185
@ -80,6 +80,8 @@ class driver(screenDriver):
|
|||||||
screenDriver.__init__(self)
|
screenDriver.__init__(self)
|
||||||
self.signalPipe = os.pipe()
|
self.signalPipe = os.pipe()
|
||||||
self.p_out = None
|
self.p_out = None
|
||||||
|
self.terminal = None
|
||||||
|
self.p_pid = -1
|
||||||
signal.signal(signal.SIGWINCH, self.handleSigwinch)
|
signal.signal(signal.SIGWINCH, self.handleSigwinch)
|
||||||
def initialize(self, environment):
|
def initialize(self, environment):
|
||||||
self.env = environment
|
self.env = environment
|
||||||
@ -112,7 +114,7 @@ class driver(screenDriver):
|
|||||||
# respect timeout but wait a little bit of time to see if something more is here
|
# respect timeout but wait a little bit of time to see if something more is here
|
||||||
if (time.time() - starttime) >= timeout:
|
if (time.time() - starttime) >= timeout:
|
||||||
break
|
break
|
||||||
r = screen_utils.hasMoreWhat(fdList,0)
|
r = screen_utils.hasMoreWhat(fdList, 0.002)
|
||||||
hasmore = fd in r
|
hasmore = fd in r
|
||||||
if not hasmore:
|
if not hasmore:
|
||||||
break
|
break
|
||||||
@ -158,9 +160,9 @@ class driver(screenDriver):
|
|||||||
lines, columns = self.getTerminalSize(0)
|
lines, columns = self.getTerminalSize(0)
|
||||||
if self.command == '':
|
if self.command == '':
|
||||||
self.command = screen_utils.getShell()
|
self.command = screen_utils.getShell()
|
||||||
terminal, p_pid, self.p_out = self.openTerminal(columns, lines, self.command)
|
self.terminal, self.p_pid, self.p_out = self.openTerminal(columns, lines, self.command)
|
||||||
lines, columns = self.resizeTerminal(self.p_out)
|
lines, columns = self.resizeTerminal(self.p_out)
|
||||||
terminal.resize(lines, columns)
|
self.terminal.resize(lines, columns)
|
||||||
fdList = [sys.stdin, self.p_out, self.signalPipe[0]]
|
fdList = [sys.stdin, self.p_out, self.signalPipe[0]]
|
||||||
while active.value:
|
while active.value:
|
||||||
r, _, _ = select.select(fdList, [], [], 1)
|
r, _, _ = select.select(fdList, [], [], 1)
|
||||||
@ -171,18 +173,18 @@ class driver(screenDriver):
|
|||||||
if self.signalPipe[0] in r:
|
if self.signalPipe[0] in r:
|
||||||
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)
|
||||||
terminal.resize(lines, columns)
|
self.terminal.resize(lines, columns)
|
||||||
# output
|
# output
|
||||||
if self.p_out in r:
|
if self.p_out in r:
|
||||||
try:
|
try:
|
||||||
msgBytes = self.readAll(self.p_out.fileno(), timeout=0.2, interruptFd=sys.stdin)
|
msgBytes = self.readAll(self.p_out.fileno())
|
||||||
except (EOFError, OSError):
|
except (EOFError, OSError):
|
||||||
active.value = False
|
active.value = False
|
||||||
break
|
break
|
||||||
terminal.feed(msgBytes)
|
self.terminal.feed(msgBytes)
|
||||||
os.write(sys.stdout.fileno(), msgBytes)
|
os.write(sys.stdout.fileno(), msgBytes)
|
||||||
eventQueue.put({"Type":fenrirEventType.ScreenUpdate,
|
eventQueue.put({"Type":fenrirEventType.ScreenUpdate,
|
||||||
"Data":screen_utils.createScreenEventData(terminal.GetScreenContent())
|
"Data":screen_utils.createScreenEventData(self.terminal.GetScreenContent())
|
||||||
})
|
})
|
||||||
# input
|
# input
|
||||||
if sys.stdin in r:
|
if sys.stdin in r:
|
||||||
@ -204,7 +206,7 @@ class driver(screenDriver):
|
|||||||
print(e)
|
print(e)
|
||||||
active.value = False
|
active.value = False
|
||||||
finally:
|
finally:
|
||||||
os.kill(p_pid, signal.SIGTERM)
|
os.kill(self.p_pid, signal.SIGTERM)
|
||||||
self.p_out.close()
|
self.p_out.close()
|
||||||
termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_attr)
|
termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_attr)
|
||||||
eventQueue.put({"Type":fenrirEventType.StopMainLoop,"Data":None})
|
eventQueue.put({"Type":fenrirEventType.StopMainLoop,"Data":None})
|
||||||
|
Loading…
Reference in New Issue
Block a user