cursesTerminal handling for character-cell displays字符单元显示的终端处理


The curses module provides an interface to the curses library, the de-facto standard for portable advanced terminal handling.curses模块为curses库提供接口,curses是便携式高级终端处理的事实标准。

While curses is most widely used in the Unix environment, versions are available for Windows, DOS, and possibly other systems as well. 虽然curses在Unix环境中使用最为广泛,但Windows、DOS和其他系统也可以使用curses版本。This extension module is designed to match the API of ncurses, an open-source curses library hosted on Linux and the BSD variants of Unix.此扩展模块设计用于匹配ncurses的API,这是一个托管在Linux和Unix的BSD变体上的开源curses库。

Note

Whenever the documentation mentions a character it can be specified as an integer, a one-character Unicode string or a one-byte byte string.只要文档提到一个字符,就可以将其指定为整数、单字符Unicode字符串或单字节字符串。

Whenever the documentation mentions a character string it can be specified as a Unicode string or a byte string.只要文档提到字符字符串,就可以将其指定为Unicode字符串或字节字符串。

Note

Since version 5.4, the ncurses library decides how to interpret non-ASCII data using the nl_langinfo function. 自版本5.4以来,ncurses库决定如何使用nl_langinfo函数解释非ASCII数据。That means that you have to call locale.setlocale() in the application and encode Unicode strings using one of the system’s available encodings. 这意味着您必须在应用程序中调用locale.setlocale(),并使用系统的一种可用编码对Unicode字符串进行编码。This example uses the system’s default encoding:此示例使用系统的默认编码:

import locale
locale.setlocale(locale.LC_ALL, '')
code = locale.getpreferredencoding()

Then use code as the encoding for str.encode() calls.然后使用code作为str.encode()调用的编码。

See also参阅

Module curses.ascii

Utilities for working with ASCII characters, regardless of your locale settings.用于处理ASCII字符的实用程序,无论您的语言环境设置如何。

Module curses.panel

A panel stack extension that adds depth to curses windows.一个面板堆栈扩展,可以增加窗口的深度。

Module curses.textpad

Editable text widget for curses supporting Emacs-like bindings.支持Emacs类绑定的可编辑文本小部件。

Curses Programming with Python用Python编程

Tutorial material on using curses with Python, by Andrew Kuchling and Eric Raymond.Andrew Kuchling和Eric Raymond编写的关于在Python中使用curses的教程材料。

The Tools/demo/ directory in the Python source distribution contains some example programs using the curses bindings provided by this module.Python源代码发行版中的Tools/demo/目录包含一些使用此模块提供的curses绑定的示例程序。

Functions函数

The module curses defines the following exception:模块curses定义了以下异常:

exceptioncurses.error

Exception raised when a curses library function returns an error.curses库函数返回错误时引发的异常。

Note

Whenever x or y arguments to a function or a method are optional, they default to the current cursor location. 每当函数或方法的xy参数是可选的时,它们默认为当前光标位置。Whenever attr is optional, it defaults to A_NORMAL.无论何时attr是可选的,它都默认为A_NORMAL

The module curses defines the following functions:模块curses定义了以下函数:

curses.baudrate()

Return the output speed of the terminal in bits per second. 返回终端的输出速度,单位为位/秒。On software terminal emulators it will have a fixed high value. 在软件终端模拟器上,它将具有固定的高值。Included for historical reasons; in former times, it was used to write output loops for time delays and occasionally to change interfaces depending on the line speed.由于历史原因而列入;在以前,它被用来写输出循环以获得时间延迟,偶尔也会根据线路速度改变接口。

curses.beep()

Emit a short attention sound.发出短暂的注意声。

curses.can_change_color()

Return True or False, depending on whether the programmer can change the colors displayed by the terminal.根据程序员是否可以更改终端显示的颜色,返回TrueFalse

curses.cbreak()

Enter cbreak mode. 进入cbreak模式。In cbreak mode (sometimes called “rare” mode) normal tty line buffering is turned off and characters are available to be read one by one. 在cbreak模式(有时称为“罕见”模式)下,关闭正常的tty行缓冲,可以逐个读取字符。However, unlike raw mode, special characters (interrupt, quit, suspend, and flow control) retain their effects on the tty driver and calling program. 但是,与原始模式不同,特殊字符(中断、退出、挂起和流控制)保留其对tty驱动程序和调用程序的影响。Calling first raw() then cbreak() leaves the terminal in cbreak mode.首先调用raw(),然后调用cbreak(),将使终端处于cbreak模式。

curses.color_content(color_number)

Return the intensity of the red, green, and blue (RGB) components in the color color_number, which must be between 0 and COLORS - 1. 返回颜色color_number中红色、绿色和蓝色(RGB)分量的强度,该值必须介于0COLORS-1之间。Return a 3-tuple, containing the R,G,B values for the given color, which will be between 0 (no component) and 1000 (maximum amount of component).返回一个3元组,包含给定颜色的R、G、B值,该值介于0(无分量)和1000(分量的最大量)之间。

curses.color_pair(pair_number)

Return the attribute value for displaying text in the specified color pair. 返回用于以指定颜色对显示文本的属性值。Only the first 256 color pairs are supported. 仅支持前256个颜色对。This attribute value can be combined with A_STANDOUT, A_REVERSE, and the other A_* attributes. 该属性值可以与A_STANDOUTA_REVERSE和其他A_*属性组合使用。pair_number() is the counterpart to this function.是此函数的对应项。

curses.curs_set(visibility)

Set the cursor state. 设置光标状态。visibility can be set to 0, 1, or 2, for invisible, normal, or very visible. visibility可以设置为012,用于不可见、正常或非常可见。If the terminal supports the visibility requested, return the previous cursor state; otherwise raise an exception. 如果终端支持所请求的可见性,则返回先前的光标状态;否则将引发异常。On many terminals, the “visible” mode is an underline cursor and the “very visible” mode is a block cursor.在许多终端上,“可见”模式为下划线光标,“非常可见”模式是块光标。

curses.def_prog_mode()

Save the current terminal mode as the “program” mode, the mode when the running program is using curses. 将当前终端模式保存为“程序”模式,即运行程序使用curses时的模式。(Its counterpart is the “shell” mode, for when the program is not in curses.) (它的对应模式是“shell”模式,用于程序不在curses中时。)Subsequent calls to reset_prog_mode() will restore this mode.reset_prog_mode()的后续调用将恢复此模式。

curses.def_shell_mode()

Save the current terminal mode as the “shell” mode, the mode when the running program is not using curses. 将当前终端模式保存为“shell”模式,即运行程序不使用Curse时的模式。(Its counterpart is the “program” mode, when the program is using curses capabilities.) (当程序使用curses功能时,它的对应模式是“程序”模式。)Subsequent calls to reset_shell_mode() will restore this mode.随后调用reset_shell_mode()将恢复此模式。

curses.delay_output(ms)

Insert an ms millisecond pause in output.在输出中插入ms毫秒暂停。

curses.doupdate()

Update the physical screen. 更新物理屏幕。The curses library keeps two data structures, one representing the current physical screen contents and a virtual screen representing the desired next state. curses库保留两个数据结构,一个表示当前物理屏幕内容,另一个表示所需下一个状态的虚拟屏幕。The doupdate() ground updates the physical screen to match the virtual screen.doupdate()地面更新物理屏幕以匹配虚拟屏幕。

The virtual screen may be updated by a noutrefresh() call after write operations such as addstr() have been performed on a window. 在窗口上执行addstr()等写入操作后,可以通过noutrefresh()调用来更新虚拟屏幕。The normal refresh() call is simply noutrefresh() followed by doupdate(); if you have to update multiple windows, you can speed performance and perhaps reduce screen flicker by issuing noutrefresh() calls on all windows, followed by a single doupdate().普通的refresh()调用简单地是noutrefresh()后跟doupdate();如果您必须更新多个窗口,可以通过在所有窗口上发出noutrefresh()调用,然后执行一次douupdate(),来提高性能并减少屏幕闪烁。

curses.echo()

Enter echo mode. 进入回声模式。In echo mode, each character input is echoed to the screen as it is entered.在回声模式下,输入的每个字符在输入时都会被回声到屏幕上。

curses.endwin()

De-initialize the library, and return terminal to normal status.取消初始化库,并将终端返回正常状态。

curses.erasechar()

Return the user’s current erase character as a one-byte bytes object. 将用户当前的擦除字符作为单字节字节对象返回。Under Unix operating systems this is a property of the controlling tty of the curses program, and is not set by the curses library itself.在Unix操作系统下,这是curses程序的控制tty的属性,而不是由curses库本身设置。

curses.filter()

The filter() routine, if used, must be called before initscr() is called. The effect is that, during those calls, LINES is set to 1; the capabilities clear, cup, cud, cud1, cuu1, cuu, vpa are disabled; and the home string is set to the value of cr. 如果使用了filter()例程,则必须在调用initscr()之前调用它。结果是,在这些调用期间,LINES被设置为1clearcupcudcud1cuu1cuuvpa功能被禁用;并且主字符串被设置为cr的值。The effect is that the cursor is confined to the current line, and so are screen updates. 其效果是游标被限制在当前行,屏幕更新也是如此。This may be used for enabling character-at-a-time line editing without touching the rest of the screen.这可用于在不触摸屏幕其余部分的情况下启用一次字符行编辑。

curses.flash()

Flash the screen. 闪烁屏幕。That is, change it to reverse-video and then change it back in a short interval. 也就是说,将其更改为反向视频,然后在短时间内将其更改回。Some people prefer such as ‘visible bell’ to the audible attention signal produced by beep().有些人更喜欢“可视铃声”而不是beep()产生的听觉注意信号。

curses.flushinp()

Flush all input buffers. 刷新所有输入缓冲区。This throws away any typeahead that has been typed by the user and has not yet been processed by the program.这会丢弃用户已键入但尚未由程序处理的任何提前键入。

curses.getmouse()

After getch() returns KEY_MOUSE to signal a mouse event, this method should be called to retrieve the queued mouse event, represented as a 5-tuple (id, x, y, z, bstate). getch()返回KEY_MOUSE以发出鼠标事件信号后,应调用此方法以检索排队的鼠标事件,表示为5元组(id, x, y, z, bstate)id is an ID value used to distinguish multiple devices, and x, y, z are the event’s coordinates. 是用于区分多个设备的ID值,xyz是事件的坐标。(z is currently unused.) z当前未使用。)bstate is an integer value whose bits will be set to indicate the type of event, and will be the bitwise OR of one or more of the following constants, where n is the button number from 1 to 5: BUTTONn_PRESSED, BUTTONn_RELEASED, BUTTONn_CLICKED, BUTTONn_DOUBLE_CLICKED, BUTTONn_TRIPLE_CLICKED, BUTTON_SHIFT, BUTTON_CTRL, BUTTON_ALT.bstate是一个整数值,其位将被设置为指示事件的类型,并且将是以下一个或多个常量的位“或”,其中n是从1到5的按钮编号:BUTTONn_PRESSEDBUTTONn_RELEASEDBUTTONn_CLICKEDBUTTONn_DOUBLE_CLICKEDBUTTONn_TRIPLE_CLICKEDBUTTTON_SHIFTBUTTENT_CTRLBUTTNT_ALT

Changed in version 3.10:版本3.10中更改: The BUTTON5_* constants are now exposed if they are provided by the underlying curses library.如果BUTTON5_*常量是由底层curses库提供的,则它们现在将公开。

curses.getsyx()

Return the current coordinates of the virtual screen cursor as a tuple (y, x). 将虚拟屏幕游标的当前坐标作为元组(y, x)返回。If leaveok is currently True, then return (-1, -1).如果leaveok当前为True,则返回(-1, -1)

curses.getwin(file)

Read window related data stored in the file by an earlier putwin() call. 通过先前的putwin()调用读取文件中存储的窗口相关数据。The routine then creates and initializes a new window using that data, returning the new window object.然后,该例程使用该数据创建并初始化新窗口,并返回新窗口对象。

curses.has_colors()

Return True if the terminal can display colors; otherwise, return False.如果终端可以显示颜色,则返回True;否则,返回False

curses.has_extended_color_support()

Return True if the module supports extended colors; otherwise, return False. 如果模块支持扩展颜色,则返回True;否则,返回FalseExtended color support allows more than 256 color pairs for terminals that support more than 16 colors (e.g. xterm-256color).扩展颜色支持允许支持16种以上颜色(例如xterm-256色)的终端使用256种以上的颜色对。

Extended color support requires ncurses version 6.1 or later.扩展颜色支持需要ncurses版本6.1或更高版本。

New in version 3.10.版本3.10中新增。

curses.has_ic()

Return True if the terminal has insert- and delete-character capabilities. 如果终端具有插入和删除字符功能,则返回TrueThis function is included for historical reasons only, as all modern software terminal emulators have such capabilities.由于所有现代软件终端仿真器都具有此类功能,因此仅出于历史原因才包含此功能。

curses.has_il()

Return True if the terminal has insert- and delete-line capabilities, or can simulate them using scrolling regions. 如果终端具有插入和删除行功能,或者可以使用滚动区域模拟它们,则返回TrueThis function is included for historical reasons only, as all modern software terminal emulators have such capabilities.由于所有现代软件终端仿真器都具有此类功能,因此仅出于历史原因才包含此功能。

curses.has_key(ch)

Take a key value ch, and return True if the current terminal type recognizes a key with that value.获取键值ch,如果当前终端类型识别出具有该值的键,则返回True

curses.halfdelay(tenths)

Used for half-delay mode, which is similar to cbreak mode in that characters typed by the user are immediately available to the program. 用于半延迟模式,与cbreak模式类似,用户键入的字符可立即用于程序。However, after blocking for tenths tenths of seconds, raise an exception if nothing has been typed. 但是,在阻塞十分之零点秒后,如果没有键入任何内容,则引发异常。The value of tenths must be a number between 1 and 255. 十分之一的值必须是介于1255之间的数字。Use nocbreak() to leave half-delay mode.使用nocbreak()离开半延迟模式。

curses.init_color(color_number, r, g, b)

Change the definition of a color, taking the number of the color to be changed followed by three RGB values (for the amounts of red, green, and blue components). 更改颜色的定义,取要更改的颜色编号,后跟三个RGB值(红色、绿色和蓝色分量的数量)。The value of color_number must be between 0 and COLORS - 1. color_number的值必须介于0COLORS-1之间。Each of r, g, b, must be a value between 0 and 1000. rgb中的每个值必须介于01000之间。When init_color() is used, all occurrences of that color on the screen immediately change to the new definition. 当使用init_color()时,屏幕上出现的所有颜色都会立即更改为新定义。This function is a no-op on most terminals; it is active only if can_change_color() returns True.该功能在大多数终端上都是无操作的;只有can_change_color()返回True时,它才处于活动状态。

curses.init_pair(pair_number, fg, bg)

Change the definition of a color-pair. 更改颜色对的定义。It takes three arguments: the number of the color-pair to be changed, the foreground color number, and the background color number. 它需要三个参数:要更改的颜色对的编号、前景颜色编号和背景颜色编号。The value of pair_number must be between 1 and COLOR_PAIRS - 1 (the 0 color pair is wired to white on black and cannot be changed). pair_number的值必须介于1COLOR_PAIRS-1之间(0颜色对连接为黑底白,无法更改)。The value of fg and bg arguments must be between 0 and COLORS - 1, or, after calling use_default_colors(), -1. fgbg参数的值必须介于0COLORS-1之间,或者在调用use_default_colors()后为-1If the color-pair was previously initialized, the screen is refreshed and all occurrences of that color-pair are changed to the new definition.如果颜色对之前已初始化,屏幕将刷新,并且该颜色对的所有出现都将更改为新定义。

curses.initscr()

Initialize the library. 初始化库。Return a window object which represents the whole screen.返回表示整个屏幕的窗口对象。

Note

If there is an error opening the terminal, the underlying curses library may cause the interpreter to exit.如果打开终端时出错,则底层curses库可能会导致解释器退出。

curses.is_term_resized(nlines, ncols)

Return True if resize_term() would modify the window structure, False otherwise.如果resize_term()将修改窗口结构,则返回True,否则返回False

curses.isendwin()

Return True if endwin() has been called (that is, the curses library has been deinitialized).如果已调用endwin()(即,curses库已被取消初始化),则返回True

curses.keyname(k)

Return the name of the key numbered k as a bytes object. 将编号为k的密钥的名称作为字节对象返回。The name of a key generating printable ASCII character is the key’s character. 生成可打印ASCII字符的密钥的名称是密钥的字符。The name of a control-key combination is a two-byte bytes object consisting of a caret (b'^') followed by the corresponding printable ASCII character. 控制键组合的名称是一个两字节字节的对象,由一个插入符号(b'^')后跟相应的可打印ASCII字符组成。The name of an alt-key combination (128–255) is a bytes object consisting of the prefix b'M-' followed by the name of the corresponding ASCII character.alt键组合的名称(128255)是一个字节对象,由前缀b'M-'和相应ASCII字符的名称组成。

curses.killchar()

Return the user’s current line kill character as a one-byte bytes object. 将用户当前的换行符作为一个单字节字节对象返回。Under Unix operating systems this is a property of the controlling tty of the curses program, and is not set by the curses library itself.在Unix操作系统下,这是curses程序的控制tty的属性,而不是由curses库本身设置的。

curses.longname()

Return a bytes object containing the terminfo long name field describing the current terminal. 返回包含描述当前终端的terminfo长名称字段的字节对象。The maximum length of a verbose description is 128 characters. 详细描述的最大长度为128个字符。It is defined only after the call to initscr().它仅在调用initscr()之后定义。

curses.meta(flag)

If flag is True, allow 8-bit characters to be input. 如果flagTrue,则允许输入8位字符。If flag is False, allow only 7-bit chars.如果flagFalse,则只允许7位字符。

curses.mouseinterval(interval)

Set the maximum time in milliseconds that can elapse between press and release events in order for them to be recognized as a click, and return the previous interval value. 设置按下和释放事件之间的最长时间(以毫秒为单位),以便将它们识别为单击,并返回上一个间隔值。The default value is 200 msec, or one fifth of a second.默认值为200毫秒或五分之一秒。

curses.mousemask(mousemask)

Set the mouse events to be reported, and return a tuple (availmask, oldmask). 设置要报告的鼠标事件,并返回一个元组(availmask, oldmask)availmask indicates which of the specified mouse events can be reported; on complete failure it returns 0. 指示可以报告哪些指定的鼠标事件;完全失败时返回0oldmask is the previous value of the given window’s mouse event mask. 是给定窗口的鼠标事件掩码的上一个值。If this function is never called, no mouse events are ever reported.如果从未调用此函数,则不会报告鼠标事件。

curses.napms(ms)

Sleep for ms milliseconds.休眠ms毫秒。

curses.newpad(nlines, ncols)

Create and return a pointer to a new pad data structure with the given number of lines and columns. 创建并返回指向具有给定行数和列数的新pad数据结构的游标。Return a pad as a window object.将衬垫作为窗口对象返回。

A pad is like a window, except that it is not restricted by the screen size, and is not necessarily associated with a particular part of the screen. 键盘就像一个窗口,只是它不受屏幕大小的限制,也不一定与屏幕的特定部分相关联。Pads can be used when a large window is needed, and only a part of the window will be on the screen at one time. 当需要一个大窗口时,可以使用pad,并且一次只有一部分窗口显示在屏幕上。Automatic refreshes of pads (such as from scrolling or echoing of input) do not occur. 不会自动刷新键盘(如滚动或回显输入)。The refresh() and noutrefresh() methods of a pad require 6 arguments to specify the part of the pad to be displayed and the location on the screen to be used for the display. pad的refresh()noutrefresh()方法需要6个参数来指定要显示的pad部分以及屏幕上用于显示的位置。The arguments are pminrow, pmincol, sminrow, smincol, smaxrow, smaxcol; the p arguments refer to the upper left corner of the pad region to be displayed and the s arguments define a clipping box on the screen within which the pad region is to be displayed.参数为pminrowpmincolsminrowsmincolsmaxrowsmaxcolp参数指的是要显示的焊盘区域的左上角,s参数定义屏幕上要显示焊盘区域所在的剪辑框。

curses.newwin(nlines, ncols)
curses.newwin(nlines, ncols, begin_y, begin_x)

Return a new window, whose left-upper corner is at (begin_y, begin_x), and whose height/width is nlines/ncols.返回一个新窗口,其左上角位于(begin_y, begin_x),高度/宽度为nlines/ncols

By default, the window will extend from the specified position to the lower right corner of the screen.默认情况下,窗口将从指定位置延伸到屏幕的右下角。

curses.nl()

Enter newline mode. 进入换行模式。This mode translates the return key into newline on input, and translates newline into return and line-feed on output. 该模式在输入时将return键转换为换行符,在输出时将换行符转换为return和换行符。Newline mode is initially on.换行模式最初处于打开状态。

curses.nocbreak()

Leave cbreak mode. Return to normal “cooked” mode with line buffering.离开cbreak模式。通过行缓冲返回到正常的“煮熟”模式。

curses.noecho()

Leave echo mode. Echoing of input characters is turned off.离开回声模式。关闭输入字符的回显。

curses.nonl()

Leave newline mode. Disable translation of return into newline on input, and disable low-level translation of newline into newline/return on output (but this does not change the behavior of addch('\n'), which always does the equivalent of return and line feed on the virtual screen). 保持换行模式。在输入时禁用将返回转换为换行符,并在输出时禁用将换行符转换为换行符/换行符的低级转换(但这不会改变addch('\n')的行为,它总是在虚拟屏幕上执行与换行符和换行符等效的操作)。With translation off, curses can sometimes speed up vertical motion a little; also, it will be able to detect the return key on input.关闭平移功能后,诅咒有时会加快垂直运动的速度;此外,它将能够在输入时检测返回键。

curses.noqiflush()

When the noqiflush() routine is used, normal flush of input and output queues associated with the INTR, QUIT and SUSP characters will not be done. 当使用noqiflush()例程时,将不会执行与INTRQUITSUSP字符相关联的输入和输出队列的正常刷新。You may want to call noqiflush() in a signal handler if you want output to continue as though the interrupt had not occurred, after the handler exits.如果希望在处理程序退出后继续输出,就像中断没有发生一样,您可能需要在信号处理程序中调用noqiflush()

curses.noraw()

Leave raw mode. 保持原始模式。Return to normal “cooked” mode with line buffering.通过行缓冲返回到正常的“煮熟”模式。

curses.pair_content(pair_number)

Return a tuple (fg, bg) containing the colors for the requested color pair. 返回包含所请求颜色对的颜色的元组(fg, bg)The value of pair_number must be between 0 and COLOR_PAIRS - 1.pair_number的值必须介于0COLOR_PAIRS - 1之间。

curses.pair_number(attr)

Return the number of the color-pair set by the attribute value attr. 返回由属性值attr设置的颜色对的编号。color_pair() is the counterpart to this function.是此功能的对应项。

curses.putp(str)

Equivalent to tputs(str, 1, putchar); emit the value of a specified terminfo capability for the current terminal. 相当于tputs(str, 1, putchar);发出当前终端的指定terminfo能力的值。Note that the output of putp() always goes to standard output.注意,putp()的输出总是转到标准输出。

curses.qiflush([flag])

If flag is False, the effect is the same as calling noqiflush(). 如果flagFalse,则效果与调用noqiflush()相同。If flag is True, or no argument is provided, the queues will be flushed when these control characters are read.如果flagTrue或未提供参数,则在读取这些控制字符时将刷新队列。

curses.raw()

Enter raw mode. 进入原始模式。In raw mode, normal line buffering and processing of interrupt, quit, suspend, and flow control keys are turned off; characters are presented to curses input functions one by one.在原始模式下,中断、退出、暂停和流量控制键的正常行缓冲和处理被关闭;字符一个接一个地呈现给诅咒输入函数。

curses.reset_prog_mode()

Restore the terminal to “program” mode, as previously saved by def_prog_mode().将终端恢复到“程序”模式,如之前由def_prog_mode()保存的那样。

curses.reset_shell_mode()

Restore the terminal to “shell” mode, as previously saved by def_shell_mode().将终端恢复到def_shell_mode()先前保存的“外壳”模式。

curses.resetty()

Restore the state of the terminal modes to what it was at the last call to savetty().将终端模式的状态恢复为上次调用savetty()时的状态。

curses.resize_term(nlines, ncols)

Backend function used by resizeterm(), performing most of the work; when resizing the windows, resize_term() blank-fills the areas that are extended. resizeterm()使用的后端函数,执行大部分工作;调整窗口大小时,resize_term()空白将填充扩展的区域。The calling application should fill in these areas with appropriate data. 调用应用程序应使用适当的数据填充这些区域。The resize_term() function attempts to resize all windows. However, due to the calling convention of pads, it is not possible to resize these without additional interaction with the application.resize_term()函数的作用是:调整所有窗口的大小。然而,由于PAD的调用约定,在不与应用程序进行额外交互的情况下,不可能调整它们的大小。

curses.resizeterm(nlines, ncols)

Resize the standard and current windows to the specified dimensions, and adjusts other bookkeeping data used by the curses library that record the window dimensions (in particular the SIGWINCH handler).将标准窗口和当前窗口调整为指定尺寸,并调整记录窗口尺寸的curses库(特别是SIGWINCH处理程序)使用的其他簿记数据。

curses.savetty()

Save the current state of the terminal modes in a buffer, usable by resetty().将终端模式的当前状态保存在可由resetty()使用的缓冲区中。

curses.get_escdelay()

Retrieves the value set by set_escdelay().检索set_escdelay()设置的值。

New in version 3.9.版本3.9中新增。

curses.set_escdelay(ms)

Sets the number of milliseconds to wait after reading an escape character, to distinguish between an individual escape character entered on the keyboard from escape sequences sent by cursor and function keys.设置读取转义字符后等待的毫秒数,以区分键盘上输入的单个转义字符与光标和功能键发送的转义序列。

New in version 3.9.版本3.9中新增。

curses.get_tabsize()

Retrieves the value set by set_tabsize().检索set_tabsize()设置的值。

New in version 3.9.版本3.9中新增。

curses.set_tabsize(size)

Sets the number of columns used by the curses library when converting a tab character to spaces as it adds the tab to a window.设置在将选项卡添加到窗口时将选项卡字符转换为空格时,curses库使用的列数。

New in version 3.9.版本3.9中新增。

curses.setsyx(y, x)

Set the virtual screen cursor to y, x. 将虚拟屏幕游标设置为yxIf y and x are both -1, then leaveok is set True.如果yx都为-1,则leaveok设置为True

curses.setupterm(term=None, fd=- 1)

Initialize the terminal. 初始化终端。term is a string giving the terminal name, or None; if omitted or None, the value of the TERM environment variable will be used. term是给出终端名称的字符串,或None;如果省略或无,将使用TERM环境变量的值。fd is the file descriptor to which any initialization sequences will be sent; if not supplied or -1, the file descriptor for sys.stdout will be used.fd是将向其发送任何初始化序列的文件描述符;如果未提供或为-1,则将使用sys.stdout的文件描述符。

curses.start_color()

Must be called if the programmer wants to use colors, and before any other color manipulation routine is called. 如果程序员想要使用颜色,必须在调用任何其他颜色操作例程之前调用。It is good practice to call this routine right after initscr().最好在initscr()之后立即调用此例程。

start_color() initializes eight basic colors (black, red, green, yellow, blue, magenta, cyan, and white), and two global variables in the curses module, COLORS and COLOR_PAIRS, containing the maximum number of colors and color-pairs the terminal can support. start_color()初始化八种基本颜色(黑色、红色、绿色、黄色、蓝色、品红色、青色和白色),以及curses模块中的两个全局变量COLORSCOLOR_PAIRS,其中包含终端可以支持的最大颜色和颜色对数。It also restores the colors on the terminal to the values they had when the terminal was just turned on.它还将终端上的颜色恢复为刚打开终端时的值。

curses.termattrs()

Return a logical OR of all video attributes supported by the terminal. 返回终端支持的所有视频属性的逻辑或。This information is useful when a curses program needs complete control over the appearance of the screen.当curses程序需要完全控制屏幕外观时,此信息非常有用。

curses.termname()

Return the value of the environment variable TERM, as a bytes object, truncated to 14 characters.返回环境变量TERM的值,作为字节对象,截断为14个字符。

curses.tigetflag(capname)

Return the value of the Boolean capability corresponding to the terminfo capability name capname as an integer. 以整数形式返回与terminfo功能名称capname对应的布尔功能的值。Return the value -1 if capname is not a Boolean capability, or 0 if it is canceled or absent from the terminal description.如果capname不是布尔函数,则返回值-1;如果capname被取消或不在终端描述中,则返回0

curses.tigetnum(capname)

Return the value of the numeric capability corresponding to the terminfo capability name capname as an integer. 以整数形式返回与terminfo功能名称capname对应的数字功能的值。Return the value -2 if capname is not a numeric capability, or -1 if it is canceled or absent from the terminal description.如果capname不是数字功能,则返回值-2;如果capname被取消或不在终端描述中,则返回-1

curses.tigetstr(capname)

Return the value of the string capability corresponding to the terminfo capability name capname as a bytes object. 返回与terminfo能力名称capname对应的字符串能力值作为字节对象。Return None if capname is not a terminfo “string capability”, or is canceled or absent from the terminal description.如果capname不是终端“字符串能力”,或者在终端描述中被取消或不存在,则返回None

curses.tparm(str[, ...])

Instantiate the bytes object str with the supplied parameters, where str should be a parameterized string obtained from the terminfo database. 使用提供的参数实例化字节对象str,其中str应该是从terminfo数据库获得的参数化字符串。E.g. tparm(tigetstr("cup"), 5, 3) could result in b'\033[6;4H', the exact result depending on terminal type.例如,tparm(tigetstr("cup"), 5, 3)可能导致b'\033[6;4H',具体结果取决于端子类型。

curses.typeahead(fd)

Specify that the file descriptor fd be used for typeahead checking. 指定文件描述符fd用于typeahead检查。If fd is -1, then no typeahead checking is done.如果fd-1,则不进行提前打印检查。

The curses library does “line-breakout optimization” by looking for typeahead periodically while updating the screen. curses库通过在更新屏幕时定期查找提前输入来进行“换行优化”。If input is found, and it is coming from a tty, the current update is postponed until refresh or doupdate is called again, allowing faster response to commands typed in advance. 如果找到输入,并且输入来自tty,则当前更新将被推迟,直到再次调用刷新或doupdate,这样可以更快地响应预先键入的命令。This function allows specifying a different file descriptor for typeahead checking.此函数允许指定不同的文件描述符以进行提前类型检查。

curses.unctrl(ch)

Return a bytes object which is a printable representation of the character ch. 返回一个字节对象,该对象是字符ch的可打印表示。Control characters are represented as a caret followed by the character, for example as b'^C'. 控制字符表示为字符后面的插入符号,例如b'^C'Printing characters are left as they are.打印字符保持原样。

curses.ungetch(ch)

Push ch so the next getch() will return it.按下ch,下一个getch()将返回它。

Note

Only one ch can be pushed before getch() is called.在调用getch()之前只能推送一个ch

curses.update_lines_cols()

Update LINES and COLS. 更新LINESCOLSUseful for detecting manual screen resize.用于检测手动调整屏幕大小。

New in version 3.5.版本3.5中新增。

curses.unget_wch(ch)

Push ch so the next get_wch() will return it.按下ch,下一个get_wch()将返回它。

Note

Only one ch can be pushed before get_wch() is called.在调用get_wch()之前只能推送一个ch

New in version 3.3.版本3.3中新增。

curses.ungetmouse(id, x, y, z, bstate)

Push a KEY_MOUSE event onto the input queue, associating the given state data with it.KEY_MOUSE事件推到输入队列上,将给定状态数据与其关联。

curses.use_env(flag)

If used, this function should be called before initscr() or newterm are called. 如果使用,则应在调用initscr()或newterm之前调用此函数。When flag is False, the values of lines and columns specified in the terminfo database will be used, even if environment variables LINES and COLUMNS (used by default) are set, or if curses is running in a window (in which case default behavior would be to use the window size if LINES and COLUMNS are not set).flagFalse时,将使用terminfo数据库中指定的行和列的值,即使设置了环境变量LINESCOLUMNS(默认使用),或者curses正在窗口中运行(在这种情况下,如果未设置LINESCOLUMNS,默认行为将使用窗口大小)。

curses.use_default_colors()

Allow use of default values for colors on terminals supporting this feature. 允许在支持此功能的终端上使用颜色的默认值。Use this to support transparency in your application. 使用此选项支持应用程序中的透明度。The default color is assigned to the color number -1. 默认颜色指定给颜色编号-1After calling this function, init_pair(x, curses.COLOR_RED, -1) initializes, for instance, color pair x to a red foreground color on the default background.调用此函数后,init_pair(x, curses.COLOR_RED, -1)将颜色对x初始化为默认背景上的红色前景色。

curses.wrapper(func, /, *args, **kwargs)

Initialize curses and call another callable object, func, which should be the rest of your curses-using application. 初始化curses并调用另一个可调用对象func,这应该是使用应用程序的其余curses。If the application raises an exception, this function will restore the terminal to a sane state before re-raising the exception and generating a traceback. 如果应用程序引发异常,此函数将在重新引发异常并生成回溯之前将终端恢复到正常状态。The callable object func is then passed the main window ‘stdscr’ as its first argument, followed by any other arguments passed to wrapper(). 然后将可调用对象func作为其第一个参数传递给主窗口“stdscr”,然后将其他任何参数传递给wrapper()Before calling func, wrapper() turns on cbreak mode, turns off echo, enables the terminal keypad, and initializes colors if the terminal has color support. 在调用func之前,wrapper()打开cbreak模式,关闭echo,启用终端键盘,如果终端支持颜色,则初始化颜色。On exit (whether normally or by exception) it restores cooked mode, turns on echo, and disables the terminal keypad.退出时(无论是正常还是异常),它恢复烹饪模式,打开回声,并禁用终端键盘。

Window Objects

Window objects, as returned by initscr() and newwin() above, have the following methods and attributes:上面initscr()newwin()返回的窗口对象具有以下方法和属性:

window.addch(ch[, attr])
window.addch(y, x, ch[, attr])

Paint character ch at (y, x) with attributes attr, overwriting any character previously painted at that location. 使用属性attr(y, x)处绘制字符ch,覆盖之前在该位置绘制的任何字符。By default, the character position and attributes are the current settings for the window object.默认情况下,角色位置和属性是窗口对象的当前设置。

Note

Writing outside the window, subwindow, or pad raises a curses.error. 在窗口、子窗口或pad外部写入会引发curses.errorAttempting to write to the lower right corner of a window, subwindow, or pad will cause an exception to be raised after the character is printed.试图写入窗口、子窗口或键盘的右下角将导致在打印字符后引发异常。

window.addnstr(str, n[, attr])
window.addnstr(y, x, str, n[, attr])

Paint at most n characters of the character string str at (y, x) with attributes attr, overwriting anything previously on the display.使用attr属性最多绘制字符串(y, x)中的n个字符,覆盖之前显示的任何内容。

window.addstr(str[, attr])
window.addstr(y, x, str[, attr])

Paint the character string str at (y, x) with attributes attr, overwriting anything previously on the display.使用attr属性在(y, x)处绘制字符串str,覆盖之前显示的任何内容。

Note

  • Writing outside the window, subwindow, or pad raises curses.error. 在窗口、子窗口或pad外部写入会引发curses.errorAttempting to write to the lower right corner of a window, subwindow, or pad will cause an exception to be raised after the string is printed.尝试写入窗口、子窗口或pad的右下角将导致字符串打印后引发异常。

  • A bug in ncurses, the backend for this Python module, can cause SegFaults when resizing windows. 此Python模块的后端ncurses中的一个错误会在调整窗口大小时导致SegFaults。This is fixed in ncurses-6.1-20190511. 这在ncurses-6.1-20190511中已修复。If you are stuck with an earlier ncurses, you can avoid triggering this if you do not call addstr() with a str that has embedded newlines. 如果您使用的是早期的ncurses,那么如果不使用带有嵌入换行符的str调用addstr(),就可以避免触发这种情况。Instead, call addstr() separately for each line.相反,为每行单独调用addstr()

window.attroff(attr)

Remove attribute attr from the “background” set applied to all writes to the current window.从应用于对当前窗口的所有写入的“背景”集中删除属性attr

window.attron(attr)

Add attribute attr from the “background” set applied to all writes to the current window.从应用于当前窗口的所有写入的“背景”集中添加属性attr

window.attrset(attr)

Set the “background” set of attributes to attr. 将“背景”属性集设置为attrThis set is initially 0 (no attributes).此集合最初为0(无属性)。

window.bkgd(ch[, attr])

Set the background property of the window to the character ch, with attributes attr. 使用属性attr将窗口的背景属性设置为字符chThe change is then applied to every character position in that window:然后将更改应用于该窗口中的每个字符位置:

  • The attribute of every character in the window is changed to the new background attribute.窗口中每个字符的属性将更改为新的背景属性。

  • Wherever the former background character appears, it is changed to the new background character.无论以前的背景字符出现在何处,它都会更改为新的背景字符

window.bkgdset(ch[, attr])

Set the window’s background. A window’s background consists of a character and any combination of attributes. 设置窗口的背景。窗口的背景由字符和属性的任意组合组成。The attribute part of the background is combined (OR’ed) with all non-blank characters that are written into the window. 背景的属性部分与写入窗口的所有非空白字符组合(或编辑)。Both the character and attribute parts of the background are combined with the blank characters. 背景的字符和属性部分都与空白字符组合。The background becomes a property of the character and moves with the character through any scrolling and insert/delete line/character operations.背景成为角色的属性,并通过任何滚动和插入/删除行/字符操作与角色一起移动。

window.border([ls[, rs[, ts[, bs[, tl[, tr[, bl[, br]]]]]]]])

Draw a border around the edges of the window. 在窗口边缘周围绘制边框。Each parameter specifies the character to use for a specific part of the border; see the table below for more details.每个参数指定用于边框特定部分的字符;详见下表。

Note

A 0 value for any parameter will cause the default character to be used for that parameter. 任何参数的0值将导致该参数使用默认字符。Keyword parameters can not be used. 不能使用关键字参数。The defaults are listed in this table:下表列出了默认值:

Parameter参数

Description描述

Default value默认值

ls

Left side左侧

ACS_VLINE

rs

Right side右侧

ACS_VLINE

ts

Top顶部

ACS_HLINE

bs

Bottom底部

ACS_HLINE

tl

Upper-left corner左上角

ACS_ULCORNER

tr

Upper-right corner右上角

ACS_URCORNER

bl

Bottom-left corner左下角

ACS_LLCORNER

br

Bottom-right corner右下角

ACS_LRCORNER

window.box([vertch, horch])

Similar to border(), but both ls and rs are vertch and both ts and bs are horch. 类似于border(),但lsrs都是vertchtsbs都是horchThe default corner characters are always used by this function.此函数始终使用默认角字符。

window.chgat(attr)
window.chgat(num, attr)
window.chgat(y, x, attr)
window.chgat(y, x, num, attr)

Set the attributes of num characters at the current cursor position, or at position (y, x) if supplied. 在当前游标位置或位置(y, x)(如果提供)设置num个字符的属性。If num is not given or is -1, the attribute will be set on all the characters to the end of the line. 如果num未给定或为-1,则将在行尾的所有字符上设置该属性。This function moves cursor to position (y, x) if supplied. 此函数将游标移动到位置(y, x)(如果提供)。The changed line will be touched using the touchline() method so that the contents will be redisplayed by the next window refresh.将使用touchline()方法触摸更改的行,以便在下次窗口刷新时重新显示内容。

window.clear()

Like erase(), but also cause the whole window to be repainted upon next call to refresh().类似于erase(),但也会在下次调用refresh()时重新绘制整个窗口。

window.clearok(flag)

If flag is True, the next call to refresh() will clear the window completely.如果flagTrue,则下一次调用refresh()将完全清除窗口。

window.clrtobot()

Erase from cursor to the end of the window: all lines below the cursor are deleted, and then the equivalent of clrtoeol() is performed.从光标到窗口末尾的擦除:删除光标下方的所有行,然后执行clrtoeol()的等效操作。

window.clrtoeol()

Erase from cursor to the end of the line.从光标擦除到行尾。

window.cursyncup()

Update the current cursor position of all the ancestors of the window to reflect the current cursor position of the window.更新窗口所有祖先的当前光标位置,以反映窗口的当前光标。

window.delch([y, x])

Delete any character at (y, x).删除(y, x)处的任何字符。

window.deleteln()

Delete the line under the cursor. 删除光标下的行。All following lines are moved up by one line.以下所有行将上移一行。

window.derwin(begin_y, begin_x)
window.derwin(nlines, ncols, begin_y, begin_x)

An abbreviation for “derive window”, derwin() is the same as calling subwin(), except that begin_y and begin_x are relative to the origin of the window, rather than relative to the entire screen. derwin()是“派生窗口”的缩写,与调用subwin()相同,只是begin_ybegin_x相对于窗口的原点,而不是整个屏幕。Return a window object for the derived window.返回派生窗口的窗口对象。

window.echochar(ch[, attr])

Add character ch with attribute attr, and immediately call refresh() on the window.添加带有属性attr的字符ch,然后立即在窗口上调用refresh()

window.enclose(y, x)

Test whether the given pair of screen-relative character-cell coordinates are enclosed by the given window, returning True or False. 测试给定的一对屏幕相对字符单元坐标是否被给定的窗口包围,返回TrueFalseIt is useful for determining what subset of the screen windows enclose the location of a mouse event.这有助于确定屏幕窗口的哪个子集包含鼠标事件的位置。

Changed in version 3.10:版本3.10中更改: Previously it returned 1 or 0 instead of True or False.以前它返回10,而不是TrueFalse

window.encoding

Encoding used to encode method arguments (Unicode strings and characters). 用于编码方法参数(Unicode字符串和字符)的编码。The encoding attribute is inherited from the parent window when a subwindow is created, for example with window.subwin(). 创建子窗口时,编码属性从父窗口继承,例如使用window.subwin()By default, the locale encoding is used (see locale.getpreferredencoding()).默认情况下,使用区域设置编码(请参阅locale.getpreferredencoding())。

New in version 3.3.版本3.3中新增。

window.erase()

Clear the window.

window.getbegyx()

Return a tuple (y, x) of co-ordinates of upper-left corner.返回左上角坐标的元组(y, x)

window.getbkgd()

Return the given window’s current background character/attribute pair.返回给定窗口的当前背景字符/属性对。

window.getch([y, x])

Get a character. 获取角色。Note that the integer returned does not have to be in ASCII range: function keys, keypad keys and so on are represented by numbers higher than 255. 请注意,返回的整数不必在ASCII范围内:功能键、键盘键等由大于255的数字表示。In no-delay mode, return -1 if there is no input, otherwise wait until a key is pressed.在无延迟模式下,如果没有输入,则返回-1,否则等待按键。

window.get_wch([y, x])

Get a wide character. 获得宽字符。Return a character for most keys, or an integer for function keys, keypad keys, and other special keys. 返回大多数键的字符,或功能键、键盘键和其他特殊键的整数。In no-delay mode, raise an exception if there is no input.在无延迟模式下,如果没有输入,则引发异常。

New in version 3.3.版本3.3中新增。

window.getkey([y, x])

Get a character, returning a string instead of an integer, as getch() does. 获取一个字符,返回字符串而不是整数,就像getch()所做的那样。Function keys, keypad keys and other special keys return a multibyte string containing the key name. 功能键、键盘键和其他特殊键返回包含键名的多字节字符串。In no-delay mode, raise an exception if there is no input.在无延迟模式下,如果没有输入,则引发异常。

window.getmaxyx()

Return a tuple (y, x) of the height and width of the window.返回窗口高度和宽度的元组(y, x)

window.getparyx()

Return the beginning coordinates of this window relative to its parent window as a tuple (y, x). 将此窗口相对于其父窗口的起始坐标作为元组(y, x)返回。Return (-1, -1) if this window has no parent.如果此窗口没有父窗口,则返回(-1, -1)

window.getstr()
window.getstr(n)
window.getstr(y, x)
window.getstr(y, x, n)

Read a bytes object from the user, with primitive line editing capacity.从用户处读取字节对象,具有基本行编辑能力。

window.getyx()

Return a tuple (y, x) of current cursor position relative to the window’s upper-left corner.返回相对于窗口左上角的当前游标位置的元组(y, x)

window.hline(ch, n)
window.hline(y, x, ch, n)

Display a horizontal line starting at (y, x) with length n consisting of the character ch.显示从(y, x)开始的水平线,长度n由字符ch组成。

window.idcok(flag)

If flag is False, curses no longer considers using the hardware insert/delete character feature of the terminal; if flag is True, use of character insertion and deletion is enabled. 如果flagFalse,curses不再考虑使用终端的硬件插入/删除字符功能;如果flagTrue,则启用字符插入和删除。When curses is first initialized, use of character insert/delete is enabled by default.首次初始化curses时,默认情况下启用字符插入/删除。

window.idlok(flag)

If flag is True, curses will try and use hardware line editing facilities. 如果flagTruecurses将尝试使用硬件行编辑工具。Otherwise, line insertion/deletion are disabled.否则,将禁用行插入/删除。

window.immedok(flag)

If flag is True, any change in the window image automatically causes the window to be refreshed; you no longer have to call refresh() yourself. 如果flagTrue,则窗口图像中的任何更改都会自动刷新窗口;您不再需要自己调用refresh()However, it may degrade performance considerably, due to repeated calls to wrefresh. 然而,由于反复调用wrefresh,它可能会大大降低性能。This option is disabled by default.默认情况下禁用此选项。

window.inch([y, x])

Return the character at the given position in the window. 返回窗口中给定位置的字符。The bottom 8 bits are the character proper, and upper bits are the attributes.最下面的8位是字符本身,最上面的位是属性。

window.insch(ch[, attr])
window.insch(y, x, ch[, attr])

Paint character ch at (y, x) with attributes attr, moving the line from position x right by one character.使用属性attr(y, x)处绘制字符ch,将行从位置x向右移动一个字符。

window.insdelln(nlines)

Insert nlines lines into the specified window above the current line. 在当前行上方的指定窗口中插入nlinesThe nlines bottom lines are lost. nlines底线丢失。For negative nlines, delete nlines lines starting with the one under the cursor, and move the remaining lines up. 对于负数nlines,删除从游标下那一行开始的nlines行,然后向上移动其余行。The bottom nlines lines are cleared. 底部的nlines行将被清除。The current cursor position remains the same.当前光标位置保持不变。

window.insertln()

Insert a blank line under the cursor. 在光标下插入一个空行。All following lines are moved down by one line.以下所有行下移一行。

window.insnstr(str, n[, attr])
window.insnstr(y, x, str, n[, attr])

Insert a character string (as many characters as will fit on the line) before the character under the cursor, up to n characters. 在光标下的字符之前插入字符串(尽可能多的字符),最多可插入n个字符。If n is zero or negative, the entire string is inserted. 如果n为零或负,则插入整个字符串。All characters to the right of the cursor are shifted right, with the rightmost characters on the line being lost. 光标右侧的所有字符都向右移动,行中最右侧的字符将丢失。The cursor position does not change (after moving to y, x, if specified).光标位置不变(移动到yx后,如果指定)。

window.insstr(str[, attr])
window.insstr(y, x, str[, attr])

Insert a character string (as many characters as will fit on the line) before the character under the cursor. 在光标下的字符之前插入字符串(尽可能多的字符)。All characters to the right of the cursor are shifted right, with the rightmost characters on the line being lost. 光标右侧的所有字符都向右移动,行中最右侧的字符将丢失。The cursor position does not change (after moving to y, x, if specified).光标位置不变(移动到yx后,如果指定)。

window.instr([n])
window.instr(y, x[, n])

Return a bytes object of characters, extracted from the window starting at the current cursor position, or at y, x if specified. 返回从当前游标位置或yx(如果指定)开始的窗口中提取的字符字节对象。Attributes are stripped from the characters. 属性从字符中剥离。If n is specified, instr() returns a string at most n characters long (exclusive of the trailing NUL).如果指定了ninstr()将返回最多n个字符长的字符串(不包括后面的NUL)。

window.is_linetouched(line)

Return True if the specified line was modified since the last call to refresh(); otherwise return False. 如果指定的行在上次调用refresh()后被修改,则返回True;否则返回FalseRaise a curses.error exception if line is not valid for the given window.如果line对给定窗口无效,则引发curses.error异常。

window.is_wintouched()

Return True if the specified window was modified since the last call to refresh(); otherwise return False.如果指定的窗口在上次调用refresh()后被修改,则返回True;否则返回False。

window.keypad(flag)

If flag is True, escape sequences generated by some keys (keypad, function keys) will be interpreted by curses. 如果flagTrue,则某些按键(键盘、功能键)生成的转义序列将被curses解释。If flag is False, escape sequences will be left as is in the input stream.如果flagFalse,则转义序列将保留在输入流中。

window.leaveok(flag)

If flag is True, cursor is left where it is on update, instead of being at “cursor position.” 如果flagTrue,游标将留在更新时的位置,而不是“游标位置”This reduces cursor movement where possible. 这将尽可能减少游标移动。If possible the cursor will be made invisible.如果可能,光标将不可见。

If flag is False, cursor will always be at “cursor position” after an update.如果flagFalse,则更新后光标将始终位于“光标位置”。

window.move(new_y, new_x)

Move cursor to (new_y, new_x).

window.mvderwin(y, x)

Move the window inside its parent window. 将窗口移到其父窗口内。The screen-relative parameters of the window are not changed. 窗口的屏幕相关参数不变。This routine is used to display different parts of the parent window at the same physical position on the screen.此例程用于在屏幕上的同一物理位置显示父窗口的不同部分。

window.mvwin(new_y, new_x)

Move the window so its upper-left corner is at (new_y, new_x).移动窗口,使其左上角位于(new_y, new_x)

window.nodelay(flag)

If flag is True, getch() will be non-blocking.如果flagTruegetch()将是非阻塞的。

window.notimeout(flag)

If flag is True, escape sequences will not be timed out.如果flagTrue,转义序列将不会超时。

If flag is False, after a few milliseconds, an escape sequence will not be interpreted, and will be left in the input stream as is.如果flagFalse,几毫秒后,转义序列将不会被解释,并将保留在输入流中。

window.noutrefresh()

Mark for refresh but wait. 标记为刷新,但等待。This function updates the data structure representing the desired state of the window, but does not force an update of the physical screen. 此函数更新表示窗口所需状态的数据结构,但不强制更新物理屏幕。To accomplish that, call doupdate().为此,调用doupdate()

window.overlay(destwin[, sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol])

Overlay the window on top of destwin. The windows need not be the same size, only the overlapping region is copied. 窗口的大小不必相同,只复制重叠区域。This copy is non-destructive, which means that the current background character does not overwrite the old contents of destwin.此副本是非破坏性的,这意味着当前背景字符不会覆盖destwin的旧内容。

To get fine-grained control over the copied region, the second form of overlay() can be used. 为了对复制区域进行细粒度控制,可以使用第二种形式的overlay()sminrow and smincol are the upper-left coordinates of the source window, and the other variables mark a rectangle in the destination window.sminrowsmincol是源窗口的左上角坐标,其他变量标记目标窗口中的矩形。

window.overwrite(destwin[, sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol])

Overwrite the window on top of destwin. The windows need not be the same size, in which case only the overlapping region is copied. 窗口的大小不必相同,在这种情况下,只复制重叠区域。This copy is destructive, which means that the current background character overwrites the old contents of destwin.此副本具有破坏性,这意味着当前背景字符将覆盖destwin的旧内容。

To get fine-grained control over the copied region, the second form of overwrite() can be used. 为了获得对复制区域的细粒度控制,可以使用第二种形式的overwrite()sminrow and smincol are the upper-left coordinates of the source window, the other variables mark a rectangle in the destination window.sminrowsmincol是源窗口的左上角坐标,其他变量标记目标窗口中的矩形。

window.putwin(file)

Write all data associated with the window into the provided file object. 将与窗口关联的所有数据写入提供的文件对象。This information can be later retrieved using the getwin() function.稍后可以使用getwin()函数检索此信息。

window.redrawln(beg, num)

Indicate that the num screen lines, starting at line beg, are corrupted and should be completely redrawn on the next refresh() call.指示num屏幕行(从beg开始)已损坏,应在下一次refresh()调用时完全重新绘制。

window.redrawwin()

Touch the entire window, causing it to be completely redrawn on the next refresh() call.触摸整个窗口,使其在下一次refresh()调用时完全重新绘制。

window.refresh([pminrow, pmincol, sminrow, smincol, smaxrow, smaxcol])

Update the display immediately (sync actual screen with previous drawing/deleting methods).立即更新显示(将实际屏幕与以前的绘制/删除方法同步)。

The 6 optional arguments can only be specified when the window is a pad created with newpad(). 只有当窗口是使用newpad()创建的pad时,才能指定6个可选参数。The additional parameters are needed to indicate what part of the pad and screen are involved. 需要额外的参数来指示涉及焊盘和屏幕的哪个部分。pminrow and pmincol specify the upper left-hand corner of the rectangle to be displayed in the pad. pminrowpmincol指定要在pad中显示的矩形的左上角。sminrow, smincol, smaxrow, and smaxcol specify the edges of the rectangle to be displayed on the screen. sminrowsmincolsmaxrowsmaxcol指定要在屏幕上显示的矩形的边缘。The lower right-hand corner of the rectangle to be displayed in the pad is calculated from the screen coordinates, since the rectangles must be the same size. 要在键盘中显示的矩形的右下角是根据屏幕坐标计算的,因为矩形的大小必须相同。Both rectangles must be entirely contained within their respective structures. 两个矩形必须完全包含在各自的结构中。Negative values of pminrow, pmincol, sminrow, or smincol are treated as if they were zero.pminrowpmincolsminrow或smincol的负值被视为零。

window.resize(nlines, ncols)

Reallocate storage for a curses window to adjust its dimensions to the specified values. 重新分配curses窗口的存储空间,以将其尺寸调整为指定值。If either dimension is larger than the current values, the window’s data is filled with blanks that have the current background rendition (as set by bkgdset()) merged into them.如果任一维度大于当前值,则窗口的数据将填充空白,并将当前背景格式副本(由bkgdset()设置)合并到其中。

window.scroll([lines=1])

Scroll the screen or scrolling region upward by lines lines.向上滚动屏幕或向上滚动区域lines行。

window.scrollok(flag)

Control what happens when the cursor of a window is moved off the edge of the window or scrolling region, either as a result of a newline action on the bottom line, or typing the last character of the last line. 控制当窗口的光标从窗口或滚动区域的边缘移动时发生的情况,无论是由于在底部行上执行换行操作,还是键入最后一行的最后一个字符。If flag is False, the cursor is left on the bottom line. 如果flagFalse,则光标将留在底线上。If flag is True, the window is scrolled up one line. 如果flagTrue,则窗口向上滚动一行。Note that in order to get the physical scrolling effect on the terminal, it is also necessary to call idlok().请注意,为了在终端上获得物理滚动效果,还需要调用idlok()

window.setscrreg(top, bottom)

Set the scrolling region from line top to line bottom. 设置从行top到行bottom的滚动区域。All scrolling actions will take place in this region.所有滚动操作将在此区域中进行。

window.standend()

Turn off the standout attribute. 关闭“突出”属性。On some terminals this has the side effect of turning off all attributes.在某些终端上,这会产生关闭所有属性的副作用。

window.standout()

Turn on attribute A_STANDOUT.启用属性A_STANDOUT

window.subpad(begin_y, begin_x)
window.subpad(nlines, ncols, begin_y, begin_x)

Return a sub-window, whose upper-left corner is at (begin_y, begin_x), and whose width/height is ncols/nlines.返回一个子窗口,其左上角位于(begin_y, begin_x),其宽度/高度为ncols/nlines

window.subwin(begin_y, begin_x)
window.subwin(nlines, ncols, begin_y, begin_x)

Return a sub-window, whose upper-left corner is at (begin_y, begin_x), and whose width/height is ncols/nlines.返回一个子窗口,其左上角位于(begin_y, begin_x),宽度/高度为ncols/nline

By default, the sub-window will extend from the specified position to the lower right corner of the window.默认情况下,子窗口将从指定位置延伸到窗口的右下角。

window.syncdown()

Touch each location in the window that has been touched in any of its ancestor windows. 触摸窗口中在其任何上级窗口中触摸过的每个位置。This routine is called by refresh(), so it should almost never be necessary to call it manually.此例程由refresh()调用,因此几乎不需要手动调用。

window.syncok(flag)

If flag is True, then syncup() is called automatically whenever there is a change in the window.如果flagTrue,则只要窗口中有更改,就会自动调用syncup()

window.syncup()

Touch all locations in ancestors of the window that have been changed in the window.触摸窗口祖先中已在窗口中更改的所有位置。

window.timeout(delay)

Set blocking or non-blocking read behavior for the window. 设置窗口的阻塞或非阻塞读取行为。If delay is negative, blocking read is used (which will wait indefinitely for input). 如果delay为负,则使用阻塞读取(这将无限期地等待输入)。If delay is zero, then non-blocking read is used, and getch() will return -1 if no input is waiting. 如果delay为零,则使用非阻塞读取,如果没有输入等待,getch()将返回-1If delay is positive, then getch() will block for delay milliseconds, and return -1 if there is still no input at the end of that time.如果delay为正,则getch()将阻塞delay毫秒,如果在该时间结束时仍然没有输入,则返回-1

window.touchline(start, count[, changed])

Pretend count lines have been changed, starting with line start. 假装count行已更改,从行start开始。If changed is supplied, it specifies whether the affected lines are marked as having been changed (changed=True) or unchanged (changed=False).如果提供了changed,则指定受影响的行标记为已更改(changed=True)还是未更改(changed=False)。

window.touchwin()

Pretend the whole window has been changed, for purposes of drawing optimizations.假设整个窗口已更改,以进行绘图优化。

window.untouchwin()

Mark all lines in the window as unchanged since the last call to refresh().将窗口中的所有行标记为自上次调用refresh()以来未更改。

window.vline(ch, n)
window.vline(y, x, ch, n)

Display a vertical line starting at (y, x) with length n consisting of the character ch.显示从(y, x)开始的垂直线,长度为n,由字符ch组成。

Constants常数

The curses module defines the following data members:curses模块定义了以下数据成员:

curses.ERR

Some curses routines that return an integer, such as getch(), return ERR upon failure.一些curses例程返回整数,如getch(),失败时返回ERR

curses.OK

Some curses routines that return an integer, such as napms(), return OK upon success.一些返回整数的curses例程,如napms(),在成功时返回OK

curses.version

A bytes object representing the current version of the module. 表示模块当前版本的字节对象。Also available as __version__.也可作为__version__提供。

curses.ncurses_version

A named tuple containing the three components of the ncurses library version: major, minor, and patch. 包含ncurses库版本的三个组件的命名元组:majorminorpatchAll values are integers. 所有值都是整数。The components can also be accessed by name, so curses.ncurses_version[0] is equivalent to curses.ncurses_version.major and so on.组件也可以通过名称访问,因此curses.ncurses_version[0]等同于curses.ncurses_version.major等等。

Availability: if the ncurses library is used.可用性:如果使用ncurses库。

New in version 3.8.版本3.8中新增。

Some constants are available to specify character cell attributes. 某些常量可用于指定字符单元属性。The exact constants available are system dependent.可用的确切常数取决于系统。

Attribute属性

Meaning意思

A_ALTCHARSET

Alternate character set mode交替字符集模式

A_BLINK

Blink mode闪烁模式

A_BOLD

Bold mode粗体模式

A_DIM

Dim mode变暗模式

A_INVIS

Invisible or blank mode不可见或空白模式

A_ITALIC

Italic mode斜体模式

A_NORMAL

Normal attribute法线属性

A_PROTECT

Protected mode

A_REVERSE

Reverse background and foreground colors反转背景色和前景色

A_STANDOUT

Standout mode突出模式

A_UNDERLINE

Underline mode下划线模式

A_HORIZONTAL

Horizontal highlight水平突出显示

A_LEFT

Left highlight左侧突出显示

A_LOW

Low highlight低高光

A_RIGHT

Right highlight右突出显示

A_TOP

Top highlight顶部突出显示

A_VERTICAL

Vertical highlight垂直突出显示

A_CHARTEXT

Bit-mask to extract a character提取字符的位掩码

New in version 3.7.版本3.7中新增。A_ITALIC was added.添加了A_ITALIC

Several constants are available to extract corresponding attributes returned by some methods.有几个常量可用于提取某些方法返回的相应属性。

Bit-mask

Meaning

A_ATTRIBUTES

Bit-mask to extract attributes提取属性的位掩码

A_CHARTEXT

Bit-mask to extract a character提取字符的位掩码

A_COLOR

Bit-mask to extract color-pair field information用于提取颜色对字段信息的位掩码

Keys are referred to by integer constants with names starting with KEY_. 键由名称以KEY_开头的整数常量引用。The exact keycaps available are system dependent.可用的确切键帽取决于系统。

Key constant

Key

KEY_MIN

Minimum key value最小键值

KEY_BREAK

Break key (unreliable)断键(不可靠)

KEY_DOWN

Down-arrow

KEY_UP

Up-arrow

KEY_LEFT

Left-arrow

KEY_RIGHT

Right-arrow

KEY_HOME

Home key (upward+left arrow)

KEY_BACKSPACE

Backspace (unreliable)

KEY_F0

Function keys. 功能键。Up to 64 function keys are supported.最多支持64个功能键。

KEY_Fn

Value of function key n

KEY_DL

Delete line

KEY_IL

Insert line

KEY_DC

Delete character

KEY_IC

Insert char or enter insert mode插入字符或进入插入模式

KEY_EIC

Exit insert char mode退出插入字符模式

KEY_CLEAR

Clear screen

KEY_EOS

Clear to end of screen清除到屏幕末尾

KEY_EOL

Clear to end of line清除到线路末端

KEY_SF

Scroll 1 line forward向前滚动1行

KEY_SR

Scroll 1 line backward (reverse)向后滚动1行(反转)

KEY_NPAGE

Next page下一页

KEY_PPAGE

Previous page上一页

KEY_STAB

Set tab设置制表符

KEY_CTAB

Clear tab清除制表符

KEY_CATAB

Clear all tabs清除所有制表符

KEY_ENTER

Enter or send (unreliable)输入或发送(不可靠)

KEY_SRESET

Soft (partial) reset (unreliable)软(部分)复位(不可靠)

KEY_RESET

Reset or hard reset (unreliable)复位或硬复位(不可靠)

KEY_PRINT

Print打印

KEY_LL

Home down or bottom (lower left)主页向下或底部(左下)

KEY_A1

Upper left of keypad键盘左上角

KEY_A3

Upper right of keypad键盘右上角

KEY_B2

Center of keypad键盘中心

KEY_C1

Lower left of keypad键盘左下角

KEY_C3

Lower right of keypad

KEY_BTAB

Back tab

KEY_BEG

Beg (beginning)

KEY_CANCEL

Cancel

KEY_CLOSE

Close

KEY_COMMAND

Cmd (command)

KEY_COPY

Copy

KEY_CREATE

Create

KEY_END

End

KEY_EXIT

Exit

KEY_FIND

Find

KEY_HELP

Help

KEY_MARK

Mark

KEY_MESSAGE

Message

KEY_MOVE

Move

KEY_NEXT

Next

KEY_OPEN

Open

KEY_OPTIONS

Options

KEY_PREVIOUS

Prev (previous)

KEY_REDO

Redo

KEY_REFERENCE

Ref (reference)

KEY_REFRESH

Refresh

KEY_REPLACE

Replace

KEY_RESTART

Restart重新启动

KEY_RESUME

Resume恢复

KEY_SAVE

Save保存

KEY_SBEG

Shifted Beg (beginning)移位开始(开始)

KEY_SCANCEL

Shifted Cancel换档取消

KEY_SCOMMAND

Shifted Command移位命令

KEY_SCOPY

Shifted Copy移位的副本

KEY_SCREATE

Shifted Create移位创建

KEY_SDC

Shifted Delete char移位删除字符

KEY_SDL

Shifted Delete line移位删除行

KEY_SELECT

Select选择

KEY_SEND

Shifted End移动的末端

KEY_SEOL

Shifted Clear line移位清除线

KEY_SEXIT

Shifted Exit换档退出

KEY_SFIND

Shifted Find移位查找

KEY_SHELP

Shifted Help转换的帮助

KEY_SHOME

Shifted Home移动的原点

KEY_SIC

Shifted Input移位输入

KEY_SLEFT

Shifted Left arrow

KEY_SMESSAGE

Shifted Message

KEY_SMOVE

Shifted Move

KEY_SNEXT

Shifted Next

KEY_SOPTIONS

Shifted Options

KEY_SPREVIOUS

Shifted Prev

KEY_SPRINT

Shifted Print

KEY_SREDO

Shifted Redo

KEY_SREPLACE

Shifted Replace

KEY_SRIGHT

Shifted Right arrow

KEY_SRSUME

Shifted Resume

KEY_SSAVE

Shifted Save

KEY_SSUSPEND

Shifted Suspend

KEY_SUNDO

Shifted Undo

KEY_SUSPEND

Suspend

KEY_UNDO

Undo

KEY_MOUSE

Mouse event has occurred

KEY_RESIZE

Terminal resize event

KEY_MAX

Maximum key value

On VT100s and their software emulations, such as X terminal emulators, there are normally at least four function keys (KEY_F1, KEY_F2, KEY_F3, KEY_F4) available, and the arrow keys mapped to KEY_UP, KEY_DOWN, KEY_LEFT and KEY_RIGHT in the obvious way. 在VT100及其软件仿真(如X终端仿真器)上,通常至少有四个功能键(KEY_F1KEY_F2KEY_F3KEY_F4)可用,箭头键以明显的方式映射到KEY_UPKEY_DOWNKEY_LEFTKEY_RIGHTIf your machine has a PC keyboard, it is safe to expect arrow keys and twelve function keys (older PC keyboards may have only ten function keys); also, the following keypad mappings are standard:如果您的电脑有PC键盘,可以安全地使用箭头键和十二个功能键(旧的PC键盘可能只有十个功能键);此外,以下键盘映射是标准的:

Keycap

Constant

Insert

KEY_IC

Delete

KEY_DC

Home

KEY_HOME

End

KEY_END

Page Up

KEY_PPAGE

Page Down

KEY_NPAGE

The following table lists characters from the alternate character set. 下表列出了备用字符集中的字符。These are inherited from the VT100 terminal, and will generally be available on software emulations such as X terminals. 这些是从VT100终端继承的,通常可用于软件仿真,如X终端。When there is no graphic available, curses falls back on a crude printable ASCII approximation.当没有可用的图形时,curses会返回原始的可打印ASCII近似值。

Note

These are available only after initscr() has been called.只有在调用initscr()后,这些选项才可用。

ACS code

Meaning

ACS_BBSS

alternate name for upper right corner右上角的替代名称

ACS_BLOCK

solid square block实心方块

ACS_BOARD

board of squares方格板

ACS_BSBS

alternate name for horizontal line水平线的替代名称

ACS_BSSB

alternate name for upper left corner左上角的备用名称

ACS_BSSS

alternate name for top tee顶部三通的替代名称

ACS_BTEE

bottom tee底部三通

ACS_BULLET

bullet子弹

ACS_CKBOARD

checker board (stipple)棋盘(点画)

ACS_DARROW

arrow pointing down向下箭头

ACS_DEGREE

degree symbol度数符号

ACS_DIAMOND

diamond钻石

ACS_GEQUAL

greater-than-or-equal-to大于或等于

ACS_HLINE

horizontal line水平线

ACS_LANTERN

lantern symbol灯笼符号

ACS_LARROW

left arrow左箭头

ACS_LEQUAL

less-than-or-equal-to小于或等于

ACS_LLCORNER

lower left-hand corner左下角

ACS_LRCORNER

lower right-hand corner右下角

ACS_LTEE

left tee左三通

ACS_NEQUAL

not-equal sign不等号

ACS_PI

letter pi字母pi

ACS_PLMINUS

plus-or-minus sign加号或减号

ACS_PLUS

big plus sign大加号

ACS_RARROW

right arrow向右箭头

ACS_RTEE

right tee右三通

ACS_S1

scan line 1扫描线1

ACS_S3

scan line 3扫描线3

ACS_S7

scan line 7扫描线7

ACS_S9

scan line 9扫描线9

ACS_SBBS

alternate name for lower right corner右下角的替代名称

ACS_SBSB

alternate name for vertical line垂直线的备用名称

ACS_SBSS

alternate name for right tee右三通的备用名称

ACS_SSBB

alternate name for lower left corner左下角的替代名称

ACS_SSBS

alternate name for bottom tee底部三通的备用名称

ACS_SSSB

alternate name for left tee左三通的备用名称

ACS_SSSS

alternate name for crossover or big plus交叉或大加号的替代名称

ACS_STERLING

pound sterling英镑

ACS_TTEE

top tee顶部三通

ACS_UARROW

up arrow向上箭头

ACS_ULCORNER

upper left corner左上角

ACS_URCORNER

upper right corner右上角

ACS_VLINE

vertical line垂直线

The following table lists the predefined colors:下表列出了预定义的颜色:

Constant常数

Color颜色

COLOR_BLACK

Black黑色

COLOR_BLUE

Blue蓝色

COLOR_CYAN

Cyan (light greenish blue)青色(浅绿蓝色)

COLOR_GREEN

Green绿色

COLOR_MAGENTA

Magenta (purplish red)洋红色(紫红色)

COLOR_RED

Red红色

COLOR_WHITE

White白色

COLOR_YELLOW

Yellow黄的

curses.textpadText input widget for curses programscurses程序的文本输入小部件

The curses.textpad module provides a Textbox class that handles elementary text editing in a curses window, supporting a set of keybindings resembling those of Emacs (thus, also of Netscape Navigator, BBedit 6.x, FrameMaker, and many other programs). curses.textpad模块提供了一个Textbox类,用于处理curses窗口中的基本文本编辑,支持一组类似Emacs(因此,也适用于Netscape Navigator、BBedit 6x、FrameMaker和许多其他程序)的键绑定。The module also provides a rectangle-drawing function useful for framing text boxes or for other purposes.该模块还提供了一个矩形绘图功能,用于框文本框或其他用途。

The module curses.textpad defines the following function:模块curses.textpad定义了以下函数:

curses.textpad.rectangle(win, uly, ulx, lry, lrx)

Draw a rectangle. 画一个矩形。The first argument must be a window object; the remaining arguments are coordinates relative to that window. 第一个参数必须是窗口对象;其余参数是相对于该窗口的坐标。The second and third arguments are the y and x coordinates of the upper left hand corner of the rectangle to be drawn; the fourth and fifth arguments are the y and x coordinates of the lower right hand corner. 第二和第三参数是要绘制的矩形左上角的y和x坐标;第四和第五个参数是右下角的y和x坐标。The rectangle will be drawn using VT100/IBM PC forms characters on terminals that make this possible (including xterm and most other software terminal emulators). 矩形将使用VT100/IBM PC表单字符在终端上绘制,使其成为可能(包括xterm和大多数其他软件终端模拟器)。Otherwise it will be drawn with ASCII dashes, vertical bars, and plus signs.否则,将使用ASCII破折号、竖条和加号绘制。

Textbox objects对象

You can instantiate a Textbox object as follows:您可以实例化Textbox对象,如下所示:

classcurses.textpad.Textbox(win)

Return a textbox widget object. 返回文本框小部件对象。The win argument should be a curses window object in which the textbox is to be contained. win参数应该是包含文本框的curseswindow对象。The edit cursor of the textbox is initially located at the upper left hand corner of the containing window, with coordinates (0, 0). 文本框的编辑游标最初位于包含窗口的左上角,坐标为(0, 0)The instance’s stripspaces flag is initially on.实例的stripspaces标志最初处于启用状态。

Textbox objects have the following methods:对象具有以下方法:

edit([validator])

This is the entry point you will normally use. 这是您通常使用的入口点。It accepts editing keystrokes until one of the termination keystrokes is entered. 它接受编辑键击,直到输入一个终止键击。If validator is supplied, it must be a function. 如果提供了validator,它必须是一个函数。It will be called for each keystroke entered with the keystroke as a parameter; command dispatch is done on the result. 它将被调用,用于以键击作为参数输入的每个键击;对结果执行命令分派。This method returns the window contents as a string; whether blanks in the window are included is affected by the stripspaces attribute.此方法以字符串形式返回窗口内容;窗口中是否包含空格受stripspaces属性的影响。

do_command(ch)

Process a single command keystroke. Here are the supported special keystrokes:处理单个命令键击。以下是支持的特殊按键:

Keystroke

Action

Control-A

Go to left edge of window.转到窗口的左边缘。

Control-B

Cursor left, wrapping to previous line if appropriate.光标向左,如果合适,将换行到上一行。

Control-D

Delete character under cursor.删除光标下的字符。

Control-E

Go to right edge (stripspaces off) or end of line (stripspaces on).转到右边缘(条带空间关闭)或行末端(条带空格打开)。

Control-F

Cursor right, wrapping to next line when appropriate.光标向右,适当时换行到下一行。

Control-G

Terminate, returning the window contents.终止,返回窗口内容。

Control-H

Delete character backward.向后删除字符。

Control-J

Terminate if the window is 1 line, otherwise insert newline.如果窗口为1行,则终止,否则插入换行符。

Control-K

If line is blank, delete it, otherwise clear to end of line.如果该行为空,则将其删除,否则清除到行尾。

Control-L

Refresh screen.刷新屏幕。

Control-N

Cursor down; move down one line.光标向下;向下移动一行。

Control-O

Insert a blank line at cursor location.在光标位置插入空行。

Control-P

Cursor up; move up one line.光标向上;上移一行。

Move operations do nothing if the cursor is at an edge where the movement is not possible. 如果光标位于无法移动的边缘,则移动操作不会起任何作用。The following synonyms are supported where possible:在可能的情况下,支持以下同义词:

Constant

Keystroke

KEY_LEFT

Control-B

KEY_RIGHT

Control-F

KEY_UP

Control-P

KEY_DOWN

Control-N

KEY_BACKSPACE

Control-h

All other keystrokes are treated as a command to insert the given character and move right (with line wrapping).所有其他键击都被视为插入给定字符并向右移动(换行)的命令。

gather()

Return the window contents as a string; whether blanks in the window are included is affected by the stripspaces member.以字符串形式返回窗口内容;窗口中是否包含空格受stripspaces成员的影响。

stripspaces

This attribute is a flag which controls the interpretation of blanks in the window. 此属性是控制窗口中空白解释的标志。When it is on, trailing blanks on each line are ignored; any cursor motion that would land the cursor on a trailing blank goes to the end of that line instead, and trailing blanks are stripped when the window contents are gathered.启用时,将忽略每行上的尾随空格;任何将光标落在尾随空格上的光标移动都会转到该行的末尾,并且在收集窗口内容时,尾随空格会被剥离。