curs_initscr(3x) curs_initscr(3x)
initscr, newterm, endwin, isendwin, set_term, delscreen -
curses screen initialization and manipulation routines
- curses 画面の初期化と操作
#include <curses.h>
WINDOW *initscr(void);
int endwin(void);
bool isendwin(void);
SCREEN *newterm(char *type, FILE *outfd, FILE *infd);
SCREEN *set_term(SCREEN *new);
void delscreen(SCREEN* sp);
initscr is normally the first curses routine to call when
initializing a program. A few special routines sometimes
need to be called before it; these are slk_init, filter,
ripoffline, use_env. For multiple-terminal applications,
newterm may be called before initscr.
initscr は通常、プログラムを初期化するとき最初に呼び出す
curses ルーチンです。
時々その前に呼び出す必要のある少数の特別なルーチンには
slk_init, filter, ripoffline, use_env があります。
複数の端末を使うアプリケーションは、 initscr の前に
newterm を呼び出す場合があります。
The initscr code determines the terminal type and initial-
izes all curses data structures. initscr also causes the
first call to refresh to clear the screen. If errors oc-
cur, initscr writes an appropriate error message to stan-
dard error and exits; otherwise, a pointer is returned to
stdscr.
initscr のコードは端末のタイプを決定し、 curses の
データ構造のすべてを初期化します。
initscr はまた、画面をクリアするために最初の
refresh 呼び出しを行います。
エラーが発生した場合、 initscr は適切なエラーメッセージを
標準エラーに書き出して終了します。
そうでない場合は、 stdscr へのポインタを返します。
A program that outputs to more than one terminal should
use the newterm routine for each terminal instead of
initscr. A program that needs to inspect capabilities, so
it can continue to run in a line-oriented mode if the ter-
minal cannot support a screen-oriented program, would also
use newterm. The routine newterm should be called once
for each terminal. It returns a variable of type SCREEN *
which should be saved as a reference to that terminal.
newterm's arguments are
複数の端末へ出力するプログラムは、 initscr の代わりに
端末ごとに newterm ルーチンを呼び出してください。
端末が画面指向プログラムをサポートしない場合に
行指向モードで実行し続けることができるように機能項目を
検査する必要のあるプログラムも newterm を使うでしょう。
newterm は端末ごとに一度ずつ呼び出さなければなりません。
newterm はその端末への参照として保存されるべき
SCREEN * 型の変数を返します。(訳注: 変数でなく値)
newterm の引数は
o the type of the terminal to be used in place of $TERM,
o $TERM (=環境変数 TERM ) の代わりに使われる端末のタイプ type
o a file pointer for output to the terminal, and
o 端末に出力するためのファイルポインタ
o another file pointer for input from the terminal
o 端末から入力するための別のファイルポインタ
If the type parameter is NULL, $TERM will be used.
type 引数が NULL の場合、 $TERM が使われます。
The program must also call endwin for each terminal being
used before exiting from curses. If newterm is called
more than once for the same terminal, the first terminal
referred to must be the last one for which endwin is
called.
プログラムはまた、 curses を終了する前に使った端末
それぞれに対して endwin を呼び出さなければなりません。
もし同じ端末に対して newterm を 2 回以上呼び出した場合、
最初に参照した端末に対して最後の endwin を呼び出さなければ
なりません。
A program should always call endwin before exiting or es-
caping from curses mode temporarily. This routine
プログラムは curses モードを終了するとき、
または一時的に抜ける前にはいつも endwin を呼び出さなければ
なりません。このルーチンは
o restores tty modes,
o tty モードを復元し、
o moves the cursor to the lower left-hand corner of the
screen and
o カーソルを画面の左下隅に移動し、
o resets the terminal into the proper non-visual mode.
o 端末を適切なノンビジュアルモードに戻します。
Calling refresh or doupdate after a temporary escape caus-
es the program to resume visual mode.
一時的に抜けたあとで refresh か doupdate を呼び出すと、
プログラムはビジュアルモードに戻ります。
The isendwin routine returns TRUE if endwin has been
called without any subsequent calls to wrefresh, and FALSE
otherwise.
isendwin ルーチンは endwin が呼び出された後、 wrefresh が
呼び出されていない場合に TRUE を、そうでない場合に FALSE を
返します。
The set_term routine is used to switch between different
terminals. The screen reference new becomes the new cur-
rent terminal. The previous terminal is returned by the
routine. This is the only routine which manipulates
SCREEN pointers; all other routines affect only the cur-
rent terminal.
set_term ルーチンは異なる端末間の切り替えに使います。
端末参照 new が新しい現在端末になります。
このルーチンは直前の端末を返します。
set_term は SCREEN ポインタを操作する唯一のルーチンです。
他のすべてのルーチンは、現在端末にしか作用しません。
The delscreen routine frees storage associated with the
SCREEN data structure. The endwin routine does not do
this, so delscreen should be called after endwin if a par-
ticular SCREEN is no longer needed.
delscreen ルーチンは SCREEN データ構造に関連する記憶領域を
開放します。
endwin ルーチンはこれをしないので、特定の SCREEN が必要なく
なったなら endwin の後で delscreen を呼び出してください。
endwin returns the integer ERR upon failure and OK upon
successful completion.
endwin は失敗の場合に整数 ERR を、正常終了の場合に OK を
返します。
Routines that return pointers always return NULL on error.
ポインタを返すルーチンは、エラーの場合つねに NULL を
返します。
X/Open defines no error conditions. In this implementa-
tion
X/Open はエラーの条件を何も定義していません。この実装では
o endwin returns an error if the terminal was not ini-
tialized.
o endwin は端末が初期化されていない場合にエラーを返します。
o newterm returns an error if it cannot allocate the da-
ta structures for the screen, or for the top-level
windows within the screen, i.e., curscr, newscr, or
stdscr.
o newterm は画面、または画面内のトップレベル・ウインドウ
curscr, newscr, stdscr に対するデータ構造の領域を
確保できなかった場合にエラーを返します。
o set_term returns no error.
o set_term はエラーを返すことはありません。
Note that initscr and newterm may be macros.
initscr と newterm はマクロであるかもしれないことに
注意してください。
These functions were described in the XSI Curses standard,
Issue 4. As of 2015, the current document is X/Open Curs-
es, Issue 7.
これらの関数は XSI Curses standard, Issue 4 に記載されて
います。
2015 年現在の文書は X/Open Curses, Issue 7 です。
X/Open specifies that portable applications must not call
initscr more than once:
X/Open はポータブル・アプリケーションは initscr を
2 回以上呼び出してはならないと指定しています。
o The portable way to use initscr is once only, using
refresh (see curs_refresh(3x)) to restore the screen
after endwin.
o endwin の後で画面を復元するには refresh を使うので、
ポータブルな initscr の使い方は 1 回のみです。
( curs_refresh(3x) 参照)
o This implementation allows using initscr after endwin.
o この実装では endwin の後で initscr を使うことを
許しています。
Old versions of curses, e.g., BSD 4.4, may have returned a
null pointer from initscr when an error is detected,
rather than exiting. It is safe but redundant to check
the return value of initscr in XSI Curses.
curses の古いバージョン、例えば BSD 4.4 では、エラーが
検出されたとき、 initscr は終了せずにヌルポインタを返します。
XSI Curses で initscr の戻り値を検査するのは安全ですが
冗長です。
If the TERM variable is missing or empty, initscr uses the
value "unknown", which normally corresponds to a terminal
entry with the generic (gn) capability. Generic entries
are detected by setupterm (see curs_terminfo(3x)) and can-
not be used for full-screen operation. Other implementa-
tions may handle a missing/empty TERM variable different-
ly.
変数 TERM が見つからないか空の場合、 initscr は、通常
generic (gn) 機能項目を持つ端末項目に対応する "unknown" 値を
使います。
収録項目 generic は setupterm で検出され
( curs_terminfo(3x) 参照) 、全画面動作では使われません。
他の実装では変数 TERM が見つからないか空の場合の扱いが
異なることがあります。
Quoting from X/Open Curses, section 3.1.1:
以下は X/Open Curses, section 3.1.1 から引用。
Curses implementations may provide for special han-
dling of the SIGINT, SIGQUIT and SIGTSTP signals if
their disposition is SIG_DFL at the time initscr() is
called ...
initscr() が呼び出されたときに SIGINT, SIGQUIT,
SIGTSTP シグナルの処理方法 (disposition) が
SIG_DFL の場合、 Curses の実装によってはこれらシグナルの
特別な取り扱いを与えることがある。…
Any special handling for these signals may remain in
effect for the life of the process or until the
process changes the disposition of the signal.
これらシグナルの特別な取り扱いは、実際上
プロセスの寿命まで、またはプロセスがシグナルの処理方法を
変更するまで続くことがある。
None of the Curses functions are required to be safe
with respect to signals ...
どの Curses 関数もシグナルに関して安全であることを
求められない…
This implementation establishes signal handlers during
initialization, e.g., initscr or newterm. Applications
which must handle these signals should set up the corre-
sponding handlers after initializing the library:
この実装は、例えば initscr または newterm による初期化の
間にシグナルハンドラを設定します。
これらのシグナルを扱わなければならないアプリケーションは
ライブラリの初期化後に対応するハンドラを準備してください。
SIGINT
The handler attempts to cleanup the screen on exit.
Although it usually works as expected, there are lim-
itations:
ハンドラは終了時に画面を一掃しようとします。
通常は期待通りに動作しますが、いくつかの制限があります。
o Walking the SCREEN list is unsafe, since all list
management is done without any signal blocking.
o SCREEN リストをたどることは安全ではありません。
すべてのリスト処理はどのシグナルもブロックせずに
行われるからです。
o On systems which have REENTRANT turned on,
set_term uses functions which could deadlock or
misbehave in other ways.
o REENTRANT を持つシステムを起動する際、 set_term は
デッドロックその他の不都合を引き起こすかもしれない
関数を使います。
o endwin calls other functions, many of which use
stdio or other library functions which are clear-
ly unsafe.
o endwin は他の関数を呼び出し、その多くは
stdio その他の明らかに安全でないライブラリ関数を
使います。
SIGTERM
This uses the same handler as SIGINT, with the same
limitations. It is not mentioned in X/Open Curses,
but is more suitable for this purpose than SIGQUIT
(which is used in debugging).
SIGINT と同じハンドラを使い、同じ制限があります。
X/Open Curses では考慮されていませんが、 (デバッグに
使われる) SIGQUIT よりもこの用途により向いています。
SIGTSTP
This handles the stop signal, used in job control.
When resuming the process, this implementation dis-
cards pending input with flushinput (see
curs_util(3x)), and repaints the screen assuming that
it has been completely altered. It also updates the
saved terminal modes with def_shell_mode (see
curs_kernel(3x)).
ジョブ制御で使われる stop シグナルを扱います。
プロセスを再開するとき、この実装は待機中の入力を
flushinput で捨て ( curs_util(3x) 参照) 、
画面が完全に変更されたものとして再描画します。
(訳注: flushinput ではなく flushinp )
また、 def_shell_mode でセーブした端末モードを
更新します。 ( curs_kernel(3x) 参照)
SIGWINCH
This handles the window-size changes which were ini-
tially ignored in the standardization efforts. The
handler sets a (signal-safe) variable which is later
tested in wgetch (see curs_getch(3x)). If keypad has
been enabled for the corresponding window, wgetch re-
turns the key symbol KEY_RESIZE. At the same time,
wgetch calls resizeterm to adjust the standard screen
stdscr, and update other data such as LINES and COLS.
標準化の努力の中で当初は無視されていた、ウインドウの
サイズ変更を扱います。
このハンドラは、後に wgetch でテストされる
(シグナル安全な) 変数をセットします。
( curs_getch(3x) 参照)
対応するウインドウで keypad が有効になっていれば、
wgetch はキー識別子 KEY_RESIZE を返します。
同時に wgetch は resizeterm を呼び出して
標準画面 stdscr を調整し、 LINES と COLS のような
他のデータを更新します。
(訳注: resizeterm(3x) 参照)
curses(3x), curs_kernel(3x), curs_refresh(3x),
curs_slk(3x), curs_terminfo(3x), curs_util(3x),
curs_variables(3x).
curs_initscr(3x)