1
/***************************************************************************
2
* Copyright (c) 2004 Jürgen Riegel <juergen.riegel@web.de> *
4
* This file is part of the FreeCAD CAx development system. *
6
* This library is free software; you can redistribute it and/or *
7
* modify it under the terms of the GNU Library General Public *
8
* License as published by the Free Software Foundation; either *
9
* version 2 of the License, or (at your option) any later version. *
11
* This library is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
* GNU Library General Public License for more details. *
16
* You should have received a copy of the GNU Library General Public *
17
* License along with this library; see the file COPYING.LIB. If not, *
18
* write to the Free Software Foundation, Inc., 59 Temple Place, *
19
* Suite 330, Boston, MA 02111-1307, USA *
21
***************************************************************************/
24
#include "PreCompiled.h"
35
#include "GuiConsole.h"
41
const unsigned int GUIConsole::s_nMaxLines = 1000;
42
unsigned int GUIConsole::s_nRefCount = 0;
45
* Open a Top level Window and redirect the
46
* stdin, stdout and stderr stream to it.
47
* Not needed in Linux!
49
GUIConsole::GUIConsole (void)
55
CONSOLE_SCREEN_BUFFER_INFO csbi;
59
::GetConsoleScreenBufferInfo(::GetStdHandle(STD_OUTPUT_HANDLE),&csbi);
60
csbi.dwSize.Y = s_nMaxLines;
61
::SetConsoleScreenBufferSize(::GetStdHandle(STD_OUTPUT_HANDLE),csbi.dwSize);
62
::SetConsoleTitleA( "FreeCAD Console");
64
*stdout = *::_fdopen(::_open_osfhandle(reinterpret_cast<intptr_t>(::GetStdHandle(STD_OUTPUT_HANDLE)), _O_TEXT), "w");
65
::setvbuf(stdout, 0, _IONBF, 0);
67
*stdin = *::_fdopen(::_open_osfhandle(reinterpret_cast<intptr_t>(::GetStdHandle(STD_INPUT_HANDLE)), _O_TEXT), "r");
68
::setvbuf(stdin, 0, _IONBF, 0);
70
*stderr = *::_fdopen(::_open_osfhandle(reinterpret_cast<intptr_t>(::GetStdHandle(STD_ERROR_HANDLE)), _O_TEXT), "w");
71
::setvbuf(stderr, 0, _IONBF, 0);
76
* Close the window and redirect the streams back
78
GUIConsole::~GUIConsole (void)
84
void GUIConsole::SendLog(const std::string& notifiername, const std::string& msg, Base::LogStyle level,
85
Base::IntendedRecipient recipient, Base::ContentType content)
89
// Do not log translated messages, or messages intended only to the user to std log
90
if(recipient == Base::IntendedRecipient::User || content == Base::ContentType::Translated)
95
case Base::LogStyle::Warning:
96
color = FOREGROUND_RED | FOREGROUND_GREEN;
98
case Base::LogStyle::Message:
99
color = FOREGROUND_GREEN;
101
case Base::LogStyle::Error:
102
color = FOREGROUND_RED;
104
case Base::LogStyle::Log:
105
color = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;
107
case Base::LogStyle::Critical:
108
color = FOREGROUND_RED | FOREGROUND_GREEN;
114
::SetConsoleTextAttribute(::GetStdHandle(STD_OUTPUT_HANDLE), color);
115
printf("%s", msg.c_str());
116
::SetConsoleTextAttribute(::GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE );
119
#else /* FC_OS_LINUX */
121
// safely ignore GUIConsole::s_nMaxLines and GUIConsole::s_nRefCount
122
GUIConsole::GUIConsole () = default;
123
GUIConsole::~GUIConsole () = default;
124
void GUIConsole::SendLog(const std::string& notifiername, const std::string& msg, Base::LogStyle level,
125
Base::IntendedRecipient recipient, Base::ContentType content)
129
// Do not log translated messages, or messages intended only to the user to std log
130
if(recipient == Base::IntendedRecipient::User || content == Base::ContentType::Translated)
134
case Base::LogStyle::Warning:
135
std::cerr << "Warning: " << msg;
137
case Base::LogStyle::Message:
140
case Base::LogStyle::Error:
141
std::cerr << "Error: " << msg;
143
case Base::LogStyle::Log:
146
case Base::LogStyle::Critical:
147
std::cout << "Critical: " << msg;
154
#endif /* FC_OS_LINUX */