Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/360.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
打字。我想你可能误解了窗口的诅咒的含义。它是终端屏幕上打印的窗口。因此,如果您打开了一个终端,并运行curses程序,它将位于同一个终端中,就像VIm一样。@legostrmtropr我想我可能有。我正在研究curses的函数,并在python测试中尝试它_Python_Text Editor - Fatal编程技术网

打字。我想你可能误解了窗口的诅咒的含义。它是终端屏幕上打印的窗口。因此,如果您打开了一个终端,并运行curses程序,它将位于同一个终端中,就像VIm一样。@legostrmtropr我想我可能有。我正在研究curses的函数,并在python测试中尝试它

打字。我想你可能误解了窗口的诅咒的含义。它是终端屏幕上打印的窗口。因此,如果您打开了一个终端,并运行curses程序,它将位于同一个终端中,就像VIm一样。@legostrmtropr我想我可能有。我正在研究curses的函数,并在python测试中尝试它,python,text-editor,Python,Text Editor,打字。我想你可能误解了窗口的诅咒的含义。它是终端屏幕上打印的窗口。因此,如果您打开了一个终端,并运行curses程序,它将位于同一个终端中,就像VIm一样。@legostrmtropr我想我可能有。我正在研究curses的函数,并在python测试中尝试它,它不像我以前看到的那样打开新窗口。也许我会再给“诅咒”一次机会。@JFA你是说闲人吗?空闲不是终端,因此当您尝试运行带有诅咒的东西时,它必须打开终端才能工作。但是如果你已经打开了一个终端,那么它会使用它。对,空闲。在我的代码中实现代码之前,我


打字。

我想你可能误解了窗口的
诅咒的含义。它是终端屏幕上打印的窗口。因此,如果您打开了一个终端,并运行
curses
程序,它将位于同一个终端中,就像VIm一样。@legostrmtropr我想我可能有。我正在研究curses的函数,并在python测试中尝试它,它不像我以前看到的那样打开新窗口。也许我会再给“诅咒”一次机会。@JFA你是说闲人吗?空闲不是终端,因此当您尝试运行带有
诅咒的东西时,它必须打开终端才能工作。但是如果你已经打开了一个终端,那么它会使用它。对,空闲。在我的代码中实现代码之前,我只使用IDLE测试代码片段,或者尝试新的库。是的,我昨晚玩了诅咒,这和玩火没什么不同,但我认为这就是我要找的。@JFA库之所以被称为
诅咒
:你通常在使用它时诅咒整个世界!它没有一个用户友好的API。它也是很久以前写的,当时终端和计算机图形速度很慢,因此很多API都是在考虑优化的情况下编写的,这在您需要时非常棒,但在常见情况下会使一切变得更加复杂。有没有办法创建一个安全文件来还原我的终端,以用于
诅咒
?我一直在用一个不回音也不打印的终端。另外,
curses
是否必须清除屏幕,或者它是否可以在输入后的一小段中工作。@JFA您应该记得调用
curses.endwin()
。如果中止应用程序(例如,使用
Ctrl+C
),则可能会出现这种情况。为了避免这种情况,您可以捕获
键盘中断
,调用
curses.endwin()
,然后重新引发异常,或者添加一个。AFAIK
curses
仅在整个终端上工作。
curses
。。。如果是这样的话,它将做一些我试图避免的事情。这实际上是一个非常体面的包和非常体面的答案-除了它缺少处理箭头键-我已经让自己解决了这个小问题
import curses

screen = curses.initscr()
screen.addstr("Hello World!!!")
screen.refresh()
screen.getch()
curses.endwin()
python test_curses.py
# key_event_handler.py

import sys
import select
import pty
import os
import time
import fcntl
import tty
import termios
def __select( iwtd, owtd, ewtd, timeout=None):

   '''This is a wrapper around select.select() that ignores signals. If
   select.select raises a select.error exception and errno is an EINTR
   error then it is ignored. Mainly this is used to ignore sigwinch
   (terminal resize). '''

   # if select() is interrupted by a signal (errno==EINTR) then
   # we loop back and enter the select() again.
   if timeout is not None:
       end_time = time.time() + timeout
   while True:
       try:
           return select.select(iwtd, owtd, ewtd, timeout)
       except select.error:
           err = sys.exc_info()[1]
           if err.args[0] == errno.EINTR:
               # if we loop back we have to subtract the
               # amount of time we already waited.
               if timeout is not None:
                   timeout = end_time - time.time()
                   if timeout < 0:
                       return([], [], [])
           else:
               # something else caused the select.error, so
               # this actually is an exception.
               raise

STDIN_FILENO=pty.STDIN_FILENO
STDOUT_FILENO=pty.STDOUT_FILENO
string_type=bytes
sys.stdout.write(string_type())
sys.stdout.flush()
buffer = string_type()
mode = tty.tcgetattr(STDIN_FILENO)
tty.setraw(STDIN_FILENO)
try:
    while True:
        r, w, e = __select([STDIN_FILENO], [], [],timeout=1)
        if STDIN_FILENO in r:
            #It accepts all keys from keyboard 
            data=os.read(STDIN_FILENO, 1)
            #Bellow line returns ASCII value of a charector
            ascii_value=ord(data[0])
            ##########################################################################
            ##                      Your code goes here                             ## 
            ##                                                                      ##
            # Do some action here by matching the ASCII value                        #
            # you can handle your program by making use of special keys like         #
            # Backspace, Ctrl, Ctrl+A,Ctrl+B, Ctrl+C, ...Ctrl+Z, Esc,F1, ...,F12 ....#
            # Tab,Enter,Arrow keys,Alphabetic and Numeric keys are also supported    #  
            ##########################################################################
            #                                                                        #
            #To Print use bellow line rather than print or sys.stdout.write(data)    #
            #os.write(STDOUT_FILENO,data)                                            #
            ##                                                                       #
            ##########################################################################


finally:
    tty.tcsetattr(STDIN_FILENO, tty.TCSAFLUSH, mode) 
import sys

class _Getch:
   """Gets a single character from standard input.  Does not echo to the
screen."""
   def __init__(self):
      self.impl = _GetchUnix()

   def __call__(self):# return self.impl()
      charlist = []
      counter = 0
      for i in range(3):
         try:charlist.append(self.impl())
         except:pass
         if charlist[i] not in [chr(27),chr(91)]:#TODO sort out escape vs arrow duh use len()
            break
         if len(charlist) > 1:
            if charlist == [chr(27),chr(27)]:
               break
      if len(charlist) == 3:
         if charlist[2] == 'a'
            return 'u-arr'
         if charlist[2] == 'b'
            return 'd-arr'
         if charlist[2] == 'c'
            return 'r-arr'
         if charlist[2] == 'd'
            return 'l-arr'
      if len(charlist == 2):
         if charlist == [chr(27),chr(27)]
            return chr(27)
      if len(charlist == 1)
         return charlist[0]
      return ''

class _GetchUnix:
   def __init__(self):
      import tty, sys

   def __call__(self):
      import sys, 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
import click

key = click.getchar()
import click

click.echo('Continue? [yn] ', nl=False)
c = click.getchar()
click.echo()
if c == 'y':
    click.echo('We will go on')
elif c == 'n':
    click.echo('Abort!')
else:
    click.echo('Invalid input :(')
#!/usr/bin/python

import click

printable = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'

while True:
    click.echo('Continue? [yn] ', nl=False)
    c = click.getchar()
    click.echo()
    if c == 'y':
        click.echo('We will go on')
    elif c == 'n':
        click.echo('Abort!')
        break
    elif c == '\x1b[D':
        click.echo('Left arrow <-')
    elif c == '\x1b[C':
        click.echo('Right arrow ->')
    else:
        click.echo('Invalid input :(')
        click.echo('You pressed: "' + ''.join([ '\\'+hex(ord(i))[1:] if i not in printable else i for i in c ]) +'"' )
elif c == ??