Avoid needing to initialize tty state in bootstrap scripts

This commit is contained in:
Kovid Goyal
2022-03-13 12:03:28 +05:30
parent 74f0057ec8
commit e1504c4775
5 changed files with 96 additions and 122 deletions

View File

@@ -194,6 +194,15 @@ class PTY:
self.screen = Screen(self.callbacks, rows, columns, scrollback, cell_width, cell_height, 0, self.callbacks)
self.received_bytes = b''
def turn_off_echo(self):
s = termios.tcgetattr(self.master_fd)
s[3] &= ~termios.ECHO
termios.tcsetattr(self.master_fd, termios.TCSANOW, s)
def is_echo_on(self):
s = termios.tcgetattr(self.master_fd)
return True if s[3] & termios.ECHO else False
def __del__(self):
if not self.is_child:
fd = self.master_fd

View File

@@ -156,6 +156,7 @@ copy --exclude */w.* d1
pty.wait_till(lambda: 'TSET={}'.format(tset.replace('$A', 'AAA')) in pty.screen_contents())
self.assertNotIn('COLORTERM', pty.screen_contents())
pty.wait_till(lambda: '/cwd' in pty.screen_contents())
self.assertTrue(pty.is_echo_on())
def test_ssh_bootstrap_with_different_launchers(self):
for launcher in self.all_possible_sh:
@@ -252,6 +253,7 @@ copy --exclude */w.* d1
open(os.path.join(home_dir, '.zshrc'), 'w').close()
cmd = wrap_bootstrap_script(script, sh)
pty = self.create_pty([launcher, '-c', ' '.join(cmd)], cwd=home_dir, env=env)
pty.turn_off_echo()
del cmd
if pre_data:
pty.write_buf = pre_data.encode('utf-8')