ANSI/VT100 Terminal Control Escape Sequences
2016-03-10 19:33
609 查看
I got a question while output something int stdout with Golang, so I copied what I found. It`s very useful!
package main import ( "fmt" "os" "strings" "time" ) func main() { for i := 0; i < 50; i++ { time.Sleep(100 * time.Millisecond) h := strings.Repeat("=", i) + strings.Repeat(" ", 49-i) fmt.Printf("\r%.0f%%[%s]", float64(i)/49*100, h) os.Stdout.Sync() } fmt.Println("\nAll System Go!") }
输出:
100%[=================================================] All System Go!
ANSI/VT100 Terminal Control Escape Sequences[ Status | Setup | Fonts | Cursor | Scrolling | Tabs | Erasing | Printing | Keyboard | Colours ]Many computer terminals and terminal emulators support colour and cursor control through a system of escape sequences. One such standard is commonly referred to as ANSI Colour. Several terminal specifications are based on the ANSI colour standard, including VT100. The following is a partial listing of the VT100 control set. <ESC>represents the ASCII "escape" character, 0x1B. Bracketed tags represent modifiable decimal parameters; eg. {ROW}would be replaced by a row number. Device StatusThe following codes are used for reporting terminal/display settings, and vary depending on the implementation:Query Device Code <ESC>[c Requests a Report Device Coderesponse from the device. Report Device Code <ESC>[{code}0c Generated by the device in response to Query Device Coderequest. Query Device Status <ESC>[5n Requests a Report Device Statusresponse from the device. Report Device OK <ESC>[0n Generated by the device in response to a Query Device Statusrequest; indicates that device is functioning correctly. Report Device Failure <ESC>[3n Generated by the device in response to a Query Device Statusrequest; indicates that device is functioning improperly. Query Cursor Position <ESC>[6n Requests a Report Cursor Positionresponse from the device. Report Cursor Position <ESC>[{ROW};{COLUMN}R Generated by the device in response to a Query Cursor Positionrequest; reports current cursor position. Terminal SetupThehand lcodes are used for setting terminal/display mode, and vary depending on the implementation. Line Wrap is one of the few setup codes that tend to be used consistently: Reset Device <ESC>c Reset all terminal settings to default. Enable Line Wrap <ESC>[7h Text wraps to next line if longer than the length of the display area. Disable Line Wrap <ESC>[7l Disables line wrapping. FontsSome terminals support multiple fonts: normal/bold, swiss/italic, etc. There are a variety of special codes for certain terminals; the following are fairly standard:Font Set G0 <ESC>( Set default font. Font Set G1 <ESC>) Set alternate font. Cursor ControlCursor Home <ESC>[{ROW};{COLUMN}H Sets the cursor position where subsequent text will begin. If no row/column parameters are provided (ie. <ESC>[H), the cursor will move to the home position, at the upper left of the screen. Cursor Up <ESC>[{COUNT}A Moves the cursor up by COUNT rows; the default count is 1. Cursor Down <ESC>[{COUNT}B Moves the cursor down by COUNT rows; the default count is 1. Cursor Forward <ESC>[{COUNT}C Moves the cursor forward by COUNT columns; the default count is 1. Cursor Backward <ESC>[{COUNT}D Moves the cursor backward by COUNT columns; the default count is 1. Force Cursor Position <ESC>[{ROW};{COLUMN}f Identical to Cursor Home. Save Cursor <ESC>[s Save current cursor position. Unsave Cursor <ESC>[u Restores cursor position after a Save Cursor. Save Cursor & Attrs <ESC>7 Save current cursor position. Restore Cursor & Attrs <ESC>8 Restores cursor position after a Save Cursor. ScrollingScroll Screen <ESC>[r Enable scrolling for entire display. Scroll Screen <ESC>[{start};{end}r Enable scrolling from row {start}to row {end}. Scroll Down <ESC>D Scroll display down one line. Scroll Up <ESC>M Scroll display up one line. Tab ControlSet Tab <ESC>H Sets a tab at the current position. Clear Tab <ESC>[g Clears tab at the current position. Clear All Tabs <ESC>[3g Clears all tabs. Erasing TextErase End of Line <ESC>[K Erases from the current cursor position to the end of the current line. Erase Start of Line <ESC>[1K Erases from the current cursor position to the start of the current line. Erase Line <ESC>[2K Erases the entire current line. Erase Down <ESC>[J Erases the screen from the current line down to the bottom of the screen. Erase Up <ESC>[1J Erases the screen from the current line up to the top of the screen. Erase Screen <ESC>[2J Erases the screen with the background colour and moves the cursor to home. PrintingSome terminals support local printing:Print Screen <ESC>[i Print the current screen. Print Line <ESC>[1i Print the current line. Stop Print Log <ESC>[4i Disable log. Start Print Log <ESC>[5i Start log; all received text is echoed to a printer. Define KeySet Key Definition <ESC>[{key};"{string}"p Associates a string of text to a keyboard key. {key}indicates the key by its ASCII value in decimal. Set Display AttributesSet Attribute Mode <ESC>[{attr1};...;{attrn}m Sets multiple display attribute settings. The following lists standard attributes: 0 Reset all attributes 1 Bright 2 Dim 4 Underscore 5 Blink 7 Reverse 8 Hidden Foreground Colours 30 Black 31 Red 32 Green 33 Yellow 34 Blue 35 Magenta 36 Cyan 37 White Background Colours 40 Black 41 Red 42 Green 43 Yellow 44 Blue 45 Magenta 46 Cyan 47 White |
ANSI/VT100 Terminal Control Escape Sequences[ Status | Setup | Fonts | Cursor | Scrolling | Tabs | Erasing | Printing | Keyboard | Colours ]Many computer terminals and terminal emulators support colour and cursor control through a system of escape sequences. One such standard is commonly referred to as ANSI Colour. Several terminal specifications are based on the ANSI colour standard, including VT100. The following is a partial listing of the VT100 control set. <ESC>represents the ASCII "escape" character, 0x1B. Bracketed tags represent modifiable decimal parameters; eg. {ROW}would be replaced by a row number. Device StatusThe following codes are used for reporting terminal/display settings, and vary depending on the implementation:Query Device Code <ESC>[c Requests a Report Device Coderesponse from the device. Report Device Code <ESC>[{code}0c Generated by the device in response to Query Device Coderequest. Query Device Status <ESC>[5n Requests a Report Device Statusresponse from the device. Report Device OK <ESC>[0n Generated by the device in response to a Query Device Statusrequest; indicates that device is functioning correctly. Report Device Failure <ESC>[3n Generated by the device in response to a Query Device Statusrequest; indicates that device is functioning improperly. Query Cursor Position <ESC>[6n Requests a Report Cursor Positionresponse from the device. Report Cursor Position <ESC>[{ROW};{COLUMN}R Generated by the device in response to a Query Cursor Positionrequest; reports current cursor position. Terminal SetupThehand lcodes are used for setting terminal/display mode, and vary depending on the implementation. Line Wrap is one of the few setup codes that tend to be used consistently: Reset Device <ESC>c Reset all terminal settings to default. Enable Line Wrap <ESC>[7h Text wraps to next line if longer than the length of the display area. Disable Line Wrap <ESC>[7l Disables line wrapping. FontsSome terminals support multiple fonts: normal/bold, swiss/italic, etc. There are a variety of special codes for certain terminals; the following are fairly standard:Font Set G0 <ESC>( Set default font. Font Set G1 <ESC>) Set alternate font. Cursor ControlCursor Home <ESC>[{ROW};{COLUMN}H Sets the cursor position where subsequent text will begin. If no row/column parameters are provided (ie. <ESC>[H), the cursor will move to the home position, at the upper left of the screen. Cursor Up <ESC>[{COUNT}A Moves the cursor up by COUNT rows; the default count is 1. Cursor Down <ESC>[{COUNT}B Moves the cursor down by COUNT rows; the default count is 1. Cursor Forward <ESC>[{COUNT}C Moves the cursor forward by COUNT columns; the default count is 1. Cursor Backward <ESC>[{COUNT}D Moves the cursor backward by COUNT columns; the default count is 1. Force Cursor Position <ESC>[{ROW};{COLUMN}f Identical to Cursor Home. Save Cursor <ESC>[s Save current cursor position. Unsave Cursor <ESC>[u Restores cursor position after a Save Cursor. Save Cursor & Attrs <ESC>7 Save current cursor position. Restore Cursor & Attrs <ESC>8 Restores cursor position after a Save Cursor. ScrollingScroll Screen <ESC>[r Enable scrolling for entire display. Scroll Screen <ESC>[{start};{end}r Enable scrolling from row {start}to row {end}. Scroll Down <ESC>D Scroll display down one line. Scroll Up <ESC>M Scroll display up one line. Tab ControlSet Tab <ESC>H Sets a tab at the current position. Clear Tab <ESC>[g Clears tab at the current position. Clear All Tabs <ESC>[3g Clears all tabs. Erasing TextErase End of Line <ESC>[K Erases from the current cursor position to the end of the current line. Erase Start of Line <ESC>[1K Erases from the current cursor position to the start of the current line. Erase Line <ESC>[2K Erases the entire current line. Erase Down <ESC>[J Erases the screen from the current line down to the bottom of the screen. Erase Up <ESC>[1J Erases the screen from the current line up to the top of the screen. Erase Screen <ESC>[2J Erases the screen with the background colour and moves the cursor to home. PrintingSome terminals support local printing:Print Screen <ESC>[i Print the current screen. Print Line <ESC>[1i Print the current line. Stop Print Log <ESC>[4i Disable log. Start Print Log <ESC>[5i Start log; all received text is echoed to a printer. Define KeySet Key Definition <ESC>[{key};"{string}"p Associates a string of text to a keyboard key. {key}indicates the key by its ASCII value in decimal. Set Display AttributesSet Attribute Mode <ESC>[{attr1};...;{attrn}m Sets multiple display attribute settings. The following lists standard attributes: 0 Reset all attributes 1 Bright 2 Dim 4 Underscore 5 Blink 7 Reverse 8 Hidden Foreground Colours 30 Black 31 Red 32 Green 33 Yellow 34 Blue 35 Magenta 36 Cyan 37 White Background Colours 40 Black 41 Red 42 Green 43 Yellow 44 Blue 45 Magenta 46 Cyan 47 White |
相关文章推荐
- uiautomator日志文件转换为xml格式文件
- uiautomator做自动化的过程
- 解决init: sys_prop: permission denied uid:1003 name:service.bootanim.exit问题
- iOS开发 提示框- UIAlertController(是UIAlertView和UIActionSheet的合二为一)
- Android通信:Handler和runOnUiThread()
- UITableViewCell 自动计算高度遇到的一些诡异问题
- EXXXUI1.6
- 实现UniqueAttribute唯一性约束,sqlunique约束[转]
- UISwitch 的具体使用方式
- stack与queue
- fatal error C1189: #error : This file requires _WIN32_WINNT to be #defined a
- [LeetCode62]Unique Paths
- 解决UITableView中Cell重用机制导致内容出错的方法总结
- 根据年月日时间换算到精确时分秒和周几
- UICC、SIM、USIM、UIM基础
- CodeForces 392C Yet Another Number Sequence 矩阵快速幂
- sizeThatFits and sizeToFit是UIView的两个方法
- 设计模式_Builder模式
- easyui treegrid 封装(不用分页,用加载更多按钮)延迟加载加加载更多
- iOS 程序在UITextView中显示NSLog日志的方法,