|
|
|
@ -102,26 +102,23 @@ def is_immediate_child(msg, stream):
|
|
|
|
|
def flags(names):
|
|
|
|
|
"""Return the result of ORing a set of (space separated) :py:mod:`termios`
|
|
|
|
|
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):
|
|
|
|
|
"""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
|
|
|
|
|
function."""
|
|
|
|
|
modified in a manner similar to the `cfmakeraw()` C library function, but
|
|
|
|
|
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 &= ~flags('IGNBRK BRKINT PARMRK ISTRIP INLCR IGNCR ICRNL IXON')
|
|
|
|
|
oflag &= ~flags('OPOST IXOFF')
|
|
|
|
|
lflag &= ~flags('ECHO ECHOE ECHONL ICANON ISIG IEXTEN')
|
|
|
|
|
iflag &= ~flags('IMAXBEL IXOFF INPCK BRKINT PARMRK ISTRIP INLCR ICRNL IXON IGNPAR')
|
|
|
|
|
iflag &= ~flags('IGNBRK BRKINT PARMRK')
|
|
|
|
|
oflag &= ~flags('OPOST')
|
|
|
|
|
lflag &= ~flags('ECHO ECHOE ECHOK ECHONL ICANON ISIG IEXTEN NOFLSH TOSTOP PENDIN')
|
|
|
|
|
cflag &= ~flags('CSIZE PARENB')
|
|
|
|
|
cflag |= flags('CS8')
|
|
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
cflag |= flags('CS8 CREAD')
|
|
|
|
|
return [iflag, oflag, cflag, lflag, ispeed, ospeed, cc]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|