8 log->info(1, SFUNCTION_NAME,
" g4 dialog : GUI_Session created");
13 QString fullQString = QString::fromStdString(coutString);
22 QRegularExpression lineBreakRegex(
"\r?\n|\u2028");
23 QStringList lines = fullQString.split(lineBreakRegex, Qt::KeepEmptyParts);
25 for (
const QString& line : lines) {
26 QString htmlLine = ansiToHtml(line);
36 QString fullQString = QString::fromStdString(cerrString);
39 QRegularExpression lineBreakRegex(
"\\r?\\n|\\u2028");
40 QStringList lines = fullQString.split(lineBreakRegex, Qt::KeepEmptyParts);
42 for (
const QString& line : lines) {
43 QString htmlLine = ansiToHtml(line);
54QString GUI_Session::ansiToHtml(
const QString& ansiText) {
56 htmlText.reserve(ansiText.length() * 1.2);
60 bool isUnderlined =
false;
61 QString currentColor =
"";
64 QMap<int, QString> colorMap;
65 colorMap[30] =
"black";
67 colorMap[32] =
"green";
68 colorMap[33] =
"darkorange";
69 colorMap[34] =
"blue";
70 colorMap[35] =
"magenta";
71 colorMap[36] =
"cyan";
72 colorMap[37] =
"grey";
75 QRegularExpression ansiRegex(
"\x1B\\[([0-9;]*)m");
78 QRegularExpressionMatchIterator i = ansiRegex.globalMatch(ansiText);
81 QRegularExpressionMatch match = i.next();
82 int currentPos = match.capturedStart();
85 if (currentPos > lastPos) {
86 QString textSegment = ansiText.mid(lastPos, currentPos - lastPos);
88 htmlText += textSegment.toHtmlEscaped();
92 QString codesStr = match.captured(1);
93 QStringList codes = codesStr.split(
';', Qt::SkipEmptyParts);
95 if (codes.isEmpty()) {
101 bool nextBold = isBold;
102 bool nextUnderlined = isUnderlined;
103 QString nextColor = currentColor;
104 bool resetDetected =
false;
106 for (
const QString& codeStr : codes) {
108 int code = codeStr.toInt(&ok);
112 resetDetected =
true;
114 nextUnderlined =
false;
120 else if (code == 1) {
123 else if (code == 4) {
124 nextUnderlined =
true;
126 else if (code == 22) {
129 else if (code == 24) {
130 nextUnderlined =
false;
132 else if (code >= 30 && code <= 37) {
133 nextColor = colorMap.value(code,
"");
135 else if (code == 39) {
144 if (isUnderlined && !nextUnderlined) { htmlText +=
"</u>"; }
145 if (isBold && !nextBold) { htmlText +=
"</b>"; }
146 if (!currentColor.isEmpty() && currentColor != nextColor) { htmlText +=
"</font>"; }
149 if (isUnderlined) htmlText +=
"</u>";
150 if (isBold) htmlText +=
"</b>";
151 if (!currentColor.isEmpty()) htmlText +=
"</font>";
156 if (!currentColor.isEmpty() && currentColor != nextColor) {
158 if (!nextColor.isEmpty()) { htmlText += QString(
"<font color=\"%1\">").arg(nextColor); }
160 else if (currentColor.isEmpty() && !nextColor.isEmpty()) {
162 htmlText += QString(
"<font color=\"%1\">").arg(nextColor);
165 if (!isBold && nextBold) { htmlText +=
"<b>"; }
166 if (!isUnderlined && nextUnderlined) { htmlText +=
"<u>"; }
170 isUnderlined = nextUnderlined;
171 currentColor = nextColor;
174 lastPos = match.capturedEnd();
178 if (lastPos < ansiText.length()) {
179 QString textSegment = ansiText.mid(lastPos);
180 htmlText += textSegment.toHtmlEscaped();
184 if (isUnderlined) { htmlText +=
"</u>"; }
185 if (isBold) { htmlText +=
"</b>"; }
186 if (!currentColor.isEmpty()) { htmlText +=
"</font>"; }
A widget that displays read-only log text along with a top bar for search, clear, and save actions.
void appendLog(const QString &text)
Appends a log message to the log tab.
GUI_Session(const std::shared_ptr< GOptions > &gopt, GBoard *board)
Constructs a new GUI_Session object.
G4int ReceiveG4cerr(const G4String &cerrString) override
Receives error output from GEANT4.
G4int ReceiveG4cout(const G4String &coutString) override
Receives standard output from GEANT4.
constexpr const char * G4DIALOG_LOGGER