Commit ec64ccd3 authored by Martin Tobias Holmedahl Sandsmark's avatar Martin Tobias Holmedahl Sandsmark Committed by Tomaz Canabrava
Browse files

the url extractor kills performance a bit, so skip it if we can

parent fac05b71
Pipeline #179887 passed with stage
in 2 minutes and 10 seconds
......@@ -403,6 +403,8 @@ Q_SIGNALS:
*/
void resetCursorStyleRequest();
void toggleUrlExtractionRequest();
protected:
virtual void setMode(int mode) = 0;
virtual void resetMode(int mode) = 0;
......
......@@ -35,8 +35,10 @@ struct ExtractedUrl {
/* Stored in Screen, but used in V10Emulation to
* store extracted URL's. Perhaps this should be a Model?
*/
class EscapeSequenceUrlExtractor
class EscapeSequenceUrlExtractor : public QObject
{
Q_OBJECT
private:
/* Tell us if we are currently reading or not a URL. */
bool _reading = false;
......@@ -120,6 +122,8 @@ public:
void historyLinesRemoved(int lines);
/* starts / stops URL Processing */
public Q_SLOTS:
void toggleUrlInput();
};
......
......@@ -84,9 +84,8 @@ Screen::Screen(int lines, int columns)
, _effectiveRendition(DEFAULT_RENDITION)
, _lastPos(-1)
, _lastDrawnChar(0)
, _escapeSequenceUrlExtractor(std::make_unique<EscapeSequenceUrlExtractor>())
, _escapeSequenceUrlExtractor(nullptr)
{
_escapeSequenceUrlExtractor->setScreen(this);
std::fill(_lineProperties.begin(), _lineProperties.end(), LINE_DEFAULT);
_graphicsPlacements = std::vector<std::unique_ptr<TerminalGraphicsPlacement_t>>();
......@@ -497,7 +496,7 @@ void Screen::resizeImage(int new_lines, int new_columns)
// If _history size > max history size it will drop a line from _history.
// We need to verify if we need to remove a URL.
if (removedLines) {
if (removedLines && _escapeSequenceUrlExtractor) {
_escapeSequenceUrlExtractor->historyLinesRemoved(removedLines);
}
}
......@@ -1063,7 +1062,10 @@ notcombine:
--w;
}
_cuX = newCursorX;
_escapeSequenceUrlExtractor->appendUrlText(QChar(c));
if (_escapeSequenceUrlExtractor) {
_escapeSequenceUrlExtractor->appendUrlText(QChar(c));
}
}
int Screen::scrolledLines() const
......@@ -1732,7 +1734,7 @@ void Screen::fastAddHistLine()
// If _history size > max history size it will drop a line from _history.
// We need to verify if we need to remove a URL.
if (removeLine) {
if (removeLine && _escapeSequenceUrlExtractor) {
_escapeSequenceUrlExtractor->historyLinesRemoved(1);
}
......@@ -1760,7 +1762,7 @@ void Screen::addHistLine()
// If the history is full, increment the count
// of dropped _lines
if (newHistLines == oldHistLines) {
if (_escapeSequenceUrlExtractor && newHistLines == oldHistLines) {
++_droppedLines;
// We removed a line, we need to verify if we need to remove a URL.
......@@ -1856,6 +1858,22 @@ void Screen::fillWithDefaultChar(Character *dest, int count)
std::fill_n(dest, count, Screen::DefaultChar);
}
void Konsole::Screen::setEnableUrlExtractor(const bool enable)
{
if (enable) {
if (_escapeSequenceUrlExtractor) {
return;
}
_escapeSequenceUrlExtractor = std::make_unique<EscapeSequenceUrlExtractor>();
_escapeSequenceUrlExtractor->setScreen(this);
} else {
if (!_escapeSequenceUrlExtractor) {
return;
}
_escapeSequenceUrlExtractor.reset();
}
}
Konsole::EscapeSequenceUrlExtractor *Konsole::Screen::urlExtractor() const
{
return _escapeSequenceUrlExtractor.get();
......
......@@ -605,6 +605,8 @@ public:
return result;
}
void setEnableUrlExtractor(const bool enable);
static const Character DefaultChar;
// Return the total number of lines before resize (fix scroll glitch)
......
......@@ -455,7 +455,7 @@ void Vt102Emulation::receiveChars(const QVector<uint> &chars)
// do not.
if (s[2] == XTERM_EXTENDED::URL_LINK) {
// printf '\e]8;;https://example.com\e\\This is a link\e]8;;\e\\\n'
_currentScreen->urlExtractor()->toggleUrlInput();
emit toggleUrlExtractionRequest();
}
processSessionAttributeRequest(p - 1);
resetTokenizer();
......@@ -733,7 +733,7 @@ void Vt102Emulation::processSessionAttributeRequest(int tokenSize)
++i;
QString value = QString::fromUcs4(&tokenBuffer[i], tokenSize - i);
if (_currentScreen->urlExtractor()->reading()) {
if (_currentScreen->urlExtractor() && _currentScreen->urlExtractor()->reading()) {
// To handle '\e ] 8 ; <id-part> ; <url-part>' we discard
// the <id-part>. Often it is empty, but GNU libtextstyle
// may output an id here, see e.g.
......
......@@ -25,7 +25,12 @@ void EscapeSequenceUrlFilter::process()
if ((_window->screenWindow() == nullptr) && (_window->screenWindow()->screen() != nullptr)) {
return;
}
auto sWindow = _window->screenWindow();
QPointer<ScreenWindow> sWindow = _window->screenWindow();
if (!sWindow->screen()->urlExtractor()) {
return;
}
const auto urls = sWindow->screen()->urlExtractor()->history();
for (const auto &escapedUrl : urls) {
......
......@@ -20,6 +20,7 @@
#include <KConfigGroup>
// Konsole
#include "Emulation.h" // to connect the URL escape sequence extractor
#include "Enumeration.h"
#include "EscapeSequenceUrlExtractor.h"
#include "Screen.h"
......@@ -277,10 +278,17 @@ void SessionManager::applyProfile(Session *session, const Profile::Ptr &profile,
if (apply.shouldApply(Profile::SilenceSeconds)) {
session->setMonitorSilenceSeconds(profile->silenceSeconds());
}
for (TerminalDisplay *view : session->views()) {
view->screenWindow()->screen()->urlExtractor()->setAllowedLinkSchema(profile->escapedLinksSchema());
view->screenWindow()->screen()->setReflowLines(profile->property<bool>(Profile::ReflowLines));
if (apply.shouldApply(Profile::AllowEscapedLinks) || apply.shouldApply(Profile::ReflowLines)) {
const bool shouldEnableUrlExtractor = profile->allowEscapedLinks();
const bool enableReflowLines = profile->allowEscapedLinks();
for (TerminalDisplay *view : session->views()) {
view->screenWindow()->screen()->setReflowLines(enableReflowLines);
view->screenWindow()->screen()->setEnableUrlExtractor(shouldEnableUrlExtractor);
if (shouldEnableUrlExtractor) {
view->screenWindow()->screen()->urlExtractor()->setAllowedLinkSchema(profile->escapedLinksSchema());
connect(session->emulation(), &Emulation::toggleUrlExtractionRequest, view->screenWindow()->screen()->urlExtractor(), &EscapeSequenceUrlExtractor::toggleUrlInput);
}
}
}
}
......
......@@ -140,8 +140,11 @@ void TerminalDisplay::setScreenWindow(ScreenWindow *window)
_screenWindow->setWindowLines(_lines);
auto profile = SessionManager::instance()->sessionProfile(_sessionController->session());
_screenWindow->screen()->urlExtractor()->setAllowedLinkSchema(profile->escapedLinksSchema());
_screenWindow->screen()->setReflowLines(profile->property<bool>(Profile::ReflowLines));
if (_screenWindow->screen()->urlExtractor()) {
_screenWindow->screen()->urlExtractor()->setAllowedLinkSchema(profile->escapedLinksSchema());
}
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment