Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ansi_escape.h
Go to the documentation of this file.
1 
2 // These are ANSI escape codes used to modify how characters
3 // are drawn on a vt100-like terminal (e.g. xterm).
4 //
5 // Example 1:
6 // Write a string in bold font
7 //
8 // cout<<ansi_bold<<"I am bold!"<<ansi_normal<<endl;
9 //
10 //
11 // Example 2:
12 // Write a message in green and then go up 2 lines and
13 // write another in red
14 //
15 // cout<<ansi_green<<"Spring is wonderful"<<ansi_normal<<endl;
16 // cout<<ansi_up(3)<<ansi_red<<"We're all going to die!"<<ansi_normal<<ansi_down(3);
17 //
18 //
19 // Note that the character drawing attributes (bold, color, etc...)
20 // will stay with the terminal even after your program exits. As such,
21 // it is advisable to immediately send a ansi_normal sequence to the
22 // screen as soon as you've finished writing the formatted message.
23 //
24 
25 #ifndef ansi_escape
26 #define ansi_escape ((char)0x1b)
27 #define ansi_bold ansi_escape<<"[1m"
28 #define ansi_italic ansi_escape<<"[3m"
29 #define ansi_underline ansi_escape<<"[4m"
30 #define ansi_blink ansi_escape<<"[5m"
31 #define ansi_rapid_blink ansi_escape<<"[6m"
32 #define ansi_reverse ansi_escape<<"[7m"
33 #define ansi_black ansi_escape<<"[30m"
34 #define ansi_red ansi_escape<<"[31m"
35 #define ansi_green ansi_escape<<"[32m"
36 #define ansi_blue ansi_escape<<"[34m"
37 #define ansi_normal ansi_escape<<"[0m"
38 #define ansi_up(A) ansi_escape<<"["<<(A)<<"A"
39 #define ansi_down(A) ansi_escape<<"["<<(A)<<"B"
40 #define ansi_forward(A) ansi_escape<<"["<<(A)<<"C"
41 #define ansi_back(A) ansi_escape<<"["<<(A)<<"D"
42 #endif // ansi_escape