[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

9.21 gauche.termios - 端末の制御

Module: gauche.termios

このモジュールは端末の制御のための手続きを提供します。 端末制御APIはPOSIXとWindowsであまりに異なり、 十分に細かい制御ができる統一したインタフェースを作るのは不可能です。 そこで、これら二つのプラットフォームで異なる低レベルAPIを提供し、 その上に若干の共通な高レベルAPIを構築しています。

Unix環境では、低レベルAPIはモジュール名からわかるように POSIX termiosへのインタフェースを提供しています。 さらに、このモジュールでは、システムがサポートしている場合には 擬似 tty のインタフェースも提供しています。

Windowsネイティブ環境では、低レベルはWindowsコンソールAPIに対応します。


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

9.21.1 POSIX termiosインタフェース

ここに挙げる手続きは、機能シンボルgauche.os.windowsが定義されていない 場合にのみ利用可能です。機能シンボルによってコードを切り替える方法は srfi-0 - 機能条件式cond-expandを参照してください。

Builtin Class: <sys-termios>

POSIX termios(7) の構造体です。

Instance Variable of <sys-termios>: iflag
Instance Variable of <sys-termios>: oflag
Instance Variable of <sys-termios>: cflag
Instance Variable of <sys-termios>: lflag
Instance Variable of <sys-termios>: cc

iflagoflagcflaglflagの各スロットは、 対応するビットマスクを非負の整数で表現した値を保持しています。

また、ccスロットはstruct termiosc_cc配列の コピーを返します。 c_cc配列の値を変えたい場合は、変更したu8vectorを明示的に ccスロットにset!して下さい。

このセクションを通じて、引数 port-or-fd はポートオブジェクトか システムのファイルディスクリプタを表現する小さい整数かのどちらかです。 portがシステム端末に結びついていないければ、エラーになります。 (sys-isatty?を使えばportが端末と結びついているか どうかチェックできます。 他のファイル操作参照)

Function: sys-tcgetattr port-or-fd

port-or-fd と結びついている <sys-termios>オブジェクトの 端末パラメータを返します。

Function: sys-tcsetattr port-or-fd when termios

port-or-fdと結びついている端末のパラメータを termios に設定します。 termios<sys-termios> のインスタンスでなければなりません。

整数の引数whenはいつ変更を有効にするかを指定します。 この引数用に3つの変数があらかじめ定義されています。

TCSANOW

変更を直ちに反映します。

TCSADRAIN

変更を、すべてのペンディングになっている出力がフラッシュされた後に反映します。

TCSAFLUSH

変更を、すべてのペンディングになっている出力がフラッシュされ、かつ、 すべてのペンディングになっている入力が破棄されたあとに反映します。

Function: sys-tcsendbreak port-or-fd duration

ゼロストリームを指定した時間、port-or-fdと結びついている端末に 送出します。時間の単位はシステム依存です。詳しくは、お使いの システムのマニュアルページ tcsendbreak(3)を参照してください。

Function: sys-tcdrain port-or-fd

port-or-fdへのすべての出力が送出されるまで待ちます。

Function: sys-tcflush port-or-fd queue

port-or-fdのバッファ内のデータを破棄します。queueには以下の値の どれかを指定します。

TCIFLUSH

受信データしたが読み込んではいないデータを破棄します。

TCOFLUSH

書き出したが送出していないデータを破棄します。

TCIOFLUSH

TCIFLUSHTCOFLUSH の両方の動作をします。

Function: sys-tcflow port-or-fd action

port-or-fdのデータフローをactionで制御します。actionは 以下の値のうちどれかです。

TCOOFF

出力の送出をサスペンドします。

TCOON

出力の送出を再開します。

TCIOFF

端末デバイスがシステムへの送出を止めるよう STOP 文字を送出する。

TCION

端末デバイスがシステムへの送出を再開するよう START 文字を送出する。

Function: sys-tcgetpgrp port-or-fd

port-or-fdの結びついている端末のプロセスのグループIDを返します。

Function: sys-tcsetpgrp port-or-fd pgrp

port-or-fdの結びついている端末のプロセスのグループIDをpgrpに 設定します。

Function: sys-cfgetispeed termios
Function: sys-cfsetispeed termios speed
Function: sys-cfgetospeed termios
Function: sys-cfsetospeed termios speed

termios内の入出力スピード(ボーレート)を取得/設定します。スピードは 以下の定義ずみの数値で表現されてます: B0B50B75B110B134B150B200B300B600B1200B1800B2400B4800B9600B19200B38400

もっと速いボーレート、たとえば、B57600B115200 あるいは B230400 をサポートしている システムもあります。symbol-bound?をつかえば、これらの オプションが定義されているかどうかをチェックできます。B0 はコネクションを終了するのに使われます。

Function: sys-openpty &optional term

擬似 tty のペア、マスターとスレーブをオープンし、2つの ファイルディスクリプタの整数を返します。オプション引数 term が渡される場合は、<sys-termios>オブジェクトでなければなりません。 これは、pty パラメータを設定します。

open-input-fd-portopen-output-fd-portの両方またはどちらか を返されたファイルディスクリプタに対するポートを生成するために使うことが できます(ファイルポート参照)。擬似端末の名前を得るには sys-ttyname を使います(他のファイル操作参照)。

この関数はシステムが openpty(3) をサポートしている場合にのみ利用 可能です。

Function: sys-forkpty &optional term

擬似 ttyのペア、マスターとスレーブをオープンし、スレーブ sty を ログイン端末になるよう設定し、fork(2) します。

二つの整数、最初の値は親プロセスに対しては子の pid の値で、0ならば 子プロセスです。ふたつ目の値はマスター pty のファイルディスクリプタの 値です。

オプション引数 termが渡される場合は、それは<sys-termios>オブジェクト でなければなりません。これはスレーブ pty のパラメータを設定します。

この関数はシステムが forkpty(3) をサポートしている場合にのみ利用 可能です。

注意: sys-forkptyにはsys-forkと同様のマルチスレッドハザー ドの危険性があります。(詳細についてはプロセス管理参照 してください)。マルチスレッドプログラムでは後述の sys-forkpty-and-execを利用してください。

Function: sys-forkpty-and-exec command args &keyword iomap term sigmask

sys-forkptyして、ただちに指定したcommandを引数 argsで子プロセスでexecします。この関数にはマルチスレッド 環境でもハザードを起こしません。

引数commandargsiomapsigmaskの意味は sys-execのものと同じです。(プロセス管理を見て ください)。キーワード引数termが与えられれば、スレーブptyの初期化 に使われます。


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

9.21.2 WindowsコンソールAPI

ここに挙げる手続きは、機能シンボルgauche.os.windowsが定義されている 場合にのみ利用可能です。機能シンボルによってコードを切り替える方法は srfi-0 - 機能条件式cond-expandを参照してください。

Most of the procedures correspond to Windows Console API one-to-one. See the Windows reference for the detail description of what each API does.

Attaching and detaching

Function: sys-alloc-console
Function: sys-free-console

[Windows] Calls AllocConsole and FreeConsole, respectively.

Function: sys-generate-console-ctrl-event event pgid

[Windows]

Constant: CTRL_C_EVENT
Constant: CTRL_BREAK_EVENT

[Windows]

Console codepage

Function: sys-get-console-cp
Function: sys-get-console-output-cp
Function: sys-set-console-cp codepage
Function: sys-set-console-output-cp codepage

[Windows]

Function: sys-get-console-cursor-info handle
Function: sys-set-console-cursor-info handle size visible

[Windows]

Function: sys-set-console-cursor-position handle x y

[Windows]

Console mode

Function: sys-get-console-mode handle
Function: sys-set-console-mode handle mode

[Windows]

Constant: ENABLE_LINE_INPUT
Constant: ENABLE_ECHO_INPUT
Constant: ENABLE_PROCESSED_INPUT
Constant: ENABLE_WINDOW_INPUT
Constant: ENABLE_MOUSE_INPUT
Constant: ENABLE_PROCESSED_OUTPUT
Constant: ENABLE_WRAP_AT_EOL_OUTPUT

[Windows]

Screen buffer

Function: sys-create-console-screen-buffer desired-access share-mode inheritable

[Windows]

Constant: GENERIC_READ
Constant: GENERIC_WRITE

[Windows]

Constant: FILE_SHARE_READ
Constant: FILE_SHARE_WRITE

[Windows]

Function: sys-set-console-active-screen-buffer handle

[Windows]

Function: sys-scroll-console-screen-buffer handle scroll-rectangle clip-rectangle x y fill

[Windows]

Class: <win:console-screen-buffer-info>

[Windows]

Instance Variable of <win:console-screen-buffer-info>: size.x
Instance Variable of <win:console-screen-buffer-info>: size.y
Instance Variable of <win:console-screen-buffer-info>: cursor-position.x
Instance Variable of <win:console-screen-buffer-info>: cursor-position.y
Instance Variable of <win:console-screen-buffer-info>: attributes
Instance Variable of <win:console-screen-buffer-info>: window.left
Instance Variable of <win:console-screen-buffer-info>: window.top
Instance Variable of <win:console-screen-buffer-info>: window.right
Instance Variable of <win:console-screen-buffer-info>: window.bottom
Instance Variable of <win:console-screen-buffer-info>: maximum-window-size.x
Instance Variable of <win:console-screen-buffer-info>: maximum-window-size.y
Constant: FOREGROUND_BLUE
Constant: FOREGROUND_GREEN
Constant: FOREGROUND_RED
Constant: FOREGROUND_INTENSITY
Constant: BACKGROUND_BLUE
Constant: BACKGROUND_GREEN
Constant: BACKGROUND_RED
Constant: BACKGROUND_INTENSITY

[Windows]

Function: sys-get-console-screen-buffer-info handle

[Windows]

Function: sys-get-largest-console-window-size handle

[Windows]

Function: sys-set-screen-buffer-size handle x y

[Windows]

Console input/output

Class: <win:input-record>

[Windows]

Instance Variable of <win:input-record>: event-type
Instance Variable of <win:input-record>: key.down
Instance Variable of <win:input-record>: key.repeat-count
Instance Variable of <win:input-record>: key.virtual-key-code
Instance Variable of <win:input-record>: key.unicode-char
Instance Variable of <win:input-record>: key.ascii-char
Instance Variable of <win:input-record>: key.control-key-state
Instance Variable of <win:input-record>: mouse.x
Instance Variable of <win:input-record>: mouse.y
Instance Variable of <win:input-record>: mouse.button-state
Instance Variable of <win:input-record>: mouse.event-flags
Instance Variable of <win:input-record>: window-buffer-size.x
Instance Variable of <win:input-record>: window-buffer-size.y
Instance Variable of <win:input-record>: menu.command-id
Instance Variable of <win:input-record>: focus.set-focus
Function: sys-get-number-of-console-input-events handle

[Windows]

Function: sys-get-number-of-console-mouse-buttons

[Windows]

Function: sys-peek-console-input handle
Function: sys-read-console-input handle

[Windows]

Function: sys-read-console handle buf

[Windows]

Function: sys-read-console-output handle buf w h x y region

[Windows]

Function: sys-read-console-output-attribute handle buf x y

[Windows]

Function: sys-read-console-output-character handle len x y

[Windows]

Function: sys-set-console-text-attribute handle attr

[Windows]

Function: sys-set-console-window-info handle absolute window

[Windows]

Function: sys-write-console handle string

[Windows]

Function: sys-write-console-output-character handle string x y

[Windows]

Function: sys-get-console-title

[Windows]

Standard handles

Function: sys-get-std-handle which
Function: sys-set-std-handle which handle

[Windows]

Constant: STD_INPUT_HANDLE
Constant: STD_OUTPUT_HANDLE
Constant: STD_ERROR_HANDLE

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

9.21.3 共通の高レベル端末制御

Currently we only have one high-level API. We may add more as needed.

Function: without-echoing iport proc

If iport is an input port connected to a terminal, sets the terminal mode non-echoing and call proc with iport as an argument. Before returning from without-echoing, or throwing an error, the terminal mode is reset to the original state when this procedure is called. The procedure returns whatever value(s) proc returns.

You can also pass #f to iport. In that case, this procedure tries to open a console (/dev/tty on Unix, CON on Windows) and set the console mode, then calls proc with the opened input port. An error is thrown if the procedure can not open a console.

If iport is other than above, this procedure simply calls proc with iport. This allows the caller to read password from redirected input, for example.

Note: Because of an implementation issue, on Windows native platforms this procedure always changes console mode of the standard input handle when iport is either #f or a terminal input port.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]

This document was generated by Shiro Kawai on November, 22 2009 using texi2html 1.78.