Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Colorize filtered output #58

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
58 changes: 56 additions & 2 deletions src/showbootlog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#include <QRegularExpression>
#include <QCompleter>
#include <QThread>
#include <QColorDialog>
#include <QRandomGenerator>

ShowBootLog::ShowBootLog(QWidget *parent) :
QDialog(parent),
Expand Down Expand Up @@ -111,6 +113,7 @@ void ShowBootLog::updateBootLog(bool keepIdentifiers)
// Reset all previously accepted but also read identifiers (clear the filter but also do a full reload!)
this->allIdentifiers.clear();
this->acceptedIdentifiers.clear();
this->acceptedIdentifiersColors.clear();
identifierFlags = "";

// Also reset the UI parts
Expand Down Expand Up @@ -182,16 +185,51 @@ void ShowBootLog::updateBootLog(bool keepIdentifiers)

void ShowBootLog::acceptIdentifier(void){
this->acceptedIdentifiers.insert(ui->identifiersLineEdit->text());
this->acceptedIdentifiersColors.insert(ui->identifiersLineEdit->text(), ui->identifiersLineEdit->palette().color(QPalette::Base));
updateBootLog(true);
ui->identifiersLineEdit->clear();
QPalette palette(QPalette::Base, Qt::white);
ui->identifiersLineEdit->setPalette(palette);
ui->identifiersLineEdit->setFocus();
}


void ShowBootLog::appendToBootLog(QString readString)
{
// Append string to the UI and increment byte counter
ui->plainTextEdit->appendPlainText(readString);
QStringList readStringLines = readString.split("\n");
QTextCharFormat defaultFormat, format;
QColor defaultColor, color;
bool found;
for ( const auto& line : readStringLines )
{
// Let's find if regex apply for the current line
found = false;
for(const auto& identifier : this->acceptedIdentifiers){
QRegularExpression re(identifier);
QRegularExpressionMatch match = re.match(line);
found = match.hasMatch();
if(found)
{
color = this->acceptedIdentifiersColors.value(identifier);
break;
}
}
if(found)
{
format = ui->plainTextEdit->currentCharFormat();
defaultFormat = format;
format.setBackground(QBrush(color));
ui->plainTextEdit->setCurrentCharFormat(format);
ui->plainTextEdit->appendPlainText(line);
ui->plainTextEdit->setCurrentCharFormat(defaultFormat);
}
else
{
ui->plainTextEdit->appendPlainText(line);
}

}
numberOfBytesRead += readString.size();
ui->plainTextEdit->ensureCursorVisible();

Expand Down Expand Up @@ -268,7 +306,8 @@ void ShowBootLog::on_filterButton_clicked()
{
acceptIdentifier();
ui->identifiersLineEdit->clear();

QPalette palette(QPalette::Base, Qt::white);
ui->identifiersLineEdit->setPalette(palette);
updateBootLog(true);
}

Expand Down Expand Up @@ -376,7 +415,10 @@ void ShowBootLog::on_clearButton_clicked()
{
ui->acceptedIdentifierLabel->setText("");
ui->identifiersLineEdit->clear();
QPalette palette(QPalette::Base, Qt::white);
ui->identifiersLineEdit->setPalette(palette);
this->acceptedIdentifiers.clear();
this->acceptedIdentifiersColors.clear();
updateBootLog(false);
}

Expand All @@ -401,3 +443,15 @@ void ShowBootLog::on_exportSelectionButton_clicked()
writeToExportFile(fileName, selection.toLocal8Bit().data());
}

void ShowBootLog::on_selectColorButton_clicked()
{
QColor color = QColorDialog::getColor(QColor::fromRgb(QRandomGenerator::global()->generate()), this );
QPalette palette;
palette.setColor(QPalette::Base, color);
if( color.isValid() )
{
qDebug() << "Color Choosen : " << color.name();
ui->identifiersLineEdit->setPalette(palette);
}

}
9 changes: 6 additions & 3 deletions src/showbootlog.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ private slots:

void on_exportSelectionButton_clicked();

void on_horizontalSlider_valueChanged(int value);
void on_horizontalSlider_valueChanged(int value);

void on_selectColorButton_clicked();

private:
void updateBootLog(bool keepIdentifiers=false);
Expand All @@ -83,8 +85,9 @@ private slots:
// Internal display variables
int numberOfBytesRead=0;
QString identifierFlags="";
QSet<QString> allIdentifiers;
QSet<QString> acceptedIdentifiers;
QSet<QString> allIdentifiers;
QSet<QString> acceptedIdentifiers;
QMap<QString, QColor> acceptedIdentifiersColors;

void execute_find(QRegExp regexp, QTextDocument::FindFlags findFlags);
void execute_find(QString string, QTextDocument::FindFlags findFlags);
Expand Down
10 changes: 10 additions & 0 deletions ui/showbootlog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,16 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="selectColorButton">
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="text">
<string>Set Color</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="filterButton">
<property name="focusPolicy">
Expand Down