Chinaunix首页 | 论坛 | 博客
  • 博客访问: 226355
  • 博文数量: 65
  • 博客积分: 1410
  • 博客等级: 上尉
  • 技术积分: 655
  • 用 户 组: 普通用户
  • 注册时间: 2006-03-31 13:33
文章分类

全部博文(65)

文章存档

2016年(1)

2010年(4)

2009年(4)

2008年(4)

2007年(40)

2006年(12)

我的朋友

分类: C/C++

2006-10-01 18:01:03

#include
#include
#include
int main ()
{
        while (1) {
                time_t sec  = time(NULL);
                struct tm t = *localtime(&sec);
                printf("\x1b[2J");      /* clear screen and home cursor */
                printf("\x1b[31;40m");  /* red foreground, black background */
                printf("\x1b[11;29H");  /* moves cursor to line 11, column 29 */
                printf("+-----^--^-----+\n");
                printf("\x1b[12;29H");
                printf("|\t%02d:%02d:%02d:  |\n", t.tm_hour, t.tm_min, t.tm_sec);
                printf("\x1b[13;29H");
                printf("+-------V------+\n");
                sleep(1);
        }
        return 0;
}
/* reference: ANSI Escape Sequences
* compile:   gcc mytime.c -o mytime
* usage:     ./mytime
*/
 
 
 
ANSI Escape Sequences
What ANSI escape sequences can be used?
ANSI escape sequences provide cursor and screen control in OS/2 character
mode sessions.  By default ANSI support is turned ON (although it may be
turned off with the command ANSI OFF).  ANSI support is also available in
DOS sessions if the device driver ANSI.SYS is loaded.  See the online
Command Reference for details.
The following ANSI escape sequences are available:
Key      
ESC       Refers to ASCII code 27 (i.e. the Escape key)
#         Replace with the appropriate number
....      Replace with additional attributes, if desired

Escape Code Sequence          Function
Cursor Controls              
ESC[#;#H or ESC[#;#f          Moves cursor to line #, column #
ESC[#A                        Moves cursor up # lines
ESC[#B                        Moves cursor down # lines
ESC[#C                        Moves cursor forward # spaces
ESC[#D                        Moves cursor back # spaces
ESC[#;#R                      Reports current cursor line and column
ESC[s                         Saves cursor position for recall later
ESC[u                         Return to saved cursor position
Erase Functions              
ESC[2J                        Clear screen and home cursor
ESC[K                         Clear to end of line
Set Graphics Rendition       
ESC[#;#;....;#m               Set display attributes where # is
                               0 for normal display
                               1 bold on
                               4 underline (mono only)
                               5 blink on
                               7 reverse video on
                               8 nondisplayed (invisible)
                               30 black foreground
                               31 red foreground
                               32 green foreground
                               33 yellow foreground
                               34 blue foreground
                               35 magenta foreground
                               36 cyan foreground
                               37 white foreground
                               40 black background
                               41 red background
                               42 green background
                               43 yellow background
                               44 blue background
                               45 magenta background
                               46 cyan background
                               47 white background
ESC[=#;7h                     Put screen in indicated mode where # is
                               0 for 40x25 black and white
                               1 40x25 color
                               2 80x25 black and white
                               3 80x25 color
                               4 320x200 color graphics
                               5 320x200 black and white graphics
                               6 640x200 black and white graphics
                               7 to wrap at end of line
ESC[=#;7l                     Resets mode # set with above command
Keyboard Reassignments       
ESC[#;#;....#p                The first ASCII code defines what is to be
                               changed; the remaining codes define what it
                               is to be changed to; strings are permitted.
                              
                               Examples:
                               ESC[65;81p - A becomes Q
                               ESC[81;65p - Q becomes A
                               ESC[0;68;"dir";13p - Assign the F10 key to
                               a DIR command.
                               The 0;68 portion is the extended ASCII code
                               for the F10 key and 13 is the ASCII code
                               for a carriage return.
                               Other function key codes: F1=59, F2=60,
                               F3=61, ... F10=68.

You can use ANSI escape sequences in the PROMPT environment variable to
create complex command line prompts.  See the online Command Reference
(under PROMPT) for details.
For example, if you have a color monitor, try editing your CONFIG.SYS
file so that
SET PROMPT=$e[32;40m$e[1m[$P]$e[0m
 
to obtain a more colorful OS/2 command line prompt.  (Case is significant
in the example given.)  You can do the same for your DOS sessions if you
edit PROMPT in AUTOEXEC.BAT, assuming you have ANSI.SYS loaded.  Note
that the $i portion of your PROMPT will enable the help line at the top
of the window or screen.  It is not included in the example above.
 
ANSI的Escape序列屏幕控制码
格式: echo "33[字背景颜色;字体颜色m字符串33[0m"

例如:
echo "33[41;36m something here 33[0m"  

其中41的位置代表底色, 36的位置是代表字的颜色


那些ascii code 是对颜色调用的始末.  
33[ ; m …… 33[0m  



字背景颜色范围:40----49
40:黑
41:深红
42:绿
43:黄色
44:蓝色
45:紫色
46:深绿
47:白色

字颜色:30-----------39
30:黑
31:红
32:绿
33:黄
34:蓝色
35:紫色
36:深绿
37:白色

===============================================ANSI控制码的说明  
33[0m 关闭所有属性  
33[1m 设置高亮度  
33[4m 下划线  
33[5m 闪烁  
33[7m 反显  
33[8m 消隐  
33[30m -- 33[37m 设置前景色  
33[40m -- 33[47m 设置背景色  
33[nA 光标上移n行  
33[nB 光标下移n行  
33[nC 光标右移n行  
33[nD 光标左移n行  
33[y;xH设置光标位置  
33[2J 清屏  
33[K 清除从光标到行尾的内容  
33[s 保存光标位置  
33[u 恢复光标位置  
33[?25l 隐藏光标  
33[?25h 显示光标  
阅读(1095) | 评论(0) | 转发(0) |
0

上一篇:钻石数

下一篇:Ubuntu for human beings!

给主人留下些什么吧!~~