Update terminalManagement
This commit is contained in:
parent
df88689942
commit
454af7a7c0
@ -32,7 +32,7 @@ class Terminal:
|
|||||||
return {"c": (cursor.x, cursor.y), "lines": lines}
|
return {"c": (cursor.x, cursor.y), "lines": lines}
|
||||||
|
|
||||||
|
|
||||||
def open_terminal(command="bash", columns=25, lines=80):
|
def open_terminal(command="bash", columns=80, lines=25):
|
||||||
p_pid, master_fd = pty.fork()
|
p_pid, master_fd = pty.fork()
|
||||||
print('PID',p_pid)
|
print('PID',p_pid)
|
||||||
if p_pid == 0: # Child.
|
if p_pid == 0: # Child.
|
||||||
@ -51,6 +51,7 @@ def HandleTerminal():
|
|||||||
try:
|
try:
|
||||||
tty.setraw(0)
|
tty.setraw(0)
|
||||||
terminal, p_pid, p_out = open_terminal()
|
terminal, p_pid, p_out = open_terminal()
|
||||||
|
std_out = os.fdopen(sys.stdout.fileno(), "w+b", 0)
|
||||||
#termios.tcdrain(p_pid)
|
#termios.tcdrain(p_pid)
|
||||||
#termios.tcdrain(0)
|
#termios.tcdrain(0)
|
||||||
while running:
|
while running:
|
||||||
@ -62,12 +63,13 @@ def HandleTerminal():
|
|||||||
if debug:
|
if debug:
|
||||||
print('pre p_out')
|
print('pre p_out')
|
||||||
try:
|
try:
|
||||||
msgBytes = os.read(p_out.fileno(), 4)
|
msgBytes = read_all(p_out.fileno())
|
||||||
|
#msgBytes = p_out.read(65536)
|
||||||
|
#msgBytes = os.read(p_out.fileno(), 4)
|
||||||
#p_out.read(4096)
|
#p_out.read(4096)
|
||||||
except (EOFError, OSError):
|
except (EOFError, OSError):
|
||||||
running = False
|
running = False
|
||||||
#sys.exit(0)
|
#sys.exit(0)
|
||||||
terminal.feed(msgBytes)
|
|
||||||
os.write(sys.stdout.fileno(), msgBytes)
|
os.write(sys.stdout.fileno(), msgBytes)
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
#print(terminal.screen.display)
|
#print(terminal.screen.display)
|
||||||
@ -75,11 +77,11 @@ def HandleTerminal():
|
|||||||
print('after p_out')
|
print('after p_out')
|
||||||
if sys.stdin in r:
|
if sys.stdin in r:
|
||||||
if debug:
|
if debug:
|
||||||
print('pre stdin')
|
print('pre stdin')
|
||||||
msgBytes = os.read(sys.stdin.fileno(), 1)
|
msgBytes = read_all(sys.stdin.fileno())
|
||||||
terminal.feed(msgBytes)
|
#msgBytes = os.read(sys.stdin.fileno(), 1)
|
||||||
p_out.write(msgBytes)
|
terminal.feed(msgBytes)
|
||||||
p_out.flush()
|
os.write(p_out.fileno(), msgBytes)
|
||||||
if debug:
|
if debug:
|
||||||
print('after stdin')
|
print('after stdin')
|
||||||
except Exception as e: # Process died?
|
except Exception as e: # Process died?
|
||||||
@ -102,5 +104,20 @@ def resize_terminal(fd):
|
|||||||
rows, cols, _, _ = struct.unpack('hhhh', s)
|
rows, cols, _, _ = struct.unpack('hhhh', s)
|
||||||
return rows, cols
|
return rows, cols
|
||||||
|
|
||||||
|
def read_all(fd):
|
||||||
|
bytes = os.read(fd, 4096)
|
||||||
|
if bytes == b'':
|
||||||
|
raise EOFError
|
||||||
|
while has_more(fd):
|
||||||
|
data = os.read(fd, 4096)
|
||||||
|
if data == b'':
|
||||||
|
raise EOFError
|
||||||
|
bytes += data
|
||||||
|
return bytes
|
||||||
|
|
||||||
|
def has_more(fd):
|
||||||
|
r, w, e = select.select([fd], [], [], 0)
|
||||||
|
return (fd in r)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
HandleTerminal()
|
HandleTerminal()
|
||||||
|
Loading…
Reference in New Issue
Block a user