Next: CSVテーブル, Previous: SXMLからXMLとXHTMLのシリアライゼーション, Up: ライブラリモジュール - ユーティリティ [Contents][Index]
text.console
- テキスト端末制御このモジュールは文字端末を制御する簡単なインタフェースを提供します。 今のところ、vt100互換端末とWindowsコンソールがサポートされています。
curses
等の外部ライブラリには依存しておらず、Gaucheだけで使うことができますが、
出来ることは限られています。
例えばシフトキーだけが押されたタイミングでイベントを受け取ることはできません。
より細かい制御には、何らかの外部拡張ライブラリが必要になるでしょう。
このモジュールの機能の例としては、 Gaucheソースのexamplesディレクトリにあるsnake.scmを見てください。
{text.console} vt100互換端末を表します。このクラスのインスタンスは 以降のジェネリックファンクションの “console” 引数に渡せます。
端末に接続されている入力ポートです。デフォルトは標準入力です。
端末に接続されている出力ポートです。デフォルトは標準出力です。
端末は、特殊キーが押された場合、ESCから始まるエスケープシーケンスを送って来ます。
実際にESCキーが押された場合と区別するために、入力の間隔を測っています。
後続の入力がinput-delay
μs以内に来なかった場合はそこでシーケンスが終了したと
みなし、受け取っているシーケンスが有効なエスケープシーケンスを構成しなければ
個別にキー入力されたとみなします。デフォルトは1000
、すなわち1msです。
Windowsコンソールを表します。このクラス自体は全てのプラットフォームで 定義されていますが、有用なメソッドはWindowsネイティブのランタイムでしか提供されません。
パブリックなスロットはありません。
アプリケーションは実行時にどの種類のコンソールが利用可能かを見極めなければなりません。 推奨される手順は次のとおりです。
has-windows-console?
が真の値を返したなら、<windows-console>
の
インスタンスを作ります。
has-windows-console?
はWindowsプラットフォーム以外では常に#f
を
返すので、cond-expand
は不要です。
TERM
を調べます。それが定義されていて、vt100-compatible?
を
満たすなら、<vt100>
のインスタンスを作ります。
(Windows上でも<vt100>
端末を使うことになる可能性もあります。
例えばgosh
がMSYSシェルから使われている場合です。)
次の手続きは上の手順を実装しています。
{text.console} 実行中のプロセスで使える端末のインスタンスを作成して返します。
適切な端末クラスが無い場合、振る舞いはif-not-availableキーワード引数に
依存します。デフォルトである:error
の場合はエラーが報告されます。
#f
の場合はこの手続きが#f
を返します。
{text.console}
環境変数TERM
の値を文字列で受け取り、それが<vt100>
端末として
扱えるなら#t
を、そうでなければ#f
を返します。
{text.console}
Takes over the control of the console, and calls proc with
console as the only argument. The console is set to
the mode, which must be a symbol with-terminal-mode
accepts: raw
, rare
or cooked
. By default
the console is set to rare
mode, which turn off the echoing
and passes most of keystrokes to the program, but it intercepts
terminal controls (like Ctrl-C
for interrupt and
Ctrl-Z
for suspend; the actual key depends on terminal
settings, though.)
If proc raises an unhandled error, this generic function resets the terminal mode before returning. It does not clear the screen.
{text.console} Display a character at the current cursor position, and move the current cursor position.
{text.console} Display a string from the current cursor position, and move the current cursor position.
{text.console} Ring the beep, or flash the screen (visible bell) if possible.
{text.console} Fetch a keypress from the console. This blocks until any key is pressed.
The return value may be one of the following values:
A key for the character is pressed. It may be a control code
if the control key is pressed with the key; that is, if the user
presses Ctrl-A, #\x01
will be returned.
Indicates a special key; the following keys are supported:
KEY_UP
, KEY_DOWN
, KEY_LEFT
, KEY_RIGHT
,
KEY_HOME
, KEY_END
, KEY_INS
, KEY_DEL
,
KEY_PGDN
, KEY_PGUP
, KEY_F1
, KEY_F2
,
KEY_F3
, KEY_F4
, KEY_F5
, KEY_F6
,
KEY_F7
, KEY_F8
, KEY_F9
, KEY_F10
,
KEY_F11
, KEY_F12
.
(Note: DELETE key is usually mapped to #\x7f
, but it depends on
the terminal).
ALT
and a character.Indicates the character key is pressed with Alt key. For example,
if the user presses Alt-a, (ALT #\a)
is returned (assuming
CAPSLOCK is off).
Indicates the input is closed somehow.
Modifier keys except ALT
are not treated separately but
included in the returned keycode. Assuming CAPSLOCK is off,
if the user press a
, Shift
+a
, and Ctrl
+a
,
the returned value is #\a
, #\A
and #\x01
, respectively.
Ctrl
+Shift
+a
can’t be distinguished from
Ctrl
+a
. ALT
+a
, ALT
+Shift
+a
,
and ALT
+Ctrl
+a
will be (ALT #\a)
,
(ALT #\A)
and (ALT #\x01)
, respectively.
{text.console} Returns true if there’s a key sequence to be read in the console’s input.
{text.console} Returns two values, the current cursor’s x and y position. The top-left corner is (0,0).
{text.console} Move cursor to the specified position. The top-left corner is (0,0).
{text.console} Reset terminal. Usually this sets the character attributes to the default, clears the screen, and moves the cursor to (0, 0).
{text.console} Clear entire screen.
{text.console} Clear characters from the current cursor position to the end of the line.
{text.console} Clear characters from the current cursor position to the end of the screen.
{text.console} Hide/show the cursor.
{text.console} If the cursor is at the bottom line of the screen, scroll up the contents and clear the bottom line; the cursor stays the same position. If the cursor is not at the bottom line of the screen, move the cursor down.
{text.console} If the cursor is at the top line of the screen, scroll down the contents and clear the top line; the cursor stays the same position. If the cursor is not at the top line of the screen, move the cursor up.
{text.console} Returns two values, the width and height of the screen.
Note: This may affect what’s shown in the console. It is recommended that you only call this before redrawing the entire screen and save the result.
{text.console} Set the console so that the subsequent characters will be written with attributes specified by spec.
The character attributes spec is a list in the following format:
(<fgcolor> [<bgcolor> . <option> ...])
where:
<fgcolor> : <color> | #f ; #f means default <bgcolor> : <color> | #f <color> : black | red | green | yellow | blue | magenta | cyan | white <option> : bright | reverse | underscore
For example, you can set characters to be written in red with black background and underscore, you can call:
(set-character-attribute con '(red black underscore))
That the options may seem rather limited in the age of full-color bitmap displays. That’s what it used to be, young lads.
{text.console} Reset character attributes to the default.
{text.console} Sets the console’s attributes to attrs and calls thunk, then restores the attributes. Even if thunk throws an error, attributes are restored.
Note: You should be able to nest this, but currently nesting isn’t working.
Next: CSVテーブル, Previous: SXMLからXMLとXHTMLのシリアライゼーション, Up: ライブラリモジュール - ユーティリティ [Contents][Index]