本文整理匯總了Python中tty.LFLAG屬性的典型用法代碼示例。如果您正苦於以下問題:Python tty.LFLAG屬性的具體用法?Python tty.LFLAG怎麽用?Python tty.LFLAG使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類tty
的用法示例。
在下文中一共展示了tty.LFLAG屬性的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __enter__
# 需要導入模塊: import tty [as 別名]
# 或者: from tty import LFLAG [as 別名]
def __enter__(self) -> None:
# NOTE: On os X systems, using pty.setraw() fails. Therefor we are using this:
try:
newattr = termios.tcgetattr(self.fileno)
except termios.error:
pass
else:
newattr[tty.LFLAG] = self._patch_lflag(newattr[tty.LFLAG])
newattr[tty.IFLAG] = self._patch_iflag(newattr[tty.IFLAG])
# VMIN defines the number of characters read at a time in
# non-canonical mode. It seems to default to 1 on Linux, but on
# Solaris and derived operating systems it defaults to 4. (This is
# because the VMIN slot is the same as the VEOF slot, which
# defaults to ASCII EOT = Ctrl-D = 4.)
newattr[tty.CC][termios.VMIN] = 1 # type: ignore
termios.tcsetattr(self.fileno, termios.TCSANOW, newattr)
# Put the terminal in cursor mode. (Instead of application mode.)
os.write(self.fileno, b"\x1b[?1l")
示例2: __enter__
# 需要導入模塊: import tty [as 別名]
# 或者: from tty import LFLAG [as 別名]
def __enter__(self):
# NOTE: On os X systems, using pty.setraw() fails. Therefor we are using this:
try:
newattr = termios.tcgetattr(self.fileno)
except termios.error:
pass
else:
newattr[tty.LFLAG] = self._patch_lflag(newattr[tty.LFLAG])
newattr[tty.IFLAG] = self._patch_iflag(newattr[tty.IFLAG])
# VMIN defines the number of characters read at a time in
# non-canonical mode. It seems to default to 1 on Linux, but on
# Solaris and derived operating systems it defaults to 4. (This is
# because the VMIN slot is the same as the VEOF slot, which
# defaults to ASCII EOT = Ctrl-D = 4.)
newattr[tty.CC][termios.VMIN] = 1
termios.tcsetattr(self.fileno, termios.TCSANOW, newattr)
# Put the terminal in cursor mode. (Instead of application mode.)
os.write(self.fileno, b'\x1b[?1l')
示例3: main
# 需要導入模塊: import tty [as 別名]
# 或者: from tty import LFLAG [as 別名]
def main(raw_args):
parser = argparse.ArgumentParser(
description="Use your keyboard as your phone's keyboard.")
logging_common.AddLoggingArguments(parser)
script_common.AddDeviceArguments(parser)
args = parser.parse_args(raw_args)
logging_common.InitializeLogging(args)
devices = script_common.GetDevices(args.devices, None)
if len(devices) > 1:
raise MultipleDevicesError(devices)
def next_char():
while True:
yield sys.stdin.read(1)
try:
fd = sys.stdin.fileno()
# See man 3 termios for more info on what this is doing.
old_attrs = termios.tcgetattr(fd)
new_attrs = copy.deepcopy(old_attrs)
new_attrs[tty.LFLAG] = new_attrs[tty.LFLAG] & ~(termios.ICANON)
new_attrs[tty.CC][tty.VMIN] = 1
new_attrs[tty.CC][tty.VTIME] = 0
termios.tcsetattr(fd, termios.TCSAFLUSH, new_attrs)
Keyboard(devices[0], next_char())
finally:
termios.tcsetattr(fd, termios.TCSAFLUSH, old_attrs)
return 0