Skip to content

Commit

Permalink
fixed issue of text color changing for code blocks in light mode (nom…
Browse files Browse the repository at this point in the history
  • Loading branch information
lakkn authored Jul 31, 2023
1 parent 55f96aa commit 3d2db76
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions gpt4all-chat/responsetext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ enum Language {
Php
};


static QColor defaultColor = "#d1d5db"; // white
static QColor keywordColor = "#2e95d3"; // blue
static QColor functionColor = "#f22c3d"; // red
static QColor functionCallColor = "#e9950c"; // orange
Expand Down Expand Up @@ -91,6 +93,12 @@ static QVector<HighlightingRule> pythonHighlightingRules()

HighlightingRule rule;

QTextCharFormat defaultFormat;
defaultFormat.setForeground(defaultColor);
rule.pattern = QRegularExpression(".*");
rule.format = defaultFormat;
highlightingRules.append(rule);

QTextCharFormat functionCallFormat;
functionCallFormat.setForeground(functionCallColor);
rule.pattern = QRegularExpression("\\b(\\w+)\\s*(?=\\()");
Expand Down Expand Up @@ -151,6 +159,12 @@ static QVector<HighlightingRule> csharpHighlightingRules()

HighlightingRule rule;

QTextCharFormat defaultFormat;
defaultFormat.setForeground(defaultColor);
rule.pattern = QRegularExpression(".*");
rule.format = defaultFormat;
highlightingRules.append(rule);

// Function call highlighting
QTextCharFormat functionCallFormat;
functionCallFormat.setForeground(functionCallColor);
Expand Down Expand Up @@ -219,6 +233,12 @@ static QVector<HighlightingRule> cppHighlightingRules()

HighlightingRule rule;

QTextCharFormat defaultFormat;
defaultFormat.setForeground(defaultColor);
rule.pattern = QRegularExpression(".*");
rule.format = defaultFormat;
highlightingRules.append(rule);

QTextCharFormat functionCallFormat;
functionCallFormat.setForeground(functionCallColor);
rule.pattern = QRegularExpression("\\b(\\w+)\\s*(?=\\()");
Expand Down Expand Up @@ -297,6 +317,12 @@ static QVector<HighlightingRule> typescriptHighlightingRules()

HighlightingRule rule;

QTextCharFormat defaultFormat;
defaultFormat.setForeground(defaultColor);
rule.pattern = QRegularExpression(".*");
rule.format = defaultFormat;
highlightingRules.append(rule);

QTextCharFormat functionCallFormat;
functionCallFormat.setForeground(functionCallColor);
rule.pattern = QRegularExpression("\\b(\\w+)\\s*(?=\\()");
Expand Down Expand Up @@ -381,6 +407,12 @@ static QVector<HighlightingRule> javaHighlightingRules()

HighlightingRule rule;

QTextCharFormat defaultFormat;
defaultFormat.setForeground(defaultColor);
rule.pattern = QRegularExpression(".*");
rule.format = defaultFormat;
highlightingRules.append(rule);

QTextCharFormat functionCallFormat;
functionCallFormat.setForeground(functionCallColor);
rule.pattern = QRegularExpression("\\b(\\w+)\\s*(?=\\()");
Expand Down Expand Up @@ -450,6 +482,12 @@ static QVector<HighlightingRule> goHighlightingRules()

HighlightingRule rule;

QTextCharFormat defaultFormat;
defaultFormat.setForeground(defaultColor);
rule.pattern = QRegularExpression(".*");
rule.format = defaultFormat;
highlightingRules.append(rule);

QTextCharFormat functionCallFormat;
functionCallFormat.setForeground(functionCallColor);
rule.pattern = QRegularExpression("\\b(\\w+)\\s*(?=\\()");
Expand Down Expand Up @@ -515,6 +553,12 @@ static QVector<HighlightingRule> bashHighlightingRules()

HighlightingRule rule;

QTextCharFormat defaultFormat;
defaultFormat.setForeground(defaultColor);
rule.pattern = QRegularExpression(".*");
rule.format = defaultFormat;
highlightingRules.append(rule);

QTextCharFormat commandFormat;
commandFormat.setForeground(commandColor);
QStringList commandPatterns = {
Expand Down Expand Up @@ -582,6 +626,12 @@ static QVector<HighlightingRule> latexHighlightingRules()

HighlightingRule rule;

QTextCharFormat defaultFormat;
defaultFormat.setForeground(defaultColor);
rule.pattern = QRegularExpression(".*");
rule.format = defaultFormat;
highlightingRules.append(rule);

QTextCharFormat commandFormat;
commandFormat.setForeground(commandColor); // commandColor needs to be set to your liking
rule.pattern = QRegularExpression("\\\\[A-Za-z]+"); // Pattern for LaTeX commands
Expand All @@ -604,6 +654,12 @@ static QVector<HighlightingRule> htmlHighlightingRules()

HighlightingRule rule;

QTextCharFormat defaultFormat;
defaultFormat.setForeground(defaultColor);
rule.pattern = QRegularExpression(".*");
rule.format = defaultFormat;
highlightingRules.append(rule);

QTextCharFormat attributeNameFormat;
attributeNameFormat.setForeground(attributeNameColor);
rule.pattern = QRegularExpression("\\b(\\w+)\\s*=");
Expand Down Expand Up @@ -644,6 +700,12 @@ static QVector<HighlightingRule> phpHighlightingRules()

HighlightingRule rule;

QTextCharFormat defaultFormat;
defaultFormat.setForeground(defaultColor);
rule.pattern = QRegularExpression(".*");
rule.format = defaultFormat;
highlightingRules.append(rule);

QTextCharFormat functionCallFormat;
functionCallFormat.setForeground(functionCallColor);
rule.pattern = QRegularExpression("\\b(\\w+)\\s*(?=\\()");
Expand Down Expand Up @@ -711,6 +773,12 @@ static QVector<HighlightingRule> jsonHighlightingRules()

HighlightingRule rule;

QTextCharFormat defaultFormat;
defaultFormat.setForeground(defaultColor);
rule.pattern = QRegularExpression(".*");
rule.format = defaultFormat;
highlightingRules.append(rule);

// Key string rule
QTextCharFormat keyFormat;
keyFormat.setForeground(keyColor); // Assuming keyColor is defined
Expand Down

0 comments on commit 3d2db76

Please sign in to comment.