issue #319: have cfsetraw() generate sensible flags.

Attempting to fix issue on WSL.

Closes #71
pull/326/head
David Wilson 6 years ago
parent 441c60a3ca
commit 56943d3141

@ -102,26 +102,23 @@ def is_immediate_child(msg, stream):
def flags(names): def flags(names):
"""Return the result of ORing a set of (space separated) :py:mod:`termios` """Return the result of ORing a set of (space separated) :py:mod:`termios`
module constants together.""" module constants together."""
return sum(getattr(termios, name) for name in names.split()) return sum(getattr(termios, name, 0)
for name in names.split())
def cfmakeraw(tflags): def cfmakeraw(tflags):
"""Given a list returned by :py:func:`termios.tcgetattr`, return a list """Given a list returned by :py:func:`termios.tcgetattr`, return a list
that has been modified in the same manner as the `cfmakeraw()` C library modified in a manner similar to the `cfmakeraw()` C library function, but
function.""" additionally disabling local echo."""
# BSD: https://github.com/freebsd/freebsd/blob/master/lib/libc/gen/termios.c#L162
# Linux: https://github.com/lattera/glibc/blob/master/termios/cfmakeraw.c#L20
iflag, oflag, cflag, lflag, ispeed, ospeed, cc = tflags iflag, oflag, cflag, lflag, ispeed, ospeed, cc = tflags
iflag &= ~flags('IGNBRK BRKINT PARMRK ISTRIP INLCR IGNCR ICRNL IXON') iflag &= ~flags('IMAXBEL IXOFF INPCK BRKINT PARMRK ISTRIP INLCR ICRNL IXON IGNPAR')
oflag &= ~flags('OPOST IXOFF') iflag &= ~flags('IGNBRK BRKINT PARMRK')
lflag &= ~flags('ECHO ECHOE ECHONL ICANON ISIG IEXTEN') oflag &= ~flags('OPOST')
lflag &= ~flags('ECHO ECHOE ECHOK ECHONL ICANON ISIG IEXTEN NOFLSH TOSTOP PENDIN')
cflag &= ~flags('CSIZE PARENB') cflag &= ~flags('CSIZE PARENB')
cflag |= flags('CS8') cflag |= flags('CS8 CREAD')
# TODO: one or more of the above bit twiddles sets or omits a necessary
# flag. Forcing these fields to zero, as shown below, gets us what we want
# on Linux/OS X, but it is possibly broken on some other OS.
iflag = 0
oflag = 0
lflag = 0
return [iflag, oflag, cflag, lflag, ispeed, ospeed, cc] return [iflag, oflag, cflag, lflag, ispeed, ospeed, cc]

Loading…
Cancel
Save