本文整理汇总了Python中termios.ONLCR属性的典型用法代码示例。如果您正苦于以下问题:Python termios.ONLCR属性的具体用法?Python termios.ONLCR怎么用?Python termios.ONLCR使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类termios
的用法示例。
在下文中一共展示了termios.ONLCR属性的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import termios [as 别名]
# 或者: from termios import ONLCR [as 别名]
def __init__(self, height=25, width=80):
self.master, self.slave = pty.openpty()
if sys.version_info[:2] < (2, 7):
self.stdout = os.fdopen(self.slave, 'w', 1)
self.stdread = os.fdopen(self.master, 'r')
else:
self.stdout = io.open(self.slave, 'w', 1, encoding='UTF-8', newline='')
self.stdread = io.open(self.master, 'r', encoding='UTF-8', newline='\n')
# Make sure linefeed behavior is consistent between Python 2 and Python 3
termattrs = termios.tcgetattr(self.slave)
termattrs[1] = termattrs[1] & ~termios.ONLCR & ~termios.OCRNL
termattrs[0] = termattrs[0] & ~termios.ICRNL
termios.tcsetattr(self.slave, termios.TCSADRAIN, termattrs)
self.resize(height, width)
示例2: _configure_term_settings
# 需要导入模块: import termios [as 别名]
# 或者: from termios import ONLCR [as 别名]
def _configure_term_settings(pty_fd):
term_settings = termios.tcgetattr(pty_fd)
# ONLCR transforms NL to CR-NL, which is undesirable. Ensure this is disabled.
# http://man7.org/linux/man-pages/man3/termios.3.html
term_settings[1] &= ~termios.ONLCR
# ECHOCTL echoes control characters, which is undesirable.
term_settings[3] &= ~termios.ECHOCTL
termios.tcsetattr(pty_fd, termios.TCSANOW, term_settings)
示例3: __enter__
# 需要导入模块: import termios [as 别名]
# 或者: from termios import ONLCR [as 别名]
def __enter__(self) -> 'Pty':
self.r, self.w = openpty()
# tty flags normally change \n to \r\n
attrs = termios.tcgetattr(self.r)
assert isinstance(attrs[1], int)
attrs[1] &= ~(termios.ONLCR | termios.OPOST)
termios.tcsetattr(self.r, termios.TCSANOW, attrs)
return self
示例4: pty_normalize_newlines
# 需要导入模块: import termios [as 别名]
# 或者: from termios import ONLCR [as 别名]
def pty_normalize_newlines(fd):
r"""
Twiddle the tty flags such that \n won't get munged to \r\n.
Details:
https://docs.python.org/2/library/termios.html
http://ftp.gnu.org/old-gnu/Manuals/glibc-2.2.3/html_chapter/libc_17.html#SEC362
"""
import termios as T
attrs = T.tcgetattr(fd)
attrs[1] &= ~(T.ONLCR | T.OPOST)
T.tcsetattr(fd, T.TCSANOW, attrs)
示例5: configure_tty
# 需要导入模块: import termios [as 别名]
# 或者: from termios import ONLCR [as 别名]
def configure_tty(self) -> bytes:
"""We don't want \n to be replaced with \r\n, and we disable the echo"""
attr = termios.tcgetattr(self.fd)
# The following raises a mypy warning, as python type hints don't allow
# per list item granularity. The last item in attr is List[bytes], but
# we don't access that here.
attr[1] &= ~termios.ONLCR # type: ignore # oflag
attr[3] &= ~termios.ECHO # type: ignore # lflag
termios.tcsetattr(self.fd, termios.TCSANOW, attr)
# unsetopt zle prevents Zsh from resetting the tty
return b'unsetopt zle 2> /dev/null;stty -echo -onlcr -ctlecho;'