kcsaff / getkey

MIT License
41 stars 18 forks source link

Output is messed after key capture in Linux #12

Open malversan opened 4 years ago

malversan commented 4 years ago

Using tty.setcbreak() messes output after key capture, leaving console echo permanently deactivated onwards.

This can be avoided by touching only the necessary tty terminal flags instead of calling tty.setbreak().

So in PlatformUnix.context(), instead of doing this:

        old_settings = self.termios.tcgetattr(fd)
        self.tty.setcbreak(fd)

this works better and without unwanted effects:

        old_settings = self.termios.tcgetattr(fd)
        raw_settings = old_settings.copy()
        raw_settings[self.tty.LFLAG] = raw_settings[self.tty.LFLAG] & ~(self.termios.ECHO | self.termios.ICANON | self.termios.ISIG)
        self.termios.tcsetattr(fd, self.termios.TCSADRAIN, raw_settings)

Tested in: Ubuntu 16.04 Python 3.5.2