00001
00002
00003
00004
00005 #ifndef __J2K__ANSI_HPP__
00006 #define __J2K__ANSI_HPP__
00007
00008 #include <j2k/Fred/Standard.hpp>
00009
00010 void Locate( USHORT row, USHORT col ) {
00011 printf("\033[%d;%dH", row, col );
00012 }
00013
00014 void gotoXY( USHORT row, USHORT col ) {
00015 printf("\033[%d;%df", row, col );
00016 }
00017
00018 void goUp( USHORT y ) {
00019 printf("\033[%dA", y );
00020 }
00021
00022 void goDown( USHORT y ) {
00023 printf("\033[%dB", y );
00024 }
00025
00026 void goRight( USHORT x ) {
00027 printf("\033[%dC", x );
00028 }
00029
00030 void goLeft( USHORT y ) {
00031 printf("\033[%dD", y );
00032 }
00033
00034 void saveCursor() {
00035 printf("\033[s" );
00036 }
00037
00038 void loadCursor() {
00039 printf("\033[u" );
00040 }
00041
00042 void EraseLine() {
00043 printf("\033[K" );
00044 }
00045
00046 enum VideoMode_t {
00047 Text40x25BW = 0x0000,
00048
00049 Text40x25C = 0x0001,
00050 Text40 = 0x0001,
00051
00052 Text80x25BW = 0x0002,
00053
00054 Text80x25C = 0x0003,
00055 Text80 = 0x0003,
00056
00057 Graph320x200x4C = 0x0004,
00058 Graph320x200x4BW = 0x0005,
00059
00060 Graph640x200x4C = 0x0006,
00061
00062 GraphMonoCard = 0x0007,
00063
00064 Graph160x200x16jr = 0x0008,
00065 Graph320x200x16jr = 0x0009,
00066 Graph640x200x4jr = 0x000A,
00067
00068 Graph320x200x16 = 0x000D,
00069 Graph640x200x16 = 0x000E,
00070 Graph640x350BW = 0x000F,
00071 Graph640x350x16 = 0x0010,
00072
00073 Graph640x480x2 = 0x0011,
00074
00075 Graph640x480x16 = 0x0012,
00076 VGA16 = 0x0012,
00077
00078 Graph320x200x256 = 0x0013,
00079 VGA256 = 0x0013
00080 };
00081
00082 void screen( enum VideoMode_t mode = Text80 ) {
00083 printf("\033[=%dh", (short)mode );
00084 }
00085
00086
00087 void screenNoLine( enum VideoMode_t mode = Text80 ) {
00088 printf("\033[=%dl", (short)mode );
00089 }
00090
00091 void Center( short row, const char* text ) {
00092 register short col = 41 - strlen( text ) / 2;
00093 Locate( row, col );
00094 printf("%s", text );
00095 }
00096
00097 const char* colorNameTable[ 16 ] = {
00098 "Black ",
00099 "Dark Red ",
00100 "Dark Green ",
00101 "Brown ",
00102 "Dark Blue ",
00103 "Dark Purple ",
00104 "Dark Cyan ",
00105 "Dark White ",
00106 "Gray ",
00107 "Bright Red ",
00108 "Bright Green ",
00109 "Bright Yellow",
00110 "Bright Blue ",
00111 "Bright Purple",
00112 "Bright Cyan ",
00113 "Bright White "
00114 };
00115
00116 enum TextAttr_t {
00117 NoAttribute = 0,
00118 Bold = 1,
00119 Underline = 4,
00120 Flashing = 5,
00121 InverseVideo = 7,
00122 HiddenText = 8
00123 };
00124
00125 enum Color_t {
00126 Black = 0,
00127 Red = 1,
00128 Green = 2,
00129 Yellow = 3,
00130 Blue = 4,
00131 Purple = 5,
00132 Cyan = 6,
00133 White = 7
00134 };
00135
00136 short Ansi2QBColorTable[ 8 ] = {
00137 0,
00138 4,
00139 2,
00140 6,
00141 1,
00142 5,
00143 3,
00144 7
00145 };
00146
00147 void ColorName( enum Color_t fg = White, enum Color_t bg = Black, enum TextAttr_t txtAttr = NoAttribute )
00148 {
00149 register short f = (short)fg + 30;
00150 register short b = (short)bg + 40;
00151 register short a = (short)txtAttr;
00152
00153 printf("\033[%d;%d;%dm", a, f, b );
00154 }
00155
00156 void Color( short fg, short bg )
00157 {
00158 register short a = 0;
00159 if ( fg > 7 && fg <= 15 ) { a = 1; fg -= 8; }
00160 if ( fg > 15 && fg <= 22 ) { a = 5; fg -= 16; }
00161 if ( fg > 22 && fg <= 30 ) { a = 6; fg -= 24; }
00162
00163 register short f = ( fg ) + 30;
00164 register short b = ( bg ) + 40;
00165
00166 printf("\033[%d;%d;%dm", a, f, b );
00167 }
00168
00169 static int NoColor = 0;
00170
00171 void QBColor( short fg = 7, short bg = 0 )
00172 {
00173 if ( NoColor ) return;
00174 register short a = 0;
00175 if ( fg > 7 && fg <= 15 ) { a = 1; fg -= 8; }
00176 if ( fg > 15 && fg <= 22 ) { a = 5; fg -= 16; }
00177 if ( fg > 22 && fg <= 30 ) { a = 6; fg -= 24; }
00178
00179 register short qb_fg = Ansi2QBColorTable[ fg ];
00180 register short qb_bg = Ansi2QBColorTable[ bg ];
00181 register short f = ( qb_fg ) + 30;
00182 register short b = ( qb_bg ) + 40;
00183
00184 printf("\033[%d;%d;%dm", a, f, b );
00185 }
00186
00187
00188 void Cls( short bg ) {
00189 QBColor( 7, bg );
00190 printf("\033[2J" );
00191 }
00192
00193 #endif
00194