Update terminalManagement
This commit is contained in:
parent
454af7a7c0
commit
5f554792f1
@ -37,7 +37,7 @@ def open_terminal(command="bash", columns=80, lines=25):
|
|||||||
print('PID',p_pid)
|
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=sys.stdout.encoding,
|
||||||
COLUMNS=str(columns), LINES=str(lines))
|
COLUMNS=str(columns), LINES=str(lines))
|
||||||
os.execvpe(argv[0], argv, env)
|
os.execvpe(argv[0], argv, env)
|
||||||
# File-like object for I/O with the child process aka command.
|
# File-like object for I/O with the child process aka command.
|
||||||
@ -49,6 +49,7 @@ def HandleTerminal():
|
|||||||
running = True
|
running = True
|
||||||
#attr = termios.tcgetattr(sys.stdin.fileno())
|
#attr = termios.tcgetattr(sys.stdin.fileno())
|
||||||
try:
|
try:
|
||||||
|
old_attr = termios.tcgetattr(sys.stdin)
|
||||||
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)
|
std_out = os.fdopen(sys.stdout.fileno(), "w+b", 0)
|
||||||
@ -69,6 +70,7 @@ def HandleTerminal():
|
|||||||
#p_out.read(4096)
|
#p_out.read(4096)
|
||||||
except (EOFError, OSError):
|
except (EOFError, OSError):
|
||||||
running = False
|
running = False
|
||||||
|
break
|
||||||
#sys.exit(0)
|
#sys.exit(0)
|
||||||
os.write(sys.stdout.fileno(), msgBytes)
|
os.write(sys.stdout.fileno(), msgBytes)
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
@ -78,7 +80,14 @@ def HandleTerminal():
|
|||||||
if sys.stdin in r:
|
if sys.stdin in r:
|
||||||
if debug:
|
if debug:
|
||||||
print('pre stdin')
|
print('pre stdin')
|
||||||
msgBytes = read_all(sys.stdin.fileno())
|
try:
|
||||||
|
msgBytes = read_all(sys.stdin.fileno())
|
||||||
|
#msgBytes = p_out.read(65536)
|
||||||
|
#msgBytes = os.read(p_out.fileno(), 4)
|
||||||
|
#p_out.read(4096)
|
||||||
|
except (EOFError, OSError):
|
||||||
|
running = False
|
||||||
|
break
|
||||||
#msgBytes = os.read(sys.stdin.fileno(), 1)
|
#msgBytes = os.read(sys.stdin.fileno(), 1)
|
||||||
terminal.feed(msgBytes)
|
terminal.feed(msgBytes)
|
||||||
os.write(p_out.fileno(), msgBytes)
|
os.write(p_out.fileno(), msgBytes)
|
||||||
@ -90,7 +99,8 @@ def HandleTerminal():
|
|||||||
finally:
|
finally:
|
||||||
#termios.tcsetattr(0, termios.TCSADRAIN, attr)
|
#termios.tcsetattr(0, termios.TCSADRAIN, attr)
|
||||||
os.kill(p_pid, signal.SIGTERM)
|
os.kill(p_pid, signal.SIGTERM)
|
||||||
p_out.close()
|
p_out.close()
|
||||||
|
termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_attr)
|
||||||
|
|
||||||
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