本文整理汇总了Python中termios.TCSAFLUSH属性的典型用法代码示例。如果您正苦于以下问题:Python termios.TCSAFLUSH属性的具体用法?Python termios.TCSAFLUSH怎么用?Python termios.TCSAFLUSH使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类termios
的用法示例。
在下文中一共展示了termios.TCSAFLUSH属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import termios [as 别名]
# 或者: from termios import TCSAFLUSH [as 别名]
def __init__(self):
'''Creates a KBHit object that you can call to do various keyboard things.
'''
if os.name == 'nt':
pass
else:
# Save the terminal settings
self.fd = sys.stdin.fileno()
self.new_term = termios.tcgetattr(self.fd)
self.old_term = termios.tcgetattr(self.fd)
# New terminal setting unbuffered
self.new_term[3] = (self.new_term[3] & ~termios.ICANON & ~termios.ECHO)
termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.new_term)
# Support normal-terminal reset at exit
atexit.register(self.set_normal_term)
示例2: __init__
# 需要导入模块: import termios [as 别名]
# 或者: from termios import TCSAFLUSH [as 别名]
def __init__(self):
'''Creates a KBHit object that you can call to do various keyboard things.
'''
if os.name == 'nt':
pass
else:
# Save the terminal settings
self.fd = sys.stdin.fileno()
self.new_term = termios.tcgetattr(self.fd)
self.old_term = termios.tcgetattr(self.fd)
# New terminal setting unbuffered
self.new_term[3] = (self.new_term[3] & ~termios.ICANON & ~termios.ECHO)
termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.new_term)
# Support normal-terminal reset at exit
atexit.register(self.set_normal_term)
示例3: wait_key
# 需要导入模块: import termios [as 别名]
# 或者: from termios import TCSAFLUSH [as 别名]
def wait_key():
""" Wait for a key press on the console and return it. """
result = None
if os.name == 'nt':
result = input("Press Enter to continue...")
else:
import termios
fd = sys.stdin.fileno()
oldterm = termios.tcgetattr(fd)
newattr = termios.tcgetattr(fd)
newattr[3] = newattr[3] & ~termios.ICANON & ~termios.ECHO
termios.tcsetattr(fd, termios.TCSANOW, newattr)
try:
result = sys.stdin.read(1)
except IOError:
pass
finally:
termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm)
return result
示例4: getch
# 需要导入模块: import termios [as 别名]
# 或者: from termios import TCSAFLUSH [as 别名]
def getch():
"""getch function
"""
fd = sys.stdin.fileno()
old = termios.tcgetattr(fd)
new = termios.tcgetattr(fd)
new[3] = new[3] & ~termios.ICANON & ~termios.ECHO
new[6][termios.VMIN] = 1
new[6][termios.VTIME] = 0
termios.tcsetattr(fd, termios.TCSANOW, new)
key = None
try:
key = os.read(fd, 80)
finally:
termios.tcsetattr(fd, termios.TCSAFLUSH, old)
return key
示例5: getch
# 需要导入模块: import termios [as 别名]
# 或者: from termios import TCSAFLUSH [as 别名]
def getch():
"""Make a get character keyboard method for Posix machines.
"""
fd = sys.stdin.fileno()
old = termios.tcgetattr(fd)
new = termios.tcgetattr(fd)
new[3] = new[3] & ~termios.ICANON & ~termios.ECHO
new[6][termios.VMIN] = 1
new[6][termios.VTIME] = 0
termios.tcsetattr(fd, termios.TCSANOW, new)
key = None
try:
key = os.read(fd, 4)
finally:
termios.tcsetattr(fd, termios.TCSAFLUSH, old)
return key
示例6: raw
# 需要导入模块: import termios [as 别名]
# 或者: from termios import TCSAFLUSH [as 别名]
def raw(self):
"""Return a context manager that enters *raw* mode. Raw mode is
similar to *cbreak* mode, in that characters typed are immediately
available to ``inkey()`` with one exception: the interrupt, quit,
suspend, and flow control characters are all passed through as their
raw character values instead of generating a signal.
"""
if self.keyboard_fd is not None:
# save current terminal mode,
save_mode = termios.tcgetattr(self.keyboard_fd)
tty.setraw(self.keyboard_fd, termios.TCSANOW)
try:
yield
finally:
# restore prior mode,
termios.tcsetattr(self.keyboard_fd,
termios.TCSAFLUSH,
save_mode)
else:
yield
示例7: wait_key
# 需要导入模块: import termios [as 别名]
# 或者: from termios import TCSAFLUSH [as 别名]
def wait_key():
''' Wait for a key press on the console and return it. '''
result = None
if os.name == 'nt':
import msvcrt
result = msvcrt.getch()
else:
import termios
fd = sys.stdin.fileno()
oldterm = termios.tcgetattr(fd)
newattr = termios.tcgetattr(fd)
newattr[3] = newattr[3] & ~termios.ICANON & ~termios.ECHO
termios.tcsetattr(fd, termios.TCSANOW, newattr)
try:
result = sys.stdin.read(1)
except IOError:
pass
finally:
termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm)
return result
示例8: __init__
# 需要导入模块: import termios [as 别名]
# 或者: from termios import TCSAFLUSH [as 别名]
def __init__(self, is_gui=False):
self.is_gui = is_gui
if os.name == "nt" or self.is_gui:
pass
else:
# Save the terminal settings
self.file_desc = sys.stdin.fileno()
self.new_term = termios.tcgetattr(self.file_desc)
self.old_term = termios.tcgetattr(self.file_desc)
# New terminal setting unbuffered
self.new_term[3] = (self.new_term[3] & ~termios.ICANON & ~termios.ECHO)
termios.tcsetattr(self.file_desc, termios.TCSAFLUSH, self.new_term)
# Support normal-terminal reset at exit
atexit.register(self.set_normal_term)
示例9: SetTerminalRaw
# 需要导入模块: import termios [as 别名]
# 或者: from termios import TCSAFLUSH [as 别名]
def SetTerminalRaw(fd, restore=False):
"""Set controlling terminal to raw mode.
Set controlling terminal to raw mode and, if requested, register an
exit handler to restore controlling terminal attribute on exit.
Args:
fd: file descriptor of the controlling terminal.
restore: whether terminal mode should be restored on exit
Returns:
None.
"""
if restore:
when = termios.TCSAFLUSH
orig_attr = termios.tcgetattr(fd)
atexit.register(lambda: termios.tcsetattr(fd, when, orig_attr))
tty.setraw(fd)
示例10: cleanup_console
# 需要导入模块: import termios [as 别名]
# 或者: from termios import TCSAFLUSH [as 别名]
def cleanup_console():
if old:
termios.tcsetattr(fd, termios.TCSAFLUSH, old)
示例11: raw
# 需要导入模块: import termios [as 别名]
# 或者: from termios import TCSAFLUSH [as 别名]
def raw(self):
r"""
A context manager for :func:`tty.setraw`.
Although both :meth:`break` and :meth:`raw` modes allow each keystroke
to be read immediately after it is pressed, Raw mode disables
processing of input and output.
In cbreak mode, special input characters such as ``^C`` or ``^S`` are
interpreted by the terminal driver and excluded from the stdin stream.
In raw mode these values are receive by the :meth:`inkey` method.
Because output processing is not done, the newline ``'\n'`` is not
enough, you must also print carriage return to ensure that the cursor
is returned to the first column::
with term.raw():
print("printing in raw mode", end="\r\n")
"""
if HAS_TTY and self._keyboard_fd is not None:
# Save current terminal mode:
save_mode = termios.tcgetattr(self._keyboard_fd)
save_line_buffered = self._line_buffered
tty.setraw(self._keyboard_fd, termios.TCSANOW)
try:
self._line_buffered = False
yield
finally:
# Restore prior mode:
termios.tcsetattr(self._keyboard_fd,
termios.TCSAFLUSH,
save_mode)
self._line_buffered = save_line_buffered
else:
yield
示例12: cleanup
# 需要导入模块: import termios [as 别名]
# 或者: from termios import TCSAFLUSH [as 别名]
def cleanup(self):
termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.old)
示例13: pause
# 需要导入模块: import termios [as 别名]
# 或者: from termios import TCSAFLUSH [as 别名]
def pause(secs):
fd = sys.stdin.fileno()
oldterm = termios.tcgetattr(fd)
newattr = termios.tcgetattr(fd)
newattr[3] = newattr[3] & ~termios.ICANON & ~termios.ECHO
termios.tcsetattr(fd, termios.TCSANOW, newattr)
oldflags = fcntl.fcntl(fd, fcntl.F_GETFL)
fcntl.fcntl(fd, fcntl.F_SETFL, oldflags | os.O_NONBLOCK)
try:
ctrlc = False
paused = False
t = secs / 0.1
i = 0
while i < t:
if keypressed():
paused = True
break
sleep(0.1)
i += 1
if paused:
while True:
if keypressed():
break
sleep(0.1)
except KeyboardInterrupt:
ctrlc = True
termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm)
fcntl.fcntl(fd, fcntl.F_SETFL, oldflags)
if ctrlc:
sys.exit(1)
示例14: main
# 需要导入模块: import termios [as 别名]
# 或者: from termios import TCSAFLUSH [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
示例15: cleanup
# 需要导入模块: import termios [as 别名]
# 或者: from termios import TCSAFLUSH [as 别名]
def cleanup(self):
if self.old is not None:
termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.old)