diff --git a/src/SaveHistoryTask.cpp b/src/SaveHistoryTask.cpp index 350046b64..2940411b4 100644 --- a/src/SaveHistoryTask.cpp +++ b/src/SaveHistoryTask.cpp @@ -22,6 +22,8 @@ #include "../decoders/HTMLDecoder.h" #include "../decoders/PlainTextDecoder.h" +#include "colorscheme/ColorScheme.h" +#include "colorscheme/ColorSchemeManager.h" namespace Konsole { @@ -110,7 +112,16 @@ void SaveHistoryTask::execute() if (((dialog->selectedNameFilter()).contains(QLatin1String("html"), Qt::CaseInsensitive)) || ((dialog->selectedFiles()).at(0).endsWith(QLatin1String("html"), Qt::CaseInsensitive))) { Profile::Ptr profile = SessionManager::instance()->sessionProfile(session); - jobInfo.decoder = new HTMLDecoder(profile->colorScheme(), profile->font()); + const auto schemeName = profile->colorScheme(); + const auto scheme = ColorSchemeManager::instance()->findColorScheme(schemeName); + QColor colorTable[TABLE_COLORS]; + if (scheme) { + scheme->getColorTable(colorTable); + } else { + std::copy_n(ColorScheme::defaultTable, TABLE_COLORS, colorTable); + } + + jobInfo.decoder = new HTMLDecoder(colorTable, profile->font()); } else { jobInfo.decoder = new PlainTextDecoder(); } diff --git a/src/Screen.cpp b/src/Screen.cpp index be6703dfd..d3f538861 100644 --- a/src/Screen.cpp +++ b/src/Screen.cpp @@ -1962,7 +1962,7 @@ QString Screen::text(int startIndex, int endIndex, const DecodingOptions options QString result; QTextStream stream(&result, QIODevice::ReadWrite); - HTMLDecoder htmlDecoder; + HTMLDecoder htmlDecoder(ColorScheme::defaultTable); PlainTextDecoder plainTextDecoder; TerminalCharacterDecoder *decoder; diff --git a/src/autotests/TerminalCharacterDecoderTest.cpp b/src/autotests/TerminalCharacterDecoderTest.cpp index bd23df1ac..4ae3f585b 100644 --- a/src/autotests/TerminalCharacterDecoderTest.cpp +++ b/src/autotests/TerminalCharacterDecoderTest.cpp @@ -11,6 +11,7 @@ // Konsole #include "../decoders/HTMLDecoder.h" #include "../decoders/PlainTextDecoder.h" +#include "colorscheme/ColorScheme.h" // Qt #include @@ -101,7 +102,7 @@ void TerminalCharacterDecoderTest::testHTMLDecoder() QFETCH(QVector, renditions); QFETCH(QString, result); - TerminalCharacterDecoder *decoder = new HTMLDecoder(); + TerminalCharacterDecoder *decoder = new HTMLDecoder(ColorScheme::defaultTable); auto testCharacters = new Character[text.size()]; convertToCharacter(testCharacters, text, renditions); QString outputString; diff --git a/src/decoders/CMakeLists.txt b/src/decoders/CMakeLists.txt index 7fe6644c3..f482cf47b 100644 --- a/src/decoders/CMakeLists.txt +++ b/src/decoders/CMakeLists.txt @@ -12,4 +12,4 @@ target_include_directories(konsoledecoders INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) # TODO: remove the konsolecolorscheme dependencies -target_link_libraries(konsoledecoders konsolecharacters konsolecolorscheme) +target_link_libraries(konsoledecoders konsolecharacters) diff --git a/src/decoders/HTMLDecoder.cpp b/src/decoders/HTMLDecoder.cpp index 2750ce684..c67f9602d 100644 --- a/src/decoders/HTMLDecoder.cpp +++ b/src/decoders/HTMLDecoder.cpp @@ -7,9 +7,6 @@ // Own #include "HTMLDecoder.h" -// Konsole colorScheme -#include - // Konsole characters #include @@ -18,9 +15,8 @@ using namespace Konsole; -HTMLDecoder::HTMLDecoder(const QString &colorSchemeName, const QFont &profileFont) +HTMLDecoder::HTMLDecoder(const QColor *colorTable, const QFont &profileFont) : _output(nullptr) - , _colorSchemeName(colorSchemeName) , _profileFont(profileFont) , _innerSpanOpen(false) , _lastRendition(DEFAULT_RENDITION) @@ -28,23 +24,8 @@ HTMLDecoder::HTMLDecoder(const QString &colorSchemeName, const QFont &profileFon , _lastBackColor(CharacterColor()) , _validProfile(false) { - std::shared_ptr colorScheme = nullptr; - - if (!colorSchemeName.isEmpty()) { - colorScheme = ColorSchemeManager::instance()->findColorScheme(colorSchemeName); - - if (colorScheme == nullptr) { - colorScheme = ColorSchemeManager::instance()->defaultColorScheme(); - } - - _validProfile = true; - } - - if (colorScheme != nullptr) { - colorScheme->getColorTable(_colorTable); - } else { - std::copy_n(ColorScheme::defaultTable, TABLE_COLORS, _colorTable); - } + Q_ASSERT(colorTable); + std::copy_n(colorTable, TABLE_COLORS, _colorTable); } void HTMLDecoder::begin(QTextStream *output) diff --git a/src/decoders/HTMLDecoder.h b/src/decoders/HTMLDecoder.h index 3e13fc87d..340d23bb0 100644 --- a/src/decoders/HTMLDecoder.h +++ b/src/decoders/HTMLDecoder.h @@ -24,7 +24,7 @@ public: /** * Constructs an HTML decoder using a default black-on-white color scheme. */ - explicit HTMLDecoder(const QString &colorSchemeName = QString(), const QFont &profileFont = QFont()); + explicit HTMLDecoder(const QColor *colorTable, const QFont &profileFont = QFont()); void decodeLine(const Character *const characters, int count, LineProperty properties) override; @@ -36,7 +36,6 @@ private: void closeSpan(QString &text); QTextStream *_output; - QString _colorSchemeName; QFont _profileFont; QColor _colorTable[TABLE_COLORS]; bool _innerSpanOpen;