diff options
author | w00t <w00t@e03df62e-2008-0410-955e-edbf42e46eb7> | 2007-05-19 16:01:06 +0000 |
---|---|---|
committer | w00t <w00t@e03df62e-2008-0410-955e-edbf42e46eb7> | 2007-05-19 16:01:06 +0000 |
commit | c778d1258a3d778d0a6227b632ba5091a0eb25a0 (patch) | |
tree | 8dcd6b8e86c093784db55498b99a6a7441d91787 /win/colours.h | |
parent | 9cf56d917d92959701694477f7944d45ad2c38ed (diff) |
Helps if I add the w32 specific code, too. :p
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@7044 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'win/colours.h')
-rw-r--r-- | win/colours.h | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/win/colours.h b/win/colours.h new file mode 100644 index 000000000..574d34640 --- /dev/null +++ b/win/colours.h @@ -0,0 +1,81 @@ +#define TRED FOREGROUND_RED | FOREGROUND_INTENSITY
+#define TGREEN FOREGROUND_GREEN | FOREGROUND_INTENSITY
+#define TYELLOW FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY
+#define TNORMAL FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE
+#define TWHITE TNORMAL | FOREGROUND_INTENSITY
+#define TBLUE FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY
+
+inline void sc(WORD color) { SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color); }
+
+/* Handles colors in printf */
+int printf_c(const char * format, ...)
+{
+ // Better hope we're not multithreaded, otherwise we'll have chickens crossing the road other side to get the to :P
+ static char message[500];
+ static char temp[10];
+ int color1, color2;
+
+ /* parse arguments */
+ va_list ap;
+ va_start(ap, format);
+ vsprintf(message, format, ap);
+ va_end(ap);
+
+ /* search for unix-style escape sequences */
+ int t;
+ int c = 0;
+ const char * p = message;
+ while(*p != 0)
+ {
+ if(*p == '\033')
+ {
+ // Escape sequence -> copy into the temp buffer, and parse the color.
+ p++;
+ t = 0;
+ while(*p != 'm')
+ {
+ temp[t++] = *p;
+ ++p;
+ }
+
+ temp[t] = 0;
+ p++;
+ if(!stricmp(temp, "[0"))
+ {
+ // Returning to normal colour.
+ SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
+ }
+ else if(!stricmp(temp, "[1"))
+ {
+ // White
+ SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), TWHITE);
+ }
+ else if(sscanf(temp, "[%u;%u", &color1, &color2) == 2)
+ {
+ switch(color2)
+ {
+ case 32: // Green
+ SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_INTENSITY); // Yellow
+ break;
+
+ default: // Unknown
+ // White
+ SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
+ break;
+ }
+ }
+ else
+ {
+ char message[50];
+ sprintf(message, "Unknown color code: %s", temp);
+ MessageBox(0, message, message, MB_OK);
+ }
+ }
+
+ putchar(*p);
+ ++c;
+ ++p;
+ }
+
+ return c;
+}
|