# ESC Sequence

エスケープシーケンスは ESC 文字 '\033' で始まり何文字かで完結する制御コードです。

本ライブラリが動作するプログラム上や、シリアルポートの先にあるマイコンから制御文字をターミナルに投入することで、様々な画面制御（画面のクリア、カーソルの移動、色などの表示属性の変更）を行うことが出来ます。

以下に対応するエスケープシーケンスを記述します。表中の ESC はエスケープ文字 '\033'、イタリックの *n* や *m* は数字の入力です。

| エスケープシーケンス                       | 意味                                                                                                                                         |
| -------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
| ESC \[ *n*  A                    | カーソルを*n*行上に移動する。（*n*省略時は1行）                                                                                                                |
| ESC \[ *n* B                     | カーソルを*n*行下に移動する。（*n*省略時は1行）                                                                                                                |
| ESC \[ *n* C                     | カーソルを*n*列右に移動する。（*n*省略時は1列）                                                                                                                |
| ESC \[ *n* D                     | カーソルを*n*列左に移動する。（*n*省略時は1列）                                                                                                                |
| ESC \[ *n* G                     | カーソルのカラム*n*の位置に移動する (*n*省略時は1カラム目＝行頭)                                                                                                      |
| ESC \[ *n* ; *m* H               | カーソル位置を行*n*列*m*に移動する。先頭位置の場合は1を指定します。*n*;*m*を省略した場合は左上ホームポジションにカーソルを移動します。                                                                 |
| ESC \[ n ; *m* f                 | ESC \[ *n* ; *m* Hに同じ。                                                                                                                     |
| ESC \[ 2 J                       | 画面をクリアしてカーソルをホームポジションに移動する。                                                                                                                |
| ESC \[ *n* K                     | <p><em>n</em>=0 または省略 カーソル行より後ろを削除する</p><p><em>n</em>=1 カーソル行より前を削除する</p><p><em>n</em>=2 行全体を削除する</p>                                      |
| ESC \[ *n1* ; *n2* ; ...; *n4* m | <p>描画属性の設定を行う。<em>n1</em> .. <em>n4</em> は任意数指定できる。</p><p>1 → 太字</p><p>7 → 反転</p><p>30 .. 37 → 文字色</p><p>40 .. 47 → 背景色</p><p>0 → 属性抹消</p> |

{% hint style="warning" %}
`ITerm`で対応するエスケープシーケンスは、ANSIターミナル互換を目的としたものではありません。解釈や仕様には違いがあります。
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mwm5.twelite.info/0.8/references/untitled/tweterm/esc-sequence.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
