KiCad PCB EDA Suite
Loading...
Searching...
No Matches
console_log.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program 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 General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#ifndef __DRC_PROTO_H
21#define __DRC_PROTO_H
22
23#include <string>
24
26#include <reporter.h>
27#include <optional>
28
29class BOARD;
30
32{
33public:
34 enum COLOR {
35 RED = 0,
38 };
39
41
42 void PrintProgress( const wxString& aMessage )
43 {
46
47 printf("%s", (const char *) aMessage.c_str() );
48 fflush(stdout);
49
51 }
52
53
54 void Print( const wxString& aMessage )
55 {
58
59 printf("%s", (const char *) aMessage.c_str() );
60 fflush(stdout);
61
63 }
64
65
66 void SetColor( COLOR color )
67 {
68 std::map<COLOR, wxString> colorMap =
69 {
70 { RED, "\033[0;31m" },
71 { GREEN, "\033[0;32m" },
72 { DEFAULT, "\033[0;37m" }
73 };
74
75 printf( "%s", (const char*) colorMap[ color ].c_str() );
76 fflush(stdout);
77 }
78
79
80private:
82 {
83 printf("\r\033[K");
84 fflush(stdout);
85 }
86
88 std::mutex m_lock;
89};
90
92{
93public:
98
99 virtual void SetCurrentProgress( double aProgress ) override
100 {
102 updateUI();
103 }
104
105private:
106 virtual bool updateUI() override
107 {
108 m_log->SetColor( CONSOLE_LOG::GREEN );
109 m_log->PrintProgress( wxString::Format( " | %s : %.02f%%",
111 (double) m_progress / (double) m_maxProgress *
112 100.0 ) );
113 return true;
114 }
115
117};
118
120{
121public:
123 m_log(log)
124 {};
126
127
128 virtual REPORTER& Report( const wxString& aText,
129 SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override
130 {
131 switch( aSeverity )
132 {
134 m_log->SetColor( CONSOLE_LOG::RED );
135 m_log->Print("ERROR | ");
136 break;
137
138 default:
139 m_log->SetColor( CONSOLE_LOG::DEFAULT );
140 m_log->Print(" | ");
141 }
142
143 m_log->SetColor( CONSOLE_LOG::DEFAULT );
144 m_log->Print( aText + "\n" );
145 return *this;
146 }
147
148 virtual bool HasMessage() const override
149 {
150 return true;
151 }
152
153private:
155};
156
157#endif
158
159
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:372
void Print(const wxString &aMessage)
Definition console_log.h:54
void PrintProgress(const wxString &aMessage)
Definition console_log.h:42
std::mutex m_lock
Definition console_log.h:88
void SetColor(COLOR color)
Definition console_log.h:66
void eraseLastLine()
Definition console_log.h:81
bool m_lastLineIsProgressBar
Definition console_log.h:87
CONSOLE_LOG * m_log
virtual bool HasMessage() const override
Returns true if any messages were reported.
CONSOLE_MSG_REPORTER(CONSOLE_LOG *log)
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
virtual void SetCurrentProgress(double aProgress) override
Set the progress value to aProgress (0..1).
Definition console_log.h:99
CONSOLE_PROGRESS_REPORTER(CONSOLE_LOG *log)
Definition console_log.h:94
virtual bool updateUI() override
virtual void SetCurrentProgress(double aProgress) override
Set the progress value to aProgress (0..1).
REPORTER()
Definition reporter.h:73
SEVERITY
@ RPT_SEVERITY_ERROR
@ RPT_SEVERITY_UNDEFINED