CGR Localization
 All Classes Namespaces Files Functions Variables Macros Pages
terminal_utils.cpp
Go to the documentation of this file.
1 //========================================================================
2 // This software is free: you can redistribute it and/or modify
3 // it under the terms of the GNU Lesser General Public License Version 3,
4 // as published by the Free Software Foundation.
5 //
6 // This software is distributed in the hope that it will be useful,
7 // but WITHOUT ANY WARRANTY; without even the implied warranty of
8 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 // GNU Lesser General Public License for more details.
10 //
11 // You should have received a copy of the GNU Lesser General Public License
12 // Version 3 in the file COPYING that came with this distribution.
13 // If not, see <http://www.gnu.org/licenses/>.
14 //========================================================================
20 //========================================================================
21 
22 #include "terminal_utils.h"
23 
24 void ColourTerminal(unsigned char fg, unsigned char bg, unsigned char attr)
25 {
26 #ifdef WIN32
27  HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
28  SetConsoleTextAttribute(hConsole, fg | (bg<<4) | attr);
29 #else
30  //printf("%c[%d;%d;%dm", 0x1B, attr, fg + 30, bg + 40);
31  printf("\033[%d;%dm", attr, fg + 30);
32  fflush(stdout);
33 #endif
34 }
35 
36 void ResetTerminal()
37 {
38 #ifdef WIN32
39  ColourTerminal(TerminalUtils::TERMINAL_COL_WHITE);
40 #else
41  printf("\033[0m");
42 #endif
43 }
44 
45 void TerminalInformation(const char* text)
46 {
47  ColourTerminal(TerminalUtils::TERMINAL_COL_BLUE, TerminalUtils::TERMINAL_COL_BLACK, TerminalUtils::TERMINAL_ATTR_BRIGHT);
48  printf("%s\n",text);
49  ResetTerminal();
50 }
51 
52 void TerminalAlert(const char* text)
53 {
54  ColourTerminal(TerminalUtils::TERMINAL_COL_GREEN, TerminalUtils::TERMINAL_COL_BLACK, TerminalUtils::TERMINAL_ATTR_BRIGHT);
55  printf("%s\n",text);
56  ResetTerminal();
57 }
58 
59 void TerminalWarning(const char* text)
60 {
61  ColourTerminal(TerminalUtils::TERMINAL_COL_RED, TerminalUtils::TERMINAL_COL_BLACK, TerminalUtils::TERMINAL_ATTR_BRIGHT);
62  printf("%s\n",text);
63  ResetTerminal();
64 }
65 
Subroutines to spice up stdout.