• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python termios.tcgetattr函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中termios.tcgetattr函数的典型用法代码示例。如果您正苦于以下问题:Python tcgetattr函数的具体用法?Python tcgetattr怎么用?Python tcgetattr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了tcgetattr函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: __enter__

    def __enter__(self):
        # prepare standard file descriptors for raw manipulation
        self.was_blocking = os.get_blocking(0)
        os.set_blocking(0, False)
        try:
            self.terminal_attr_stdin = termios.tcgetattr(0)
            self.terminal_attr_stdout = termios.tcgetattr(1)
            self.terminal_attr_stderr = termios.tcgetattr(2)
            tty.setraw(0)
            tty.setraw(1)
            tty.setraw(2)
        except termios.error:  # probably redirected
            self.terminal_attr_stdin = None

        # redirect standard file descriptors to new PTY
        master, slave = pty.openpty()
        os.set_blocking(master, False)
        self.real_stdin = os.dup(0)
        self.real_stdout = os.dup(1)
        self.real_stderr = os.dup(2)
        os.close(0)
        os.close(1)
        os.close(2)
        os.dup2(slave, 0)
        os.dup2(slave, 1)
        os.dup2(slave, 2)
        os.close(slave)
        self.terminal_pipe = master

        # start REPL in separate thread
        threading.Thread(target=repl, args=(self,), daemon=True).start()

        return self
开发者ID:qsantos,项目名称:spyce,代码行数:33,代码来源:terminal.py


示例2: getch

def getch():
    "Returns a single character"
    if getch.platform is None:
        try:
            # Window's python?
            import msvcrt
            getch.platform = 'windows'
        except ImportError:
            # Fallback...
            try:
                import tty, termios
                fd = sys.stdin.fileno()
                old_settings = termios.tcgetattr(fd)
                getch.platform = 'unix'
            except termios.error:
                getch.platform = 'dumb'

    if getch.platform == 'windows':
        import msvcrt
        return msvcrt.getch()
    elif getch.platform == 'unix':
        import tty, termios
        fd = sys.stdin.fileno()
        old_settings = termios.tcgetattr(fd)
        try:
            tty.setraw(sys.stdin.fileno())
            ch = sys.stdin.read(1)
        finally:
            termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
        return ch
    else:
        return sys.stdin.read(1).strip().lower()
开发者ID:docwhat,项目名称:homedir,代码行数:32,代码来源:setup.py


示例3: setup

 def setup(self):
     self.old = termios.tcgetattr(self.fd)
     new = termios.tcgetattr(self.fd)
     new[3] = new[3] & ~termios.ICANON & ~termios.ECHO & ~termios.ISIG
     new[6][termios.VMIN] = 1
     new[6][termios.VTIME] = 0
     termios.tcsetattr(self.fd, termios.TCSANOW, new)
开发者ID:mullens,项目名称:khk-lights,代码行数:7,代码来源:miniterm.py


示例4: run

	def run(self):
		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:
			while not self.stopped():
				try:
					c = sys.stdin.read(16)


					for fn in self.registered_fns[c]:
						fn()
						# print "Called registered func %s for %s" % (fn,repr(c))
					#print 'Got char %s' % c



					if c == 'q':
						self.stop()

				except IOError: pass

				#time.sleep(.1)
		finally:
			termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm)
			fcntl.fcntl(fd, fcntl.F_SETFL, oldflags)
			print 'Keyboard handler stopped.'
开发者ID:topher515,项目名称:metropowall,代码行数:34,代码来源:walldriver.py


示例5: _make_eof_intr

def _make_eof_intr():
    """Set constants _EOF and _INTR.
    
    This avoids doing potentially costly operations on module load.
    """
    global _EOF, _INTR
    if (_EOF is not None) and (_INTR is not None):
        return

    # inherit EOF and INTR definitions from controlling process.
    try:
        from termios import VEOF, VINTR
        try:
            fd = sys.__stdin__.fileno()
        except ValueError:
            # ValueError: I/O operation on closed file
            fd = sys.__stdout__.fileno()
        intr = ord(termios.tcgetattr(fd)[6][VINTR])
        eof = ord(termios.tcgetattr(fd)[6][VEOF])
    except (ImportError, OSError, IOError, ValueError, termios.error):
        # unless the controlling process is also not a terminal,
        # such as cron(1), or when stdin and stdout are both closed.
        # Fall-back to using CEOF and CINTR. There
        try:
            from termios import CEOF, CINTR
            (intr, eof) = (CINTR, CEOF)
        except ImportError:
            #                         ^C, ^D
            (intr, eof) = (3, 4)
    
    _INTR = _byte(intr)
    _EOF = _byte(eof)
开发者ID:sccolbert,项目名称:ptyprocess,代码行数:32,代码来源:ptyprocess.py


示例6: warning

def warning(message, answer=None):
    """
    Print warning message into srdErr and may can for answer
    :param message: message
    :param answer: list of supported options. Default is first item.
    """
    c = ""
    sys.stderr.write("\n\x1b[92;01m%s " % message)
    if answer:
        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:
            while 1:
                try:
                    c = sys.stdin.read(1)
                    break
                except IOError:
                    pass
        finally:
            termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm)
            fcntl.fcntl(fd, fcntl.F_SETFL, oldflags)
        c = (u"%s" % c).lower()
    sys.stderr.write(" %s\x1b[39;49;00m\n\n" % c)
    if answer:
        for it in answer:
            if c in it:
                return c
        return answer.pop(0)
开发者ID:lhellebr,项目名称:5minute,代码行数:33,代码来源:vminute.py


示例7: input_loop

def input_loop(url_prefix):
    global plex_keys

    while True:
        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:        
            while 1:          
                try:
                    c = sys.stdin.read(3)
                    break
                except IOError:
                    time.sleep(0.1)  
                    pass
        finally:
            termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm)
            fcntl.fcntl(fd, fcntl.F_SETFL, oldflags)
            if c == 'q':
                clear()
                exit(0)
            elif c == '*':
                print "\n"
                change_defaults_i()
                del sys.argv[1:]
                main()
            elif c in plex_keys:
                urllib2.urlopen(url_prefix + plex_keys[c]).read()
开发者ID:SimSla,项目名称:plex-remote-keyboard,代码行数:35,代码来源:plex-remote-keyboard.py


示例8: wait_key

    def wait_key(message = ''):
        ''' Wait for a key press on the console and return it. '''
        if message != '':
            print (message)

        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
开发者ID:07101994,项目名称:AutonomousDrivingCookbook,代码行数:26,代码来源:AirSimClient.py


示例9: interact

 def interact(self):
   os.write(self.fd, self.readbuffer)
   old = termios.tcgetattr(self.fd)
   new = termios.tcgetattr(self.fd)
   new[3] = new[3] & ~termios.ECHO
   try:
     tty.setraw(self.fd)
     while True:
       try:
         rd, wd, ed = select.select([self.ptyfd, self.fd], [], [])
       except select.error as e:
         if e.args[0] == 4:
           continue
         else:
           raise
       for i in rd:
         if i == self.ptyfd:
           s = os.read(i, 1024)
           os.write(self.fd, s)
         elif i == self.fd:
           s = os.read(i, 1024)
           os.write(self.ptyfd, s)
   except OSError as e:
     if e.errno == 5:
       # 使用 print() 会导致下一个 Python 提示符位置不对
       os.write(self.fd, '已结束。\r\n'.encode())
     else:
       raise
   finally:
     termios.tcsetattr(self.fd, termios.TCSADRAIN, old)
开发者ID:JaHIY,项目名称:winterpy,代码行数:30,代码来源:expect3.py


示例10: __call__

    def __call__(self):
        import sys, termios, fcntl, os

        fd = sys.stdin.fileno()
        oldattr = termios.tcgetattr(fd)
        oldflags = fcntl.fcntl(fd, fcntl.F_GETFL)
        c = 0
        try:
            newattr = termios.tcgetattr(fd)
            newattr[3] = newattr[3] & ~termios.ICANON & ~termios.ECHO
            termios.tcsetattr(fd, termios.TCSANOW, newattr)
            fcntl.fcntl(fd, fcntl.F_SETFL, oldflags | os.O_NONBLOCK)

            while True:
                try:
                    c = sys.stdin.read(1)
                    break
                except IOError:
                    pass

        finally:
            termios.tcsetattr(fd, termios.TCSADRAIN, oldattr)
            fcntl.fcntl(fd, fcntl.F_SETFL, oldflags)

        return c
开发者ID:damaxwell,项目名称:siple,代码行数:25,代码来源:reporting.py


示例11: oldstat

def oldstat(pid, events, t, ann=None, norm=False, guest=False):
  evcmd = ",".join(events)
  if guest:
    cmd = "sudo perf kvm stat"
  else:
    cmd = "sudo perf stat"
  cmd += " -e {events} --log-fd 1 -x, -p {pid}".format(events=evcmd, pid=pid)
  pid, fd = pty.fork()
  if pid == 0:
    osexec(cmd)
  # fcntl.ioctl(fd, termios.TIOCSWINSZ, struct.pack("hhhh", 24, 80, 0, 0)) # resise terminal

  # disable echo
  flags = termios.tcgetattr(fd)
  flags[3] &= ~termios.ECHO
  termios.tcsetattr(fd, termios.TCSADRAIN, flags)

  time.sleep(t)
  ctrl_c = termios.tcgetattr(fd)[-1][termios.VINTR]  # get Ctrl+C character
  os.write(fd, ctrl_c)
  os.waitpid(pid, 0)
  raw = b""
  while True:
    try:
      chunk = os.read(fd, BUF_SIZE)
    except OSError:
      break
    if not chunk:
      break
    raw += chunk
  return PerfData(raw, ann=ann, norm=norm)
开发者ID:kopchik,项目名称:perftest,代码行数:31,代码来源:perftool.py


示例12: __del__

	def __del__(self):
		if self.LOGGING:
			# push any remaining output
			line = self.serial.readline()
			while line != "":
				print line,
				line = self.serial.readline()
                if AUTOTEST:
                        if self.quiet:
                                sys = __import__("sys")
                                termios = __import__("termios")
		else:
			if self.quiet:
				# for some reason, when our destructor is called sys and termios
				# are no longer available.  So we reimport them.
				sys = __import__("sys")
				termios = __import__("termios")
				fd = sys.stdin.fileno()
				old = termios.tcgetattr(fd)
				new = termios.tcgetattr(fd)
				new[3] = new[3] | termios.ECHO
				termios.tcsetattr(fd, termios.TCSADRAIN, new)

		self.serial.flushInput()
		self.serial.flushOutput()
		self.serial.close()
开发者ID:tomsparrow25,项目名称:wifisdk_for_wm,代码行数:26,代码来源:mtfterm.py


示例13: readKeys

def readKeys():
    """Waits for keyboard input and calls the method that is mapped to it."""
    fd = sys.stdin.fileno()

    oldterm = termios.tcgetattr(fd)
    newattr = termios.tcgetattr(fd)
    newattr[3] = newattr[3] & ~termios.ICANON & ~termios.ECHO # dont echo back
    termios.tcsetattr(fd, termios.TCSANOW, newattr)

    oldflags = fcntl.fcntl(fd, fcntl.F_GETFL)
    fcntl.fcntl(fd, fcntl.F_SETFL, oldflags | os.O_NONBLOCK)
    
    try:        
        while True:            
            try:
                key = sys.stdin.read(1)
                if key in control_keys.keys():
                    control_keys[key]()
                elif key == 'x':
                    pibot.stop()
                    sys.exit(0)
            except IOError: pass
    finally:
        termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm)
        fcntl.fcntl(fd, fcntl.F_SETFL, oldflags)
开发者ID:arudyk,项目名称:PiBot,代码行数:25,代码来源:kbd_controller.py


示例14: getChar

def getChar():
    """ 
    !! DOES NOT WORK, IF STDIN WAS "CLOSED" WITH EOF IN THE SAME PROCESS !!
    Stolen from:
    http://python4fun.blogspot.de/2008/06/get-key-press-in-python.html
    """
    if (os.name == "nt"):
        import msvcrt
        return msvcrt.getch()
    else:
        import termios, sys
        TERMIOS = termios
        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)
        c = None
        try:
            c = os.read(fd, 1)
        finally:
            termios.tcsetattr(fd, TERMIOS.TCSAFLUSH, old)
        return c
开发者ID:ooz,项目名称:ICFP2012,代码行数:25,代码来源:cli.py


示例15: getch

def getch():
  '''
  Get a character from stdin
  '''
  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:        
    while True:            
      try:
        c = sys.stdin.read(1)
        if c != "":
          break
      except IOError: pass


  finally:
    termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm)
    fcntl.fcntl(fd, fcntl.F_SETFL, oldflags)
  return c
开发者ID:jordanmng,项目名称:test,代码行数:27,代码来源:trie_shell.py


示例16: get_user_command

def get_user_command():
    '''
    Gets the command character from stdin, if any.

    @note
    This code is from/based on: http://docs.python.org/faq/library#how-do-i-get-a-single-keypress-at-a-time

    @return Character inputted by user. None if there isn't any.
    '''
    import termios, fcntl, sys, os
    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:
        try:
            c = sys.stdin.read(1)
            if c != '':
                return c
            else:
                return None
        except IOError:
            return None
    finally:
        termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm)
        fcntl.fcntl(fd, fcntl.F_SETFL, oldflags)
开发者ID:matcatc,项目名称:Timer,代码行数:32,代码来源:timer.py


示例17: getchar

def getchar(prompt, hidden=False, end='\n', timeout=None):
  '''读取一个字符'''
  import termios
  sys.stdout.write(prompt)
  sys.stdout.flush()
  fd = sys.stdin.fileno()

  def _read():
    if timeout is None:
      ch = sys.stdin.read(1)
    else:
      ch = _timed_read(sys.stdin, timeout)
    return ch

  if os.isatty(fd):
    old = termios.tcgetattr(fd)
    new = termios.tcgetattr(fd)
    if hidden:
      new[3] = new[3] & ~termios.ICANON & ~termios.ECHO
    else:
      new[3] = new[3] & ~termios.ICANON
    new[6][termios.VMIN] = 1
    new[6][termios.VTIME] = 0
    try:
      termios.tcsetattr(fd, termios.TCSANOW, new)
      termios.tcsendbreak(fd, 0)
      ch = _read()
    finally:
      termios.tcsetattr(fd, termios.TCSAFLUSH, old)
  else:
    ch = _read()

  sys.stdout.write(end)
  return ch
开发者ID:EvanHongYousan,项目名称:spiders-python,代码行数:34,代码来源:myutils.py


示例18: run_python_interpreter

def run_python_interpreter (local_dict):
    # Pass in the dictionary, for continuity from one session to the next.
    setquit()
    try:
        fd = sys.stdin.fileno();
        interacted = False
        if get_terminal_size(fd)[1] == 0:
            try:
                import termios
                old = termios.tcgetattr(fd)
                if old[3] & termios.ECHO:
                    # Need to turn off echoing and restore
                    new = termios.tcgetattr(fd)
                    new[3] = new[3] & ~termios.ECHO
                    try:
                        termios.tcsetattr(fd, termios.TCSADRAIN, new)
                        interacted = True
                        code.interact(banner="Python Interactive Interpreter. To exit, type 'quit()', 'exit()'.", readfunc=readfunc_stdio, local=local_dict)
                    finally:
                        termios.tcsetattr(fd, termios.TCSADRAIN, old)
            except:
                pass
            # Don't need to turn off echoing
            if not interacted:
                code.interact(banner="Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D.", readfunc=readfunc_stdio, local=local_dict)
        else:
            # We have a real interactive terminal
            code.interact(banner="Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D.", local=local_dict)
    except SystemExit as e:
        global g_builtin_override_called
        if not g_builtin_override_called:
            print('Script exited with %s' %(e))
开发者ID:2asoft,项目名称:freebsd,代码行数:32,代码来源:embedded_interpreter.py


示例19: echo_off

	def echo_off(self):
		self.oldterm = termios.tcgetattr(self.fd)
		self.newattr = termios.tcgetattr(self.fd)
		self.newattr[3] = self.newattr[3] & ~termios.ICANON & ~termios.ECHO
		termios.tcsetattr(self.fd, termios.TCSANOW, self.newattr)
		self.oldflags = fcntl.fcntl(self.fd, fcntl.F_GETFL)
		fcntl.fcntl(self.fd, fcntl.F_SETFL, self.oldflags | os.O_NONBLOCK)
开发者ID:CosmicPi,项目名称:cosmicpi-arduino,代码行数:7,代码来源:pi-server.py


示例20: __init__

    def __init__(self, slave=0, pid=os.getpid()):
        # apparently python GC's modules before class instances so, here
        # we have some hax to ensure we can restore the terminal state.
        self.termios, self.fcntl = termios, fcntl

        # open our controlling PTY
        self.pty  = open(os.readlink("/proc/%d/fd/%d" % (pid, slave)), "rb+")

        # store our old termios settings so we can restore after
        # we are finished
        self.oldtermios = termios.tcgetattr(self.pty)

        # get the current settings se we can modify them
        newattr = termios.tcgetattr(self.pty)

        # set the terminal to uncanonical mode and turn off
        # input echo.
        newattr[3] &= ~termios.ICANON & ~termios.ECHO

        # don't handle ^C / ^Z / ^\
        newattr[6][termios.VINTR] = '\x00'
        newattr[6][termios.VQUIT] = '\x00'
        newattr[6][termios.VSUSP] = '\x00'

        # set our new attributes
        termios.tcsetattr(self.pty, termios.TCSADRAIN, newattr)

        # store the old fcntl flags
        self.oldflags = fcntl.fcntl(self.pty, fcntl.F_GETFL)
        # fcntl.fcntl(self.pty, fcntl.F_SETFD, fcntl.FD_CLOEXEC)
        # make the PTY non-blocking
        fcntl.fcntl(self.pty, fcntl.F_SETFL, self.oldflags | os.O_NONBLOCK)
开发者ID:capnspacehook,项目名称:ShellPop,代码行数:32,代码来源:handlers.py



注:本文中的termios.tcgetattr函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python termios.tcsendbreak函数代码示例发布时间:2022-05-27
下一篇:
Python termios.tcflush函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap