curses --- 文字セル表示のターミナル処理

ソースコード: Lib/curses


The curses module provides an interface to the curses library, the de-facto standard for portable advanced terminal handling.

curses が最も広く用いられているのは Unix 環境ですが、Windows、DOS で利用できるバージョンもあり、おそらく他のシステムで利用できるバージョンもあります。この拡張モジュールは Linux および BSD 系の Unixで動作するオープンソースの curses ライブラリである ncurses の API に合致するように設計されています。

Availability: not Android, not iOS, not WASI.

このモジュールは モバイルプラットフォームWebAssemblyプラットフォーム をサポートしません。

This is an optional module. If it is missing from your copy of CPython, look for documentation from your distributor (that is, whoever provided Python to you). If you are the distributor, see オプションのモジュールの要件.

Availability: Unix.

注釈

Whenever the documentation mentions a character it can be specified as an integer, a one-character Unicode string or a one-byte byte string.

Whenever the documentation mentions a character string it can be specified as a Unicode string or a byte string.

参考

curses.ascii モジュール

ロケール設定に関わらず ASCII 文字を扱うためのユーティリティ。

curses.panel モジュール

curses ウィンドウにデプス機能を追加するパネルスタック拡張。

curses.textpad モジュール

Emacs ライクなキーバインディングをサポートする編集可能な curses 用テキストウィジェット。

Python で Curses プログラミング

Andrew Kuchling および Eric Raymond によって書かれた、curses を Python で使うためのチュートリアルです。

関数

The module curses defines the following exception:

exception curses.error

curses ライブラリ関数がエラーを返した際に送出される例外です。

注釈

関数やメソッドにおけるオプションの引数 x および y がある場合、デフォルト値は常に現在のカーソルになります。オプションの attr がある場合、デフォルト値は A_NORMAL です。

The module curses defines the following functions:

curses.assume_default_colors(fg, bg, /)

Allow use of default values for colors on terminals supporting this feature. Use this to support transparency in your application.

  • Assign terminal default foreground/background colors to color number -1. So init_pair(x, COLOR_RED, -1) will initialize pair x as red on default background and init_pair(x, -1, COLOR_BLUE) will initialize pair x as default foreground on blue.

  • Change the definition of the color-pair 0 to (fg, bg).

This is an ncurses extension.

Added in version 3.14.

curses.alloc_pair(fg, bg)

Allocate a color pair for foreground color fg and background color bg, and return its number. If a color pair for the same combination of colors already exists, return its number. Otherwise allocate a new color pair and return its number.

This function is only available if Python was built against a wide-character version of the underlying curses library with extended-color support (see has_extended_color_support()).

Added in version 3.16.0a0 (unreleased).

curses.baudrate()

端末の出力速度をビット/秒で返します。ソフトウェア端末エミュレータの場合、これは固定の高い値を持つことになります。この関数は歴史的な理由で入れられています; かつては、この関数は時間遅延を生成するための出力ループを書くために用いられたり、行速度に応じてインターフェースを切り替えたりするために用いられたりしていました。

curses.beep()

注意を促す短い音を鳴らします。

curses.can_change_color()

端末に表示される色をプログラマが変更できるか否かによって、True または False を返します。

curses.cbreak()

cbreak モードに入ります。cbreak モード ("rare" モードと呼ばれることもあります) では、通常の tty 行バッファリングはオフにされ、文字を一文字一文字読むことができます。ただし、raw モードとは異なり、特殊文字 (割り込み:interrupt、終了:quit、一時停止:suspend、およびフロー制御) については、tty ドライバおよび呼び出し側のプログラムに対する通常の効果をもっています。まず 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. 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). Raise an exception if the color is not supported.

curses.color_pair(pair_number)

Return the attribute value for displaying text in the specified color pair. Only color pairs that fit in the color-pair field of the returned value can be represented (usually the first 256); a larger pair_number raises OverflowError rather than being silently masked to a different pair. Use color_set() or attr_set() to display higher pairs. This attribute value can be combined with A_STANDOUT, A_REVERSE, and the other A_* attributes. pair_number() is the counterpart to this function.

curses.curs_set(visibility)

カーソルの状態を設定します。visibility01``または ``2 に設定され、それぞれ不可視、通常、または非常に可視、を意味します。要求された可視属性を端末がサポートしている場合、以前のカーソル状態が返されます; そうでなければ例外が送出されます。多くの端末では、"可視 (通常)" モードは下線カーソルで、"非常に可視" モードはブロックカーソルです。

curses.def_prog_mode()

現在の端末属性を、稼動中のプログラムが curses を使う際のモードである "プログラム" モードとして保存します。(このモードの反対は、プログラムが curses を使わない "シェル" モードです。) その後 reset_prog_mode() を呼ぶとこのモードを復旧します。

curses.def_shell_mode()

現在の端末属性を、稼動中のプログラムが curses を使っていないときのモードである "シェル" モードとして保存します。(このモードの反対は、プログラムが curses 機能を利用している "プログラム" モードです。) その後 reset_shell_mode() を呼ぶとこのモードを復旧します。

curses.delay_output(ms)

出力に 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. The doupdate() function updates the physical screen to match the virtual screen.

仮想スクリーンは addstr() のような書き込み操作をウィンドウに行った後に noutrefresh() を呼び出して更新することができます。通常の:meth:~window.refresh 呼び出しは、単に noutrefresh() を呼んだ後に doupdate`を呼ぶだけです; 複数のウィンドウを更新しなければならない場合、すべてのウィンドウに対して :meth:()!noutrefresh` を呼び出した後、一度だけ doupdate() を呼ぶことで、パフォーマンスを向上させることができ、おそらくスクリーンのちらつきも押さえることができます。

curses.echo()

echo モードに入ります。echo モードでは、各文字入力はスクリーン上に入力された通りにエコーバックされます。

curses.endwin()

ライブラリの非初期化を行い、端末を通常の状態に戻します。

curses.erasechar()

Return the user's current erase character as a raw byte, a bytes object of length 1. See also erasewchar().

curses.erasewchar()

Return the user's current erase character as a one-character str. 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.

Added in version 3.16.0a0 (unreleased).

curses.filter()

The filter() routine, if used, must be called before initscr() is called. The effect is that, during the initialization, 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. 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.nofilter()

Undo the effect of a previous filter() call. Like filter(), it must be called before initscr() (or newterm()) so that the next initialization uses the full screen again.

Availability: if the underlying curses library provides nofilter().

Added in version 3.16.0a0 (unreleased).

curses.find_pair(fg, bg)

Return the number of a color pair for foreground color fg and background color bg, or -1 if no color pair for this combination of colors has been allocated.

This function is only available if Python was built against a wide-character version of the underlying curses library with extended-color support (see has_extended_color_support()).

Added in version 3.16.0a0 (unreleased).

curses.flash()

スクリーンを点滅します。すなわち、画面を色反転して、短時間でもとにもどします。人によっては、beep() で生成される注意音よりも、このような "目に見えるベル" を好みます。

curses.flushinp()

すべての入力バッファをフラッシュします。この関数は、ユーザによってすでに入力されているが、まだプログラムによって処理されていないすべての先行入力文字を破棄します。

curses.free_pair(pair_number)

Free the color pair pair_number, which must have been allocated by alloc_pair(). The pair must not be in use.

This function is only available if Python was built against a wide-character version of the underlying curses library with extended-color support (see has_extended_color_support()).

Added in version 3.16.0a0 (unreleased).

curses.getmouse()

getch()KEY_MOUSE を返してマウスイベントを通知した後、この関数を呼んで待ち行列上に置かれているマウスイベントを取得しなければなりません。イベントは (id, x, y, z, bstate) の 5 要素のタプルで表現されています。id は複数のデバイスを区別するための ID 値で、x, y, z はイベントの座標値です。(現在 z は使われていません) bstate は整数値で、その各ビットはイベントのタイプを示す値に設定されています。この値は以下に示す定数のうち一つまたはそれ以上のビット単位 OR になっています。以下の定数の n は 1 から 5 のボタン番号を示します: BUTTONn_PRESSED, BUTTONn_RELEASED, BUTTONn_CLICKED, BUTTONn_DOUBLE_CLICKED, BUTTONn_TRIPLE_CLICKED, BUTTON_SHIFT, BUTTON_CTRL, BUTTON_ALT

バージョン 3.10 で変更: The BUTTON5_* constants are now exposed if they are provided by the underlying curses library.

curses.getsyx()

仮想スクリーンにおける現在のカーソル位置をタプル (y, x) で返します。 leaveok()True に設定されていれば、 (-1, -1) が返されます。

curses.getwin(file)

Read window-related data stored in the file by an earlier window.putwin() call. The routine then creates and initializes a new window using that data, returning the new window object. The file argument must be a file object opened for reading in binary mode.

curses.has_colors()

端末が色表示を行える場合には True を返します。そうでない場合には False を返します。

curses.has_extended_color_support()

Return True if the module supports extended colors; otherwise, return False. Extended color support allows more than 256 color pairs for terminals that support more than 16 colors (for example, xterm-256color).

Extended color support requires ncurses version 6.1 or later.

Added in version 3.10.

curses.has_ic()

端末が文字の挿入/削除機能を持つ場合に True を返します。最近の端末エミュレータはどれもこの機能を持っており、この関数は歴史的な理由のためだけに存在しています。

curses.has_il()

端末が行の挿入/削除機能を持つ場合に True を返します。最近の端末エミュレータはどれもこの機能を持っていて、この関数は歴史的な理由のためだけに存在しています。

curses.has_key(ch)

キー値 ch をとり、現在の端末タイプがその値のキーを認識できる場合に True を返します。

curses.has_mouse()

Return True if the mouse driver has been successfully initialized.

Added in version 3.16.0a0 (unreleased).

curses.define_key(definition, keycode)

Define an escape sequence definition, a string, as a key that generates the key code keycode, so that curses interprets it like one of the keys predefined in the terminal database.

If definition is None, any existing binding for keycode is removed. If keycode is zero or negative, any existing binding for definition is removed.

Added in version 3.16.0a0 (unreleased).

curses.key_defined(definition)

Return the key code bound to the escape sequence definition, a string, 0 if no key code is bound to it, or -1 if definition is a prefix of a longer bound sequence (and so is ambiguous).

Added in version 3.16.0a0 (unreleased).

curses.keyok(keycode, enable)

Enable (if enable is true) or disable (otherwise) interpretation of the key code keycode. Unlike window.keypad(), this affects a single key code rather than all of them.

Added in version 3.16.0a0 (unreleased).

curses.halfdelay(tenths)

半遅延モード、すなわち cbreak モードに似た、ユーザが打鍵した文字がすぐにプログラムで利用できるようになるモードで使われます。しかしながら、何も入力されなかった場合、十分の tenths 秒後に例外が送出されます。tenths の値は 1 から 255 の間でなければなりません。半遅延モードから抜けるには nocbreak() を使います。

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

色の定義を変更します。変更したい色番号と、その後に 3 つ組みの RGB 値 (赤、緑、青の成分の大きさ) をとります。color_number の値は 0 から COLORS - 1 の間でなければなりません。r, g, b の値は 0 から 1000 の間でなければなりません。init_color() を使うと、スクリーン上でカラーが使用されている部分はすべて新しい設定に即時変更されます。この関数はほとんどの端末で何も行いません; 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 can only be changed by use_default_colors() and assume_default_colors()). The value of fg and bg arguments must be between 0 and COLORS - 1, or, after calling use_default_colors() or assume_default_colors(), -1. If 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()

ライブラリを初期化します。スクリーン全体をあらわす ウィンドウ オブジェクトを返します。

注釈

端末のオープン時にエラーが発生した場合、curses ライブラリによってインタープリタが終了される場合があります。

curses.intrflush(flag)

If flag is True, pressing an interrupt key (interrupt, break, or quit) will flush all output in the terminal driver queue. If flag is False, no flushing is done.

curses.is_cbreak()

Return True if cbreak mode (see cbreak()) is enabled, False otherwise. Availability: ncurses 6.5 or later.

Added in version 3.16.0a0 (unreleased).

curses.is_echo()

Return True if echo mode (see echo()) is enabled, False otherwise. Availability: ncurses 6.5 or later.

Added in version 3.16.0a0 (unreleased).

curses.is_nl()

Return True if nl mode (see nl()) is enabled, False otherwise. Availability: ncurses 6.5 or later.

Added in version 3.16.0a0 (unreleased).

curses.is_raw()

Return True if raw mode (see raw()) is enabled, False otherwise. Availability: ncurses 6.5 or later.

Added in version 3.16.0a0 (unreleased).

curses.is_term_resized(nlines, ncols)

resize_term() によってウィンドウ構造が変更されている場合に True を、そうでない場合は False を返します。

curses.isendwin()

endwin() がすでに呼び出されている (すなわち、curses ライブラリが非初期化されてしまっている) 場合に True を返します。

curses.keyname(k)

bytes オブジェクト k に番号付けされているキーの名前を返します。 印字可能な ASCII 文字を生成するキーの名前はそのキーの文字自体になります。 コントロールキーと組み合わせたキーの名前は、キャレット(b'^')の後に対応する ASCII 文字が続く 2 バイトの bytes オブジェクトになります。 Alt キーと組み合わせたキー (128--255) の名前は、先頭に b'M-' が付き、その後に対応する ASCII 文字が続く bytes オブジェクトになります。

Raise a ValueError if k is negative.

curses.killchar()

Return the user's current line kill character as a raw byte, a bytes object of length 1. See also killwchar().

curses.killwchar()

Return the user's current line kill character as a one-character str. 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.

Added in version 3.16.0a0 (unreleased).

curses.longname()

現在の端末について記述している terminfo の長形式 name フィールドが入った bytes オブジェクトを返します。verbose 形式記述の最大長は 128 文字です。この値は initscr() 呼び出しの後でのみ定義されています。

curses.meta(flag)

flagTrue の場合、8 ビット文字の入力を許可します。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 166 milliseconds, or one sixth of a second. Use a negative interval to obtain the interval value without changing it.

curses.mousemask(mousemask)

Set the mouse events to be reported, and return a tuple (availmask, oldmask). availmask indicates which of the specified mouse events can be reported; on complete failure it returns 0. oldmask is the previous value of the mouse event mask. If this function is never called, no mouse events are ever reported.

curses.napms(ms)

ms ミリ秒間スリープします。

curses.newpad(nlines, ncols)

与えられた行とカラム数を持つパッド (pad) データ構造を生成し、そのポインタを返します。パッドはウィンドウオブジェクトとして返されます。

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. 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. 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.

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

左上の角が (begin_y, begin_x) で、高さ/幅が nlines / ncols の新規 ウィンドウ を返します。

デフォルトでは、ウィンドウは指定された位置からスクリーンの右下まで広がります。

curses.newterm(type=None, fd=None, infd=None, /)

Initialize a new terminal in addition to the one initialized by initscr(), and return a screen for it. This allows a program to drive more than one terminal.

type is the terminal name, as in setupterm(); if None, the value of the TERM environment variable is used. fd and infd are the output and input files for the terminal: either a file object or a file descriptor. They default to sys.stdout and sys.stdin.

The new screen becomes the current one. Use set_term() to switch between screens.

Added in version 3.16.0a0 (unreleased).

curses.new_prescr()

Return a new screen that can be used to call functions that affect global state before initscr() or newterm() is called.

Availability: if the underlying curses library provides new_prescr().

Added in version 3.16.0a0 (unreleased).

curses.nl(flag=True)

newlime モードに入ります。このモードはリターンキーを入力中の改行として変換し、出力時に改行文字を復帰 (return) と改行 (line-feed) に変換します。newline モードは初期化時にはオンになっています。

If flag is False, the effect is the same as calling nonl().

curses.nocbreak()

cbreak モードを終了します。行バッファリングを行う通常の "cooked" モードに戻ります。

curses.noecho()

echo モードを終了します。入力のエコーバックはオフにされます。

curses.nonl()

newline モードを終了します。入力時のリターンキーから改行への変換、および出力時の改行から復帰/改行への低レベル変換を無効化します (ただし、addch('\n') の振る舞いは変更せず、仮想スクリーン上では常に復帰と改行に等しくなります)。変換をオフにすることで、curses は水平方向の動きを少しだけ高速化できることがあります; また、入力中のリターンキーの検出ができるようになります。

curses.noqiflush()

noqiflush() ルーチンを使うと、通常行われている INTRQUIT および SUSP 文字による入力および出力キューのフラッシュが行われなくなります。シグナルハンドラが終了した際、割り込みが発生しなかったかのように出力を続たい場合、ハンドラ中で noqiflush() を呼び出すことができます。

curses.noraw()

raw モードから離れます。行バッファリングを行う通常の "cooked" モードに戻ります。

curses.pair_content(pair_number)

要求された色ペアの色を含むタプル (fg, bg) を返します。pair_number0 から COLOR_PAIRS - 1 の間でなければなりません。

curses.pair_number(attr)

attr に対する色ペアセットの番号を返します。color_pair() はこの関数の逆に相当します。

curses.putp(str)

tputs(str, 1, putchar) と等価です; 現在の端末における、指定された terminfo 機能の値を出力します。putp() の出力は常に標準出力に送られるので注意して下さい。

setupterm() (or initscr()) must be called first.

curses.qiflush([flag])

flagFalse なら、noqiflush() を呼ぶのとと同じ効果です。flagTrue か、引数が与えられていない場合、制御文字が読み出された最にキューはフラッシュされます。

curses.raw()

raw モードに入ります。raw モードでは、通常の行バッファリングと割り込み (interrupt)、終了 (quit)、一時停止 (suspend)、およびフロー制御キーはオフになります; 文字は curses 入力関数に一文字づつ渡されます。

curses.reset_color_pairs()

Discard all color-pair definitions, releasing the color pairs allocated by init_pair() and alloc_pair().

This function is only available if Python was built against a wide-character version of the underlying curses library with extended-color support (see has_extended_color_support()).

Added in version 3.16.0a0 (unreleased).

curses.reset_prog_mode()

端末を "program" モードに復旧し、あらかじめ def_prog_mode() で保存した内容に戻します。

curses.reset_shell_mode()

端末を "shell" モードに復旧し、あらかじめ def_shell_mode() で保存した内容に戻します。

curses.resetty()

端末モードの状態を最後に savetty() を呼び出した時の状態に戻します。

curses.resize_term(nlines, ncols)

resizeterm() で使用されるバックエンド関数で、ウィンドウサイズを変更する時、resize_term() は拡張された領域を埋めます。呼び出したアプリケーションはそれらの領域を適切なデータで埋めなくてはなりません。resize_term() 関数はすべてのウィンドウのサイズ変更を試みます。ただし、パッド呼び出しの慣例により、アプリケーションとの追加のやり取りを行わないサイズ変更は行えません。

curses.resizeterm(nlines, ncols)

現在の標準ウィンドウのサイズを指定された寸法に変更し、curses ライブラリが使用する、その他のウィンドウサイズを記憶しているデータ (特に SIGWINCH ハンドラ) を調整します。

curses.savetty()

resetty() で使用される、バッファ内の端末モードの現在の状態を保存します。

curses.scr_dump(filename)

Write the current contents of the virtual screen to filename, which may be a string or a path-like object. The file can later be read by scr_restore(), scr_init() or scr_set(). This is the whole-screen counterpart of window.putwin().

Added in version 3.16.0a0 (unreleased).

curses.scr_restore(filename)

Set the virtual screen to the contents of filename, which must have been written by scr_dump(). The next call to doupdate() or window.refresh() restores the screen to those contents.

Added in version 3.16.0a0 (unreleased).

curses.scr_init(filename)

Initialize the assumed contents of the terminal from filename, which must have been written by scr_dump(). Use it when the terminal already displays those contents, for example after another program has drawn the screen, so that curses does not redraw what is already there.

Added in version 3.16.0a0 (unreleased).

curses.scr_set(filename)

Use filename, which must have been written by scr_dump(), as both the virtual screen and the assumed terminal contents. This combines the effects of scr_restore() and scr_init().

Added in version 3.16.0a0 (unreleased).

curses.get_escdelay()

Retrieves the value set by set_escdelay().

Added in version 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.

Added in version 3.9.

curses.get_tabsize()

Retrieves the value set by set_tabsize().

Added in version 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.

Added in version 3.9.

curses.set_term(screen, /)

Make screen, a screen returned by newterm(), the current terminal, and return the previously current screen. Returns None if the previous screen was the one created by initscr().

Added in version 3.16.0a0 (unreleased).

curses.setsyx(y, x)

仮想スクリーンのカーソルを y, x に設定します。y および x がどちらも -1 の場合、 leaveok() が に``True``に設定されます。

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

端末を初期化します。term は端末名となる文字列または None です。省略または None の場合、環境変数 TERM の値が使用されます。fd は送信される初期化シーケンスへのファイル記述子です。指定されないまたは -1 の場合、sys.stdout のファイル記述子が使用されます。

Raise a curses.error if the terminal could not be found or its terminfo database entry could not be read. If the terminal has already been initialized, this function has no effect.

curses.start_color()

プログラマがカラーを利用したい場合で、かつ他の何らかのカラー操作ルーチンを呼び出す前に呼び出さなくてはなりません。この関数は 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. It also restores the colors on the terminal to the values they had when the terminal was just turned on.

curses.termattrs()

端末がサポートするすべてのビデオ属性を論理和した値を返します。この情報は、curses プログラムがスクリーンの見え方を完全に制御する必要がある場合に便利です。

curses.term_attrs()

Like termattrs(), but return the attributes as WA_* values rather than A_* values.

Added in version 3.16.0a0 (unreleased).

curses.termname()

14 文字以下になるように切り詰められた環境変数 TERM の値を bytes オブジェクトで返します。

curses.tigetflag(capname)

terminfo 機能名 capname に対応する真偽値の機能値を整数で返します。capname が真偽値で表せる機能値でない場合 -1 を返し、機能がキャンセルされているか、端末記述上に見つからない場合 0 を返します。

setupterm() (or initscr()) must be called first.

curses.tigetnum(capname)

terminfo 機能名 capname に対応する数値の機能値を整数で返します。capname が数値で表せる機能値でない場合 -2 を返し、機能がキャンセルされているか、端末記述上に見つからない場合 -1 を返します。

setupterm() (or initscr()) must be called first.

curses.tigetstr(capname)

Return the value of the string capability corresponding to the terminfo capability name capname as a bytes object. Return None if capname is not a terminfo "string capability", or is canceled or absent from the terminal description.

setupterm() (or initscr()) must be called first.

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

Instantiate the bytes object str with the supplied parameters, where str should be a parameterized string obtained from the terminfo database. For example, tparm(tigetstr("cup"), 5, 3) could result in b'\033[6;4H', the exact result depending on terminal type. Up to nine integer parameters may be supplied.

setupterm() (or initscr()) must be called first.

curses.typeahead(fd)

先読みチェックに使うためのファイル記述子 fd を指定します。fd-1 の場合、先読みチェックは行われません。

curses ライブラリはスクリーンを更新する間、先読み文字列を定期的に検索することで "行はみ出し最適化 (line-breakout optimization)" を行います。入力が得られ、かつ入力は端末からのものである場合、現在行おうとしている更新は refresh や doupdate を再度呼び出すまで先送りにします。この関数は異なるファイル記述子で先読みチェックを行うように指定することができます。

curses.unctrl(ch)

Return a bytes object which is a printable representation of the character ch. ch cannot be a character that does not fit in a single byte; use wunctrl() for those.

curses.wunctrl(ch)

Return a string which is a printable representation of the character ch; any attributes and color pair are ignored. ASCII control characters are represented as a caret followed by a character, for example as '^C'. Printing characters, including non-ASCII characters printable in the locale, are left as they are. The representation of other characters is defined by the underlying curses library.

Added in version 3.16.0a0 (unreleased).

curses.ungetch(ch)

Push ch so the next getch() or get_wch() will return it.

ch may be an integer (a key code or character code), a byte, or a string of length 1. A one-character string is pushed like unget_wch(); on a narrow build it must encode to a single byte.

注釈

getch() を呼び出すまでは ch は一つしかプッシュできません。

バージョン 3.16.0a0 (unreleased) で変更: A one-character string argument is no longer required to encode to a single byte, except on a narrow build.

curses.update_lines_cols()

Update the LINES and COLS module variables. Useful for detecting manual screen resize.

Added in version 3.5.

curses.unget_wch(ch)

ch をプッシュし、次に get_wch() を呼び出した時にその値が返るようにします。

注釈

get_wch() を呼び出すまでは ch は一つしかプッシュできません。

Added in version 3.3.

バージョン 3.16.0a0 (unreleased) で変更: Also available on a narrow build, where ch must encode to a single byte (an 8-bit locale).

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

与えられた状態データが関連付けられた KEY_MOUSE イベントを入力キューにプッシュします。

curses.use_env(flag)

この関数を使う場合、initscr() または newterm を呼ぶ前に呼び出さなくてはなりません。flagFalse の場合、環境変数 LINES および COLUMNS の値 (デフォルトで使用されます) の値が設定されていたり、curses がウィンドウ内で動作して (この場合 LINESCOLUMNS が設定されていないとウィンドウのサイズを使います) いても、terminfo データベースに指定された lines および columns の値を使います。

curses.use_default_colors()

Equivalent to assume_default_colors(-1, -1).

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

curses を初期化し、呼び出し可能なオブジェクト func (その他の curses を使用するアプリケーション) を呼び出します。アプリケーションが例外を送出した場合、この関数は端末を例外を再送出する前に正常な状態に戻し、トレースバックを作成します。その後、呼び出し可能オブジェクト func には、第一引数としてメインウィンドウ 'stdscr' が、続いて wrapper() に渡されたその他の引数が渡されます。func を呼び出す前、wrapper() は cbreak モードをオンに、エコーをオフに、端末キーパッドを有効にし、端末が色表示をサポートしている場合は色を初期化します。終了時 (通常終了、例外による終了のどちらでも)、cooked モードに戻し、エコーをオンにし、端末キーパッドを無効にします。

Window objects

class curses.window

上記の initscr()newwin() が返すウィンドウは、以下のメソッドと属性を持ちます:

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

(y, x) にある文字 ch を属性 attr で描画します。このときその場所に以前描画された文字は上書きされます。デフォルトでは、文字の位置および属性はウィンドウオブジェクトにおける現在の設定になります。

ch may be a single character, optionally followed by combining characters, that together occupy one character cell.

注釈

Writing outside the window, subwindow, or pad raises a curses.error. Attempting 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.

バージョン 3.16.0a0 (unreleased) で変更: A character may now be given as a string of a base character followed by combining characters, instead of only a single character, or as a complexchar cell.

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

文字列 str から最大で n 文字を (y, x) に属性 attr で描画します。以前ディスプレイにあった内容はすべて上書きされます。

バージョン 3.16.0a0 (unreleased) で変更: str may now also be a complexstr; see addstr().

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

(y, x) に文字列 str を属性 attr で描画します。以前ディスプレイにあった内容はすべて上書きされます。

str may also be a complexstr, in which case each cell carries its own attributes and color pair, so attr must not be given. A complexstr obtained from in_wchstr() is written back unchanged.

注釈

  • Writing outside the window, subwindow, or pad raises curses.error. Attempting 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.

  • A bug in ncurses, the backend for this Python module, could cause segfaults when resizing windows. This was fixed in ncurses-6.1-20190511. If you are stuck with an earlier ncurses, you can avoid triggering it by not calling addstr() with a str that has embedded newlines; instead, call addstr() separately for each line.

バージョン 3.16.0a0 (unreleased) で変更: str may now also be a complexstr, as described above.

window.attroff(attr)

現在のウィンドウに書き込まれたすべての内容に対し "バックグラウンド" に設定された属性 attr を除去します。

window.attron(attr)

Add attribute attr to the "background" set applied to all writes to the current window.

window.attrset(attr)

"バックグラウンド" の属性セットを attr に設定します。初期値は 0 (属性なし) です。

window.attr_get()

Return the window's current rendition as a (attrs, pair) tuple, where attrs is the set of attributes and pair is the color pair number.

Unlike attron() and friends, which take packed A_* attributes, this method and the other attr_* methods work with the WA_* attributes and keep the color pair as a separate number, which lets them use color pairs that do not fit alongside the attributes in a single value.

Added in version 3.16.0a0 (unreleased).

window.attr_set(attr, pair=0)

Set the window's rendition to the attributes attr and the color pair pair.

Added in version 3.16.0a0 (unreleased).

window.attr_on(attr)

Turn on the attributes attr without affecting any others.

Added in version 3.16.0a0 (unreleased).

window.attr_off(attr)

Turn off the attributes attr without affecting any others.

Added in version 3.16.0a0 (unreleased).

window.color_set(pair)

Set the window's color pair to pair, leaving the other attributes unchanged.

Added in version 3.16.0a0 (unreleased).

window.getattrs()

Return the window's current attributes.

Added in version 3.16.0a0 (unreleased).

window.bkgd(ch[, attr])

ウィンドウ上の背景プロパティを、attr を属性とする文字 ch に設定します。変更はそのウィンドウ中のすべての文字に以下のようにして適用されます:

  • ウィンドウ中のすべての文字の属性が新たな背景属性に変更されます。

  • 以前の背景文字が出現すると、常に新たな背景文字に変更されます。

バージョン 3.16.0a0 (unreleased) で変更: Wide and combining characters, and complexchar cells, are now accepted.

window.bkgdset(ch[, attr])

ウィンドウの背景を設定します。ウィンドウの背景は、文字と何らかの属性の組み合わせから成り立ちます。背景情報の属性の部分は、ウィンドウ上に描画されている空白でないすべての文字と組み合わされ (OR され) ます。空白文字には文字部分と属性部分の両方が組み合わされます。背景は文字のプロパティとなり、スクロールや行/文字の挿入/削除操作の際には文字と一緒に移動します。

バージョン 3.16.0a0 (unreleased) で変更: Wide and combining characters, and complexchar cells, are now accepted.

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

ウィンドウの縁に境界線を描画します。各引数には境界の特定部分を表現するために使われる文字を指定します; 詳細は以下のテーブルを参照してください。

注釈

どの引数も、0 を指定した場合デフォルトの文字が使われるようになります。キーワード引数は使うことが できません。デフォルトはテーブル内で示しています:

引数

説明

デフォルト値

ls

左側

ACS_VLINE

rs

右側

ACS_VLINE

ts

上側

ACS_HLINE

bs

下側

ACS_HLINE

tl

左上の角

ACS_ULCORNER

tr

右上の角

ACS_URCORNER

bl

左下の角

ACS_LLCORNER

br

右下の角

ACS_LRCORNER

バージョン 3.16.0a0 (unreleased) で変更: Wide and combining characters, and complexchar cells, are now accepted. A single call cannot mix them with integer or byte characters.

window.box([vertch, horch])

border() と同様ですが、ls および rs は共に vertch で、ts および bs は共に horch です。この関数では、角に使われるデフォルト文字が常に使用されます。

バージョン 3.16.0a0 (unreleased) で変更: Wide and combining characters, and complexchar cells, are now accepted. A single call cannot mix them with integer or byte characters.

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. If num is not given or is -1, the attribute will be set on all the characters to the end of the line. This function moves cursor to position (y, x) if supplied. The changed line will be touched using the touchline() method so that the contents will be redisplayed by the next window refresh.

window.clear()

erase() に似ていますが、次に refresh() が呼び出された際にすべてのウィンドウを再描画するようにします。

window.clearok(flag)

flagTrue ならば、次の refresh() はウィンドウを完全に消去します。

window.clrtobot()

カーソルの位置からウィンドウの端までを消去します: カーソル以降のすべての行が削除されるため、clrtoeol() と等価です。

window.clrtoeol()

カーソル位置から行末までを消去します。

window.cursyncup()

ウィンドウのすべての親ウィンドウについて、現在のカーソル位置を反映するよう更新します。

window.delch([y, x])

Delete the character under the cursor, or at (y, x) if specified. All characters to the right on the same line are shifted one position left.

window.deleteln()

カーソルの下にある行を削除します。後続の行はすべて 1 行上に移動します。

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

"derive window (ウィンドウを派生する)" の短縮形です。derwin()subwin() と同じですが、begin_y および begin_x はスクリーン全体の原点ではなく、ウィンドウの原点からの相対位置です。派生したウィンドウオブジェクトが返されます。

window.dupwin()

Return a new window that is an exact duplicate of the window: it has the same size, position, contents and attributes. Unlike a window created by subwin() or derwin(), the duplicate is independent of the original -- it has its own cell buffer, so later changes to one do not affect the other.

Added in version 3.16.0a0 (unreleased).

window.echochar(ch[, attr])

文字 ch に属性 attr を付与し、即座に refresh() をウィンドウに対して呼び出します。

バージョン 3.16.0a0 (unreleased) で変更: Wide and combining characters, and complexchar cells, are now accepted.

window.enclose(y, x)

与えられた文字セル座標をスクリーン原点から相対的なものとし、ウィンドウの中に含まれるかを調べて、True または False を返します。スクリーン上のウィンドウの一部がマウスイベントの発生場所を含むかどうかを調べる上で便利です。

バージョン 3.10 で変更: Previously it returned 1 or 0 instead of True or False.

window.mouse_trafo(y, x, to_screen)

Convert between window-relative and screen-relative (stdscr-relative) character-cell coordinates. If to_screen is true, convert the window-relative coordinates y, x to screen-relative coordinates; otherwise convert in the opposite direction. The two coordinate systems differ when lines are reserved on the screen, for example for soft labels.

Return the converted coordinates as a (y, x) tuple, or None if they lie outside the window.

Added in version 3.16.0a0 (unreleased).

window.encoding

encode メソッドの引数 (Unicode 文字列および文字) で使用されるエンコーディングです。例えば window.subwin() などでサブウィンドウを生成した時、エンコーディング属性は親ウィンドウから継承します。デフォルトでは、現在のロケールのエンコーディングが使用されます (locale.getencoding() 参照)。

Added in version 3.3.

window.erase()

ウィンドウをクリアします。

window.getbegyx()

Return a tuple (y, x) of coordinates of upper-left corner.

window.getbkgd()

Return the given window's current background character/attribute pair. Its components can be extracted like those of inch(). It cannot represent a background set with a wide character or with a color pair outside the color_pair() range; use getbkgrnd() for those.

window.getbkgrnd()

Return the given window's current background as a complexchar. Unlike getbkgd(), the returned object carries the background character together with its attributes and color pair, and the color pair is not limited to the value that fits in a color_pair().

Added in version 3.16.0a0 (unreleased).

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. In no-delay mode, return -1 if there is no input, otherwise wait until a key is pressed. A multibyte character is returned as its encoded bytes one at a time; use get_wch() to read it as a single character.

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. Unlike getch(), an ordinary key is returned as a one-character str. In no-delay mode, raise an exception if there is no input.

Added in version 3.3.

バージョン 3.16.0a0 (unreleased) で変更: Also available on a narrow build, where only a character representable as a single byte (an 8-bit locale) can be returned.

window.getdelay()

Return the window's read timeout in milliseconds, as set by nodelay() or timeout(): -1 for blocking, 0 for non-blocking, or a positive number of milliseconds.

Added in version 3.16.0a0 (unreleased).

window.getkey([y, x])

文字を 1 個取得し、 getch() が返すような整数ではなく文字列を返します。ファンクションキー、キーパッドのキー、およびその他特殊キーはキー名を含む複数文字を返します。無遅延モードでは、入力がない場合例外を送出します。

window.getmaxyx()

ウィンドウの高さおよび幅を表すタプル (y, x) を返します。

window.getparent()

Return the parent window of this subwindow, or None if this window is not a subwindow.

Added in version 3.16.0a0 (unreleased).

window.getparyx()

親ウィンドウ中におけるウィンドウの開始位置をタプル (y, x) で返します。ウィンドウに親ウィンドウがない場合 (-1, -1) を返します。

window.getscrreg()

Return a tuple (top, bottom) of the window's current scrolling region, as set by setscrreg().

Added in version 3.16.0a0 (unreleased).

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. At most n characters are read; n defaults to and cannot exceed 2047. A multibyte character is returned as its encoded bytes; use get_wstr() to read the input as a str.

バージョン 3.14 で変更: The maximum value for n was increased from 1023 to 2047.

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

Read a string from the user, with primitive line editing capacity. Unlike getstr(), it can return characters that are not representable in the window's encoding. At most n characters are read; n defaults to and cannot exceed 2047.

Added in version 3.16.0a0 (unreleased).

window.getyx()

ウィンドウの左上角からの相対で表した現在のカーソル位置をタプル (y, x) で返します。

window.hline(ch, n[, attr])
window.hline(y, x, ch, n[, attr])

Display a horizontal line starting at (y, x) with length n consisting of the character ch with attributes attr. The line stops at the right edge of the window if fewer than n cells are available.

バージョン 3.16.0a0 (unreleased) で変更: Wide and combining characters, and complexchar cells, are now accepted.

window.idcok(flag)

flagFalse の場合、curses は端末のハードウェアによる文字挿入/削除機能を使おうとしなくなります; flagTrue ならば、文字挿入/削除は有効にされます。curses が最初に初期化された際には文字挿入/削除はデフォルトで有効になっています。

window.idlok(flag)

If flag is True, curses will try to use hardware line editing facilities. Otherwise, curses will not use them.

window.immedok(flag)

flagTrue ならば、ウィンドウイメージ内における何らかの変更があるとウィンドウを更新するようになります; すなわち、refresh() を自分で呼ばなくても良くなります。とはいえ、wrefresh を繰り返し呼び出すことになるため、この操作はかなりパフォーマンスを低下させます。デフォルトでは無効になっています。

window.inch([y, x])

Return the character at the given position in the window. The bottom 8 bits are the character proper and the upper bits are the attributes; extract them with the A_CHARTEXT and A_ATTRIBUTES bit-masks, and the color pair with pair_number(). It cannot represent a cell holding combining characters, a character that does not fit in a single byte, or a color pair outside the color_pair() range; use in_wch() for those, which returns it as a complexchar.

window.in_wch([y, x])

Return the complex character at the given position in the window as a complexchar. Unlike inch(), the returned object carries the cell's text (a spacing character optionally followed by combining characters) together with its attributes and color pair.

Added in version 3.16.0a0 (unreleased).

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

Insert character ch with attributes attr before the character under the cursor, or at (y, x) if specified. All characters to the right of the cursor are shifted one position right, with the rightmost character on the line being lost. The cursor position does not change.

バージョン 3.16.0a0 (unreleased) で変更: Wide and combining characters, and complexchar cells, are now accepted.

window.insdelln(nlines)

nlines 行を指定されたウィンドウの現在の行の上に挿入します。その下にある nlines 行は失われます。負の nlines を指定すると、カーソルのある行以降の nlines を削除し、削除された行の後ろに続く内容が上に来ます。その下にある nlines は消去されます。現在のカーソル位置はそのままです。

window.insertln()

カーソルの下に空行を 1 行入れます。それ以降の行は 1 行づつ下に移動します。

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

文字列をカーソルの下にある文字の前に (一行に収まるだけ) 最大 n 文字挿入します。n がゼロまたは負の値の場合、文字列全体が挿入されます。カーソルの右にあるすべての文字は右に移動し、行の左端にある文字は失われます。カーソル位置は (y, x が指定されていた場合はそこに移動しますが、その後は) 変化しません。

バージョン 3.16.0a0 (unreleased) で変更: str may now also be a complexstr; see insstr().

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

キャラクタ文字列を (行に収まるだけ) カーソルより前に挿入します。カーソルの右側にある文字はすべて右にシフトし、行の右端の文字は失われます。カーソル位置は (y, x が指定されていた場合はそこに移動しますが、その後は) 変化しません。

str may also be a complexstr, in which case each cell carries its own attributes and color pair, so attr must not be given.

バージョン 3.16.0a0 (unreleased) で変更: str may now also be a complexstr, as described above.

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, and stopping at the end of the line. Attributes and color information are stripped from the characters. If n is specified, instr() returns a string at most n characters long (exclusive of the trailing NUL). The maximum value for n is 2047. A character not representable in the window's encoding cannot be returned; use in_wstr() for those.

バージョン 3.14 で変更: The maximum value for n was increased from 1023 to 2047.

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

Return a string of characters, extracted from the window starting at the current cursor position, or at y, x if specified. Unlike instr(), it can return characters that are not representable in the window's encoding. Attributes and color information are stripped from the characters. The maximum value for n is 2047.

Added in version 3.16.0a0 (unreleased).

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

Return a complexstr of the styled cells extracted from the window starting at the current cursor position, or at y, x if specified, and stopping at the end of the line. This is the variant of instr() and in_wstr() that keeps each cell's attributes and color pair (those methods strip the rendition). If n is specified, at most n cells are returned. The maximum value for n is 2047.

The result can be written back unchanged with addstr() (a read and a re-write is a round-trip that preserves every cell's rendition).

Added in version 3.16.0a0 (unreleased).

window.is_cleared()

Return the current value set by clearok().

Added in version 3.16.0a0 (unreleased).

window.is_idcok()

Return the current value set by idcok().

Added in version 3.16.0a0 (unreleased).

window.is_idlok()

Return the current value set by idlok().

Added in version 3.16.0a0 (unreleased).

window.is_immedok()

Return the current value set by immedok().

Added in version 3.16.0a0 (unreleased).

window.is_keypad()

Return the current value set by keypad().

Added in version 3.16.0a0 (unreleased).

window.is_leaveok()

Return the current value set by leaveok().

Added in version 3.16.0a0 (unreleased).

window.is_linetouched(line)

指定した行が、最後に refresh() を呼んだ時から変更されている場合に True を返します; そうでない場合には False を返します。line が現在のウィンドウ上の有効な行でない場合、curses.error 例外を送出します。

window.is_nodelay()

Return the current value set by nodelay().

Added in version 3.16.0a0 (unreleased).

window.is_notimeout()

Return the current value set by notimeout().

Added in version 3.16.0a0 (unreleased).

window.is_pad()

Return True if the window is a pad created by newpad().

Added in version 3.16.0a0 (unreleased).

window.is_scrollok()

Return the current value set by scrollok().

Added in version 3.16.0a0 (unreleased).

window.is_subwin()

Return True if the window is a subwindow created by subwin() or derwin().

Added in version 3.16.0a0 (unreleased).

window.is_syncok()

Return the current value set by syncok().

Added in version 3.16.0a0 (unreleased).

window.is_wintouched()

指定したウィンドウが、最後に refresh() を呼んだ時から変更されている場合に True を返します; そうでない場合には False を返します。

window.keypad(flag)

If flag is True, escape sequences generated by some keys (keypad, function keys) will be interpreted by curses. If flag is False, escape sequences will be left as is in the input stream.

window.leaveok(flag)

If flag is True, cursor is left where it is on update, instead of being at "cursor position." This reduces cursor movement where possible.

flagFalse の場合、カーソルは更新の際に常に "カーソル位置" に移動します。

window.move(new_y, new_x)

カーソルを (new_y, new_x) に移動します。

window.mvderwin(y, x)

ウィンドウを親ウィンドウの中で移動します。ウィンドウのスクリーン相対となるパラメタ群は変化しません。このルーチンは親ウィンドウの一部をスクリーン上の同じ物理位置に表示する際に用いられます。

window.mvwin(new_y, new_x)

ウィンドウの左上角が (new_y, new_x) になるように移動します。

Moving the window so that any part of it would be off the screen is an error: the window is not moved and curses.error is raised.

window.nodelay(flag)

flagTrue の場合、getch() は非ブロックで動作します。

window.notimeout(flag)

flagTrue の場合、エスケープシーケンスはタイムアウトしなくなります。

flagFalse の場合、数ミリ秒間の間エスケープシーケンスは解釈されず、入力ストリーム中にそのままの状態で残されます。

window.noutrefresh()
window.noutrefresh(pminrow, pmincol, sminrow, smincol, smaxrow, smaxcol)

更新をマークはしますが待機します。この関数はウィンドウのデータ構造を表現したい内容を反映するように更新しますが、物理スクリーン上に反映させるための強制更新を行いません。更新を行うためには doupdate() を呼び出します。

The 6 arguments can only be specified, and are then required, when the window is a pad created with newpad(); they have the same meaning as for refresh().

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

ウィンドウを destwin の上に重ね書き (overlay) します。ウィンドウは同じサイズである必要はなく、重なっている領域だけが複写されます。この複写は非破壊的です。これは現在の背景文字が destwin の内容を上書きしないことを意味します。

複写領域をきめ細かく制御するために、overlay() の第二形式を使うことができます。sminrow および smincol は元のウィンドウの左上の座標で、他の変数は destwin 内の矩形を表します。

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

destwin の上にウィンドウの内容を上書き (overwrite) します。ウィンドウは同じサイズである必要はなく、重なっている領域だけが複写されます。この複写は破壊的です。これは現在の背景文字が destwin の内容を上書きすることを意味します。

複写領域をきめ細かく制御するために、overwrite() の第二形式を使うことができます。sminrow および smincol は元のウィンドウの左上の座標で、他の変数は destwin 内の矩形を表します。

window.putwin(file)

ウィンドウに関連付けられているすべてのデータを与えられたファイルオブジェクトに書き込みます。この情報は後に getwin() 関数を使って取得することができます。

window.redrawln(beg, num)

beg 行から始まる num スクリーン行の表示内容が壊れており、次の refresh() 呼び出しで完全に再描画されなければならないことを通知します。

window.redrawwin()

ウィンドウ全体を更新 (touch) し、次の refresh() 呼び出しで完全に再描画されるようにします。

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

ディスプレイを即時更新し (実際のウィンドウとこれまでの描画/削除メソッドの内容とを同期し) ます。

The 6 arguments can only be specified, and are then required, when the window is a pad created with newpad(). The additional parameters are needed to indicate what part of the pad and screen are involved. pminrow and pmincol specify the upper-left corner of the rectangle to be displayed in the pad. sminrow, smincol, smaxrow, and smaxcol specify the edges of the rectangle to be displayed on the screen. The lower-right 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.

window.resize(nlines, ncols)

curses ウィンドウの記憶域を、指定値のサイズに調整するため再割当てします。サイズが現在の値より大きい場合、ウィンドウのデータは現在の背景設定 (bkgdset() で設定) で埋められマージされます。

window.scroll([lines=1])

Scroll the screen or scrolling region. Scroll upward by lines lines if lines is positive, or downward if it is negative. Scrolling has no effect unless it has been enabled for the window with scrollok().

window.scrollok(flag)

ウィンドウのカーソルが、最下行で改行を行ったり最後の文字を入力したりした結果、ウィンドウやスクロール領域の縁からはみ出して移動した際の動作を制御します。flagFalse の場合、カーソルは最下行にそのままにしておかれます。flagTrue の場合、ウィンドウは 1 行上にスクロールします。端末の物理スクロール効果を得るためには idlok() も呼び出す必要があるので注意してください。

window.setscrreg(top, bottom)

スクロール領域を top から bottom に設定します。スクロール動作はすべてこの領域で行われます。

window.standend()

A_STANDOUT 属性をオフにします。端末によっては、この操作ですべての属性をオフにする副作用が発生します。

window.standout()

A_STANDOUT 属性をオンにします。

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

Return a sub-pad, whose upper-left corner is at (begin_y, begin_x), and whose width/height is ncols/nlines. The coordinates are relative to the parent pad (unlike subwin(), which uses screen coordinates). This method is only available for pads created with newpad().

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

Return a sub-window, whose upper-left corner is at the screen-relative coordinates (begin_y, begin_x), and whose width/height is ncols/nlines.

デフォルトでは、サブウィンドウは指定された場所からウィンドウの右下角まで広がります。

window.syncdown()

このウィンドウの上位のウィンドウのいずれかで更新(touch)された各場所をこのウィンドウ内でも更新します。このルーチンは refresh() から呼び出されるので、手動で呼び出す必要はほとんどないはずです。

window.syncok(flag)

flagTrue の場合、ウィンドウが変更された際は常に syncup() を自動的に呼ぶようになります。

window.syncup()

ウィンドウ内で更新 (touch) した場所を、上位のすべてのウィンドウ内でも更新します。

window.timeout(delay)

ウィンドウのブロックまたは非ブロック読み込み動作を設定します。delay が負の場合、ブロック読み出しが使われ、入力を無期限で待ち受けます。delay がゼロの場合、非ブロック読み出しが使われ、入力待ちの文字がない場合 getch()-1 を返します。delay が正の値であれば、getch()delay ミリ秒間ブロックし、ブロック後の時点で入力がない場合には -1 を返します。

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

start から始まる count 行が変更されたかのように振舞わせます。もし changed が与えられた場合、その引数は指定された行が変更された(changed=True)か、変更されていないか(changed)を指定します。

window.touchwin()

描画を最適化するために、すべてのウィンドウが変更されたかのように振舞わせます。

window.untouchwin()

ウィンドウ内のすべての行を、最後に refresh() を呼んだ際から変更されていないものとしてマークします。

window.use(func, /, *args, **kwargs)

Call func(window, *args, **kwargs) with the lock of the window held, and return its result. This provides automatic protection for the window against concurrent access from another thread.

Availability: if the underlying curses library provides use_window().

Added in version 3.16.0a0 (unreleased).

window.vline(ch, n[, attr])
window.vline(y, x, ch, n[, attr])

Display a vertical line starting at (y, x) with length n consisting of the character ch with attributes attr.

バージョン 3.16.0a0 (unreleased) で変更: Wide and combining characters, and complexchar cells, are now accepted.

Screen objects

class curses.screen

A screen object represents a terminal initialized by newterm() (or new_prescr()), in addition to the default screen created by initscr(). Screen objects are returned by those functions; they cannot be instantiated directly.

A screen is freed automatically once it is no longer referenced, either directly or through one of its windows. Each window keeps its screen alive, so a screen remains valid as long as any of its windows does.

Added in version 3.16.0a0 (unreleased).

screen.close()

Detach the screen's standard window, breaking the reference cycle between them so the screen can be reclaimed promptly instead of waiting for a garbage collection. Afterwards stdscr is None and the window it returned earlier can no longer be used. The screen's resources are released once it and all its windows are no longer referenced.

Added in version 3.16.0a0 (unreleased).

screen.stdscr

The standard window of the screen, covering the whole terminal, or None for a screen created by new_prescr().

screen.use(func, /, *args, **kwargs)

Call func(screen, *args, **kwargs) with the lock of the screen held, and return its result. This provides automatic protection for the screen against concurrent access from another thread.

Availability: if the underlying curses library provides use_screen().

Added in version 3.16.0a0 (unreleased).

Complex character objects

class curses.complexchar(text, /, attr=0, pair=0)

A complex character (or complexchar) is an immutable styled character cell: a spacing character optionally followed by combining characters, together with a set of attributes and a color pair.

text is the cell's text, attr a combination of the WA_* attributes (equivalent to the matching A_* constants), and pair a color pair number. Unlike the packed chtype used by inch() and the A_* methods, the color pair is stored separately and is not limited to the value that fits in a color_pair().

Complex characters are returned by window.in_wch() and window.getbkgrnd(), and are accepted (along with an integer, a byte or a string) by the character-cell methods such as window.addch(), window.insch(), window.bkgd(), window.border(), window.hline() and window.vline(). A complex character already carries its own rendition, so it cannot be combined with an explicit attr argument.

str() returns the cell's text; two complex characters are equal when their text, attributes and color pair all match.

The same code works on both wide- and narrow-character builds. On a narrow build a cell holds a single character (no combining marks) that must encode to one byte in the window's encoding (8-bit locales only), and pair is limited to the value that fits in a color_pair().

attr

The attributes of the character cell (read-only).

pair

The color pair number of the character cell (read-only).

Added in version 3.16.0a0 (unreleased).

class curses.complexstr(cells[, attr[, pair]])

A complex character string (or complexstr) is an immutable sequence of styled character cells -- the string counterpart of complexchar (as str is to a single character).

If cells is a string, it is split into character cells (each a spacing character optionally followed by combining characters), and attr (a combination of the WA_* attributes) and pair (a color pair number), if given, are applied to every cell.

Otherwise cells is an iterable whose items are themselves cells, each a complexchar or a string; each item then carries its own rendition, and attr and pair must be omitted.

It is returned by window.in_wchstr(), and accepted by window.addstr(), addnstr(), insstr() and insnstr(), so a run read from a window can be written back unchanged.

It behaves like an immutable sequence: len(s) is the number of cells, s[i] is the i-th cell as a complexchar, slicing and concatenation produce new complexstr instances, and iterating yields the cells. str() returns the cells' text joined together, and two complex character strings are equal when their cells all match. It is hashable.

To build or edit a run of cells, use an ordinary list of complexchar (or strings); a complexstr is the immutable form returned by a read.

Like complexchar, this type works on both wide- and narrow-character builds, with the same per-cell limitations on a narrow build.

Added in version 3.16.0a0 (unreleased).

定数

The curses module defines the following data members:

curses.ERR

getch() のような整数を返す curses ルーチンのいくつかは、失敗した際に ERR を返します。

curses.OK

napms() のような整数を返す curses ルーチンのいくつかは、成功した際に OK を返します。

curses.version

A bytes object representing the current version of the module.

curses.ncurses_version

A named tuple containing the three components of the ncurses library version: major, minor, and patch. All 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.

Availability: if the ncurses library is used.

Added in version 3.8.

curses.COLORS

The maximum number of colors the terminal can support. It is defined only after the call to start_color().

curses.COLOR_PAIRS

The maximum number of color pairs the terminal can support. It is defined only after the call to start_color().

curses.COLS

The width of the screen, that is, the number of columns. It is defined only after the call to initscr(). Updated by update_lines_cols(), resizeterm() and resize_term().

curses.LINES

The height of the screen, that is, the number of lines. It is defined only after the call to initscr(). Updated by update_lines_cols(), resizeterm() and resize_term().

Some constants are available to specify character cell attributes. The exact constants available are system dependent.

属性

意味

curses.A_ALTCHARSET

代替文字セットモード

点滅モード

curses.A_BOLD

太字モード

curses.A_DIM

低輝度モード

curses.A_INVIS

Invisible or blank mode

curses.A_ITALIC

イタリックモード

curses.A_NORMAL

通常の属性

curses.A_PROTECT

Protected mode

curses.A_REVERSE

Reverse background and foreground colors

curses.A_STANDOUT

強調モード

curses.A_UNDERLINE

下線モード

curses.A_HORIZONTAL

Horizontal highlight

curses.A_LEFT

Left highlight

curses.A_LOW

Low highlight

curses.A_RIGHT

Right highlight

curses.A_TOP

Top highlight

curses.A_VERTICAL

Vertical highlight

Added in version 3.7: A_ITALIC が追加されました。

The attr_get(), attr_set(), attr_on() and attr_off() methods use a parallel set of WA_* constants. These have the same meaning as the corresponding A_* attributes above (WA_BOLD like A_BOLD, and so on), but belong to the attr_t type rather than being packed into a character. In ncurses the two sets share the same values, but other curses implementations may give them different ones, so use the WA_* constants with the attr_* methods. The available names are WA_ATTRIBUTES, WA_NORMAL, WA_STANDOUT, WA_UNDERLINE, WA_REVERSE, WA_BLINK, WA_DIM, WA_BOLD, WA_ALTCHARSET, WA_INVIS, WA_PROTECT, WA_HORIZONTAL, WA_LEFT, WA_LOW, WA_RIGHT, WA_TOP, WA_VERTICAL and WA_ITALIC (each available only where the platform defines it).

Added in version 3.16.0a0 (unreleased): The WA_* constants were added.

Several constants are available to extract corresponding attributes returned by some methods.

Bit-mask

意味

curses.A_ATTRIBUTES

Bit-mask to extract attributes

curses.A_CHARTEXT

Bit-mask to extract a character

curses.A_COLOR

Bit-mask to extract color-pair field information

キーは KEY_ で始まる名前をもつ整数定数です。利用可能なキーキャップはシステムに依存します。

キー定数

キー

curses.KEY_MIN

最小のキー値

curses.KEY_BREAK

ブレークキー (Break, 信頼できません)

curses.KEY_DOWN

下矢印

curses.KEY_UP

上矢印

curses.KEY_LEFT

左矢印

curses.KEY_RIGHT

右矢印

curses.KEY_HOME

ホームキー (Home, または上左矢印)

curses.KEY_BACKSPACE

バックスペース (Backspace, 信頼できません)

curses.KEY_F0

ファンクションキー。64 個までサポートされています。

curses.KEY_Fn

ファンクションキー n の値

curses.KEY_DL

行削除 (Delete line)

curses.KEY_IL

行挿入 (Insert line)

curses.KEY_DC

文字削除 (Delete char)

curses.KEY_IC

文字挿入、または文字挿入モードへ入る

curses.KEY_EIC

文字挿入モードから抜ける

curses.KEY_CLEAR

画面消去

curses.KEY_EOS

画面の末端まで消去

curses.KEY_EOL

行末端まで消去

curses.KEY_SF

前に 1 行スクロール

curses.KEY_SR

後ろ (逆方向) に 1 行スクロール

curses.KEY_NPAGE

次のページ (Page Next)

curses.KEY_PPAGE

前のページ (Page Prev)

curses.KEY_STAB

タブ設定

curses.KEY_CTAB

タブリセット

curses.KEY_CATAB

すべてのタブをリセット

curses.KEY_ENTER

入力または送信 (信頼できません)

curses.KEY_SRESET

ソフトウェア (部分的) リセット (信頼できません)

curses.KEY_RESET

リセットまたはハードリセット (信頼できません)

curses.KEY_PRINT

印刷 (Print)

curses.KEY_LL

下ホーム (Home down) または最下行 (左下)

curses.KEY_A1

キーパッドの左上キー

curses.KEY_A3

キーパッドの右上キー

curses.KEY_B2

キーパッドの中央キー

curses.KEY_C1

キーパッドの左下キー

curses.KEY_C3

キーパッドの右下キー

curses.KEY_BTAB

Back tab

curses.KEY_BEG

開始 (Beg)

curses.KEY_CANCEL

キャンセル (Cancel)

curses.KEY_CLOSE

Close [閉じる]

curses.KEY_COMMAND

コマンド (Cmd)

curses.KEY_COPY

Copy [コピー]

curses.KEY_CREATE

生成 (Create)

curses.KEY_END

終了 (End)

curses.KEY_EXIT

Exit [終了]

curses.KEY_FIND

検索 (Find)

curses.KEY_HELP

ヘルプ (Help)

curses.KEY_MARK

マーク (Mark)

curses.KEY_MESSAGE

メッセージ (Message)

curses.KEY_MOVE

移動 (Move)

curses.KEY_NEXT

次へ (Next)

curses.KEY_OPEN

開く (Open)

curses.KEY_OPTIONS

オプション

curses.KEY_PREVIOUS

前へ (Prev)

curses.KEY_REDO

Redo [やり直し]

curses.KEY_REFERENCE

参照 (Ref)

curses.KEY_REFRESH

更新 (Refresh)

curses.KEY_REPLACE

置換 (Replace)

curses.KEY_RESTART

再起動 (Restart)

curses.KEY_RESUME

再開 (Resume)

curses.KEY_SAVE

Save [保存]

curses.KEY_SBEG

シフト付き Beg

curses.KEY_SCANCEL

シフト付き Cancel

curses.KEY_SCOMMAND

シフト付き Command

curses.KEY_SCOPY

シフト付き Copy

curses.KEY_SCREATE

シフト付き Create

curses.KEY_SDC

シフト付き Delete char

curses.KEY_SDL

シフト付き Delete line

curses.KEY_SELECT

選択 (Select)

curses.KEY_SEND

シフト付き End

curses.KEY_SEOL

シフト付き Clear line

curses.KEY_SEXIT

シフト付き Exit

curses.KEY_SFIND

シフト付き Find

curses.KEY_SHELP

シフト付き Help

curses.KEY_SHOME

シフト付き Home

curses.KEY_SIC

シフト付き Input

curses.KEY_SLEFT

シフト付き Left arrow

curses.KEY_SMESSAGE

シフト付き Message

curses.KEY_SMOVE

シフト付き Move

curses.KEY_SNEXT

シフト付き Next

curses.KEY_SOPTIONS

シフト付き Options

curses.KEY_SPREVIOUS

シフト付き Prev

curses.KEY_SPRINT

シフト付き Print

curses.KEY_SREDO

シフト付き Redo

curses.KEY_SREPLACE

シフト付き Replace

curses.KEY_SRIGHT

シフト付き Right arrow

curses.KEY_SRSUME

シフト付き Resume

curses.KEY_SSAVE

シフト付き Save

curses.KEY_SSUSPEND

シフト付き Suspend

curses.KEY_SUNDO

シフト付き Undo

curses.KEY_SUSPEND

一時停止 (Suspend)

curses.KEY_UNDO

Undo [元に戻す]

curses.KEY_MOUSE

マウスイベント通知

curses.KEY_RESIZE

端末リサイズイベント

curses.KEY_MAX

最大キー値

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. If 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:

キーキャップ

定数

Insert

KEY_IC

Delete

KEY_DC

Home

KEY_HOME

End

KEY_END

Page Up

KEY_PPAGE

Page Down

KEY_NPAGE

代替文字セットを以下の表に列挙します。これらは VT100 端末から継承したものであり、X 端末のようなソフトウェアエミュレーション上で一般に利用可能なものです。グラフィックが利用できない場合、curses は印字可能 ASCII文字による粗雑な近似出力を行います。

注釈

これらは initscr() が呼び出された後でしか利用できません。

ACS コード

意味

curses.ACS_BBSS

alternate name for upper-right corner

curses.ACS_BLOCK

黒四角ブロック

curses.ACS_BOARD

白四角ブロック

curses.ACS_BSBS

水平線の別名

curses.ACS_BSSB

alternate name for upper-left corner

curses.ACS_BSSS

上向き T 字罫線の別名

curses.ACS_BTEE

下向き T 字罫線

curses.ACS_BULLET

黒丸(bullet)

curses.ACS_CKBOARD

チェッカーボードパタン (点描)

curses.ACS_DARROW

下向き矢印

curses.ACS_DEGREE

度記号

curses.ACS_DIAMOND

ダイアモンド

curses.ACS_GEQUAL

大なりイコール

curses.ACS_HLINE

水平線

curses.ACS_LANTERN

ランタン(lantern) シンボル

curses.ACS_LARROW

左向き矢印

curses.ACS_LEQUAL

小なりイコール

curses.ACS_LLCORNER

lower-left corner

curses.ACS_LRCORNER

lower-right corner

curses.ACS_LTEE

左向き T 字罫線

curses.ACS_NEQUAL

不等号

curses.ACS_PI

パイ記号

curses.ACS_PLMINUS

プラスマイナス記号

curses.ACS_PLUS

大プラス記号

curses.ACS_RARROW

右向き矢印

curses.ACS_RTEE

右向き T 字罫線

curses.ACS_S1

スキャンライン 1

curses.ACS_S3

スキャンライン 3

curses.ACS_S7

スキャンライン 7

curses.ACS_S9

スキャンライン 9

curses.ACS_SBBS

alternate name for lower-right corner

curses.ACS_SBSB

垂直線の別名

curses.ACS_SBSS

右向き T 字罫線の別名

curses.ACS_SSBB

alternate name for lower-left corner

curses.ACS_SSBS

下向き T 字罫線の別名

curses.ACS_SSSB

左向き T 字罫線の別名

curses.ACS_SSSS

交差罫線または大プラス記号の別名

curses.ACS_STERLING

ポンドスターリング記号

curses.ACS_TTEE

上向き T 字罫線

curses.ACS_UARROW

上向き矢印

curses.ACS_ULCORNER

upper-left corner

curses.ACS_URCORNER

upper-right corner

curses.ACS_VLINE

垂直線

The following table lists mouse button constants used by getmouse():

Mouse button constant

意味

curses.BUTTONn_PRESSED

Mouse button n pressed

curses.BUTTONn_RELEASED

Mouse button n released

curses.BUTTONn_CLICKED

Mouse button n clicked

curses.BUTTONn_DOUBLE_CLICKED

Mouse button n double clicked

curses.BUTTONn_TRIPLE_CLICKED

Mouse button n triple clicked

curses.BUTTON_SHIFT

Shift was down during button state change

curses.BUTTON_CTRL

Control was down during button state change

curses.BUTTON_ALT

Alt was down during button state change

バージョン 3.10 で変更: The BUTTON5_* constants are now exposed if they are provided by the underlying curses library.

以下のテーブルは定義済みの色を列挙したものです:

定数

curses.COLOR_BLACK

curses.COLOR_BLUE

curses.COLOR_CYAN

シアン (薄く緑がかった青)

curses.COLOR_GREEN

curses.COLOR_MAGENTA

マゼンタ (紫がかった赤)

curses.COLOR_RED

curses.COLOR_WHITE

curses.COLOR_YELLOW

黄色

curses.textpad --- Text input widget for curses programs

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). 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.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 corner of the rectangle to be drawn; the fourth and fifth arguments are the y and x coordinates of the lower-right corner. 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). Otherwise it will be drawn with ASCII dashes, vertical bars, and plus signs.

Textbox オブジェクト

以下のような Textbox オブジェクトをインスタンス生成することができます:

class curses.textpad.Textbox(win, insert_mode=False)

Return a textbox widget object. The win argument should be a curses window object in which the textbox is to be contained. If insert_mode is true, the textbox inserts typed characters, shifting existing text to the right, rather than overwriting it. The edit cursor of the textbox is initially located at the upper-left corner of the containing window, with coordinates (0, 0). The instance's stripspaces flag is initially on.

バージョン 3.16.0a0 (unreleased) で変更: Entering and reading back the full Unicode range, including combining characters, is now supported when curses is built with wide-character support.

Textbox オブジェクトは以下のメソッドを持ちます:

edit(validate=None)

This is the entry point you will normally use. It accepts editing keystrokes until one of the termination keystrokes is entered. If validate is supplied, it must be a function. It will be called for each keystroke entered with the keystroke as a parameter; command dispatch is done on the result. If it returns a false value, the keystroke is ignored. This method returns the window contents as a string; whether blanks in the window are included is affected by the stripspaces attribute.

バージョン 3.16.0a0 (unreleased) で変更: validate is now called with a non-ASCII character as a string; other keystrokes are still passed as an integer.

do_command(ch)

Process a single command keystroke. Returns 1 to continue editing, or 0 if a termination keystroke was processed. Here are the supported special keystrokes:

キーストローク

動作

Control-A

ウィンドウの左端に移動します。

Control-B

カーソルを左へ移動し、必要なら前の行に折り返します。

Control-D

カーソル下の文字を削除します。

Control-E

右端 (stripspaces がオフのとき) または行末 (stripspaces がオンのとき) に移動します。

Control-F

カーソルを右に移動し、必要なら次の行に折り返します。

Control-G

ウィンドウを終了し、その内容を返します。

Control-H

逆方向に文字を削除します。

Control-J

Terminate if the window is 1 line, otherwise move to the start of the next line.

Control-K

行が空白行ならその行全体を削除し、そうでなければカーソル以降行末までを消去します。

Control-L

スクリーンを更新します。

Control-N

カーソルを下に移動します; 1 行下に移動します。

Control-O

カーソルの場所に空行を 1 行挿入します。

Control-P

カーソルを上に移動します; 1 行上に移動します。

移動操作は、カーソルがウィンドウの縁にあって移動ができない場合には何も行いません。場合によっては、以下のような同義のキーストロークがサポートされています:

定数

キーストローク

KEY_LEFT

Control-B

KEY_RIGHT

Control-F

KEY_UP

Control-P

KEY_DOWN

Control-N

KEY_BACKSPACE

Control-h

他のキーストロークは、与えられた文字を挿入し、(行折り返し付きで) 右に移動するコマンドとして扱われます。

gather()

ウィンドウの内容を文字列として返します; ウィンドウ内の空白が含められるかどうかは stripspaces メンバ変数で決められます。

stripspaces

この属性はウィンドウ内の空白領域の解釈方法を制御するためのフラグです。フラグがオンに設定されている場合、各行の末端にある空白領域は無視されます; すなわち、末端空白領域にカーソルが入ると、その場所の代わりに行の末尾にカーソルが移動します。また、末端の空白領域はウィンドウの内容を取得する際に剥ぎ取られます。