Update terminalManagement
This commit is contained in:
parent
b0e920207e
commit
62d6583c66
@ -32,8 +32,9 @@ class Terminal:
|
|||||||
return {"c": (cursor.x, cursor.y), "lines": lines}
|
return {"c": (cursor.x, cursor.y), "lines": lines}
|
||||||
|
|
||||||
|
|
||||||
def open_terminal(command="bash", columns=80, lines=24):
|
def open_terminal(command="bash", columns=25, lines=80):
|
||||||
p_pid, master_fd = pty.fork()
|
p_pid, master_fd = pty.fork()
|
||||||
|
print('PID',p_pid)
|
||||||
if p_pid == 0: # Child.
|
if p_pid == 0: # Child.
|
||||||
argv = shlex.split(command)
|
argv = shlex.split(command)
|
||||||
env = dict(TERM="linux", LC_ALL="de_DE.UTF-8",
|
env = dict(TERM="linux", LC_ALL="de_DE.UTF-8",
|
||||||
@ -43,17 +44,6 @@ def open_terminal(command="bash", columns=80, lines=24):
|
|||||||
p_out = os.fdopen(master_fd, "w+b", 0)
|
p_out = os.fdopen(master_fd, "w+b", 0)
|
||||||
return Terminal(columns, lines, p_out), p_pid, p_out
|
return Terminal(columns, lines, p_out), p_pid, p_out
|
||||||
|
|
||||||
|
|
||||||
def convert_to_text(dump):
|
|
||||||
lines = dump['lines']
|
|
||||||
strLines = ''
|
|
||||||
for line in lines:
|
|
||||||
strLines += str(line[0])
|
|
||||||
for c in line[1]:
|
|
||||||
strLines += c[0]
|
|
||||||
return strLines
|
|
||||||
|
|
||||||
|
|
||||||
def HandleTerminal():
|
def HandleTerminal():
|
||||||
debug = False
|
debug = False
|
||||||
running = True
|
running = True
|
||||||
@ -64,29 +54,32 @@ def HandleTerminal():
|
|||||||
#termios.tcdrain(p_pid)
|
#termios.tcdrain(p_pid)
|
||||||
#termios.tcdrain(0)
|
#termios.tcdrain(0)
|
||||||
while running:
|
while running:
|
||||||
r, w, x = select.select([sys.stdin, p_out],[],[],0)
|
time.sleep(0.04)
|
||||||
|
r, w, x = select.select([sys.stdin, p_out],[],[])
|
||||||
if r == []:
|
if r == []:
|
||||||
continue
|
continue
|
||||||
if p_out in r:
|
if p_out in r:
|
||||||
if debug:
|
if debug:
|
||||||
print('pre p_out')
|
print('pre p_out')
|
||||||
try:
|
try:
|
||||||
msgBytes = os.read(p_out.fileno(), 4096)
|
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)
|
terminal.feed(msgBytes)
|
||||||
os.write(sys.stdout.fileno(), msgBytes)
|
os.write(sys.stdout.fileno(), msgBytes)
|
||||||
|
sys.stdout.flush()
|
||||||
#print(terminal.screen.display)
|
#print(terminal.screen.display)
|
||||||
if debug:
|
if debug:
|
||||||
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(), 4096)
|
msgBytes = os.read(sys.stdin.fileno(), 1)
|
||||||
terminal.feed(msgBytes)
|
terminal.feed(msgBytes)
|
||||||
p_out.write(msgBytes)
|
p_out.write(msgBytes)
|
||||||
|
p_out.flush()
|
||||||
if debug:
|
if debug:
|
||||||
print('after stdin')
|
print('after stdin')
|
||||||
except Exception as e: # Process died?
|
except Exception as e: # Process died?
|
||||||
@ -94,8 +87,8 @@ def HandleTerminal():
|
|||||||
running = False
|
running = False
|
||||||
finally:
|
finally:
|
||||||
#termios.tcsetattr(0, termios.TCSADRAIN, attr)
|
#termios.tcsetattr(0, termios.TCSADRAIN, attr)
|
||||||
p_out.close()
|
|
||||||
os.kill(p_pid, signal.SIGTERM)
|
os.kill(p_pid, signal.SIGTERM)
|
||||||
|
p_out.close()
|
||||||
|
|
||||||
def get_terminal_size(fd):
|
def get_terminal_size(fd):
|
||||||
s = struct.pack('HHHH', 0, 0, 0, 0)
|
s = struct.pack('HHHH', 0, 0, 0, 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user