ANSI escape code

本文详细介绍了ANSI转义码的各种序列及其效果,包括光标移动、屏幕清除、滚动等操作,同时还深入探讨了SGR参数如何设置文本颜色及样式。

前一段时间在处理telnet的一些控制字符,遇到了比较纠结的事情。

自己通过socket发送命令到交换机上,获取相关字符,瞎猜,还是宣告失败,后面维基百科了一下。果然全部搞定。。。

现,献上ANSI escape code的相关解码。

 

Some ANSI escape sequences (not a complete list)
CodeNameEffect
CSI n ACUU – Cursor UpMoves the cursor n (default 1) cells in the given direction. If the cursor is already at the edge of the screen, this has no effect.
CSI n BCUD – Cursor Down
CSI n CCUF – Cursor Forward
CSI n DCUB – Cursor Back
CSI n ECNL – Cursor Next LineMoves cursor to beginning of the line n (default 1) lines down.
CSI n FCPL – Cursor Previous LineMoves cursor to beginning of the line n (default 1) lines up.
CSI n GCHA – Cursor Horizontal AbsoluteMoves the cursor to column n.
CSI n ; m HCUP – Cursor PositionMoves the cursor to row n, column m. The values are 1-based, and default to 1 (top left corner) if omitted. A sequence such as CSI ;5H is a synonym for CSI 1;5H as well as CSI 17;H is the same as CSI 17H and CSI 17;1H
CSI n JED – Erase DataClears part of the screen. If n is zero (or missing), clear from cursor to end of screen. If n is one, clear from cursor to beginning of the screen. If n is two, clear entire screen (and moves cursor to upper left on MS-DOS ANSI.SYS).
CSI n KEL – Erase in LineErases part of the line. If n is zero (or missing), clear from cursor to the end of the line. If n is one, clear from cursor to beginning of the line. If n is two, clear entire line. Cursor position does not change.
CSI n SSU – Scroll UpScroll whole page up by n (default 1) lines. New lines are added at the bottom. (not ANSI.SYS)
CSI n TSD – Scroll DownScroll whole page down by n (default 1) lines. New lines are added at the top. (not ANSI.SYS)
CSI n ; m fHVP – Horizontal and Vertical PositionMoves the cursor to row n, column m. Both default to 1 if omitted. Same as CUP
CSI n [;k] mSGR – Select Graphic RenditionSets SGR parameters, including text color. After CSI can be zero or more parameters separated with ;. With no parameters, CSI m is treated as CSI 0 m (reset / normal), which is typical of most of the ANSI escape sequences.
CSI 6 nDSR – Device Status ReportReports the cursor position to the application as (as though typed at the keyboard) ESC[n;mR, where n is the row and m is the column. (May not work on MS-DOS.)
CSI sSCP – Save Cursor PositionSaves the cursor position.
CSI uRCP – Restore Cursor PositionRestores the cursor position.
CSI ?25lDECTCEMHides the cursor. (Note: the trailing character is lowercase L.)
CSI ?25hDECTCEMShows the cursor.
SGR (Select Graphic Rendition) parameters
CodeEffectNote
0Reset / Normalall attributes off
1Bright (increased intensity) or Bold 
2Faint (decreased intensity)not widely supported
3Italic: onnot widely supported. Sometimes treated as inverse.
4Underline: Single 
5Blink: Slowless than 150 per minute
6Blink: RapidMS-DOS ANSI.SYS; 150 per minute or more; not widely supported
7Image: Negativeinverse or reverse; swap foreground and background
8Concealnot widely supported
9Crossed-outCharacters legible, but marked for deletion. Not widely supported.
10Primary(default) font 
11–19n-th alternate fontSelect the n-th alternate font. 14 being the fourth alternate font, up to 19 being the 9th alternate font.
20Frakturhardly ever supported
21Bright/Bold: off or Underline: Doublebold off not widely supported, double underline hardly ever
22Normal color or intensityneither bright, bold nor faint
23Not italic, not Fraktur 
24Underline: Nonenot singly or doubly underlined
25Blink: off 
26Reserved 
27Image: Positive 
28Revealconceal off
29Not crossed out 
30–37Set text color30 + x, where x is from the color table below
38Set xterm-256 text color[dubious ]next arguments are 5;x where x is color index (0..255)
39Default text colorimplementation defined (according to standard)
40–47Set background color40 + x, where x is from the color table below
48Set xterm-256 background colornext arguments are 5;x where x is color index (0..255)
49Default background colorimplementation defined (according to standard)
50Reserved 
51Framed 
52Encircled 
53Overlined 
54Not framed or encircled 
55Not overlined 
56–59Reserved 
60ideogram underline or right side linehardly ever supported
61ideogram double underline or double line on the right sidehardly ever supported
62ideogram overline or left side linehardly ever supported
63ideogram double overline or double line on the left sidehardly ever supported
64ideogram stress markinghardly ever supported
90–99Set foreground color, high intensityaixterm (not in standard)
100–109Set background color, high intensityaixterm (not in standard)

 http://en.wikipedia.org/wiki/ANSI_escape_code

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值