Files
nexus/wiki/concepts/ANSI-Escape-Sequence.md
2026-04-20 09:58:08 +08:00

41 lines
1.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: "ANSI Escape Sequence"
type: concept
tags: [ansi, terminal, escape, control]
---
## 定义
ANSI 转义序列ANSI Escape Sequence是一种用于控制终端显示的标准化指令通过转义字符ESC开头后跟参数和控制码。
## 序列结构
- 开头ESC\x1b或 CSI\x9b
- 参数:数字序列,用分号分隔
- 结束:控制码字母
## 常用序列类别
### SGRSelect Graphic Rendition
- `\x1b[0m` — 重置所有属性
- `\x1b[1m` — 加粗
- `\x1b[4m` — 下划线
- `\x1b[30m`-`\x1b[37m` — 前景色(黑-白)
- `\x1b[40m`-`\x1b[47m` — 背景色(黑-白)
### 光标控制
- `\x1b[H``\x1b[;H` — 光标归位
- `\x1b[nA`/`\x1b[nB` — 上/下移动
- `\x1b[nC`/`\x1b[nD` — 右/左移动
### 屏幕操作
- `\x1b[2J` — 清除屏幕
- `\x1b[K` — 清除行
## 应用场景
- 终端输出着色
- 进度条渲染
- 表格边框绘制
- 交互式 UITUI
## 相关技术
- [[VT100]]:终端标准规范
- [[Terminal Emulation]]:终端仿真