Commit f4bc91f1 authored by Martin Hostettler's avatar Martin Hostettler Committed by Kurt Hindenburg

Match OSC reply sequence terminator to OSC request terminator.

Traditionally konsole only was able to parse OSC sequences terminated with
non-standard BEL. In 324d78c0 konsole was extended to parse sequences
terminated by 7-bit ST (ESC \) as well. But the OSC responses were still
hardcoded to reply only with sequences with BEL. But replying to 7-bit ST
terminated sequences with a reply terminated by a non-standard terminator
is wrong.

This commit passes the terminator along and changes the response to match
the original request.

printf "\033]10;?\a" replies with "^[]10;rgb:fcfc/fcfc/fcfc^G"
printf "\033]10;?\033\\" replies with "^[]10;rgb:fcfc/fcfc/fcfc^[\"
parent af65698b
......@@ -399,7 +399,7 @@ Q_SIGNALS:
/**
* Emitted when terminal code requiring terminal's response received.
*/
void sessionAttributeRequest(int id);
void sessionAttributeRequest(int id, uint terminator);
/**
* Emitted when Set Cursor Style (DECSCUSR) escape sequences are sent
......
......@@ -533,7 +533,9 @@ void Vt102Emulation::processSessionAttributeRequest(int tokenSize)
}
if (value == QLatin1String("?")) {
emit sessionAttributeRequest(attribute);
// pass terminator type indication here, because OSC response terminator
// should match the terminator of OSC request.
emit sessionAttributeRequest(attribute, tokenBuffer[tokenSize]);
return;
}
......
......@@ -708,16 +708,16 @@ bool Session::isPrimaryScreen()
return _isPrimaryScreen;
}
void Session::sessionAttributeRequest(int id)
void Session::sessionAttributeRequest(int id, uint terminator)
{
switch (id) {
case TextColor:
// Get 'TerminalDisplay' (_view) foreground color
emit getForegroundColor();
emit getForegroundColor(terminator);
break;
case BackgroundColor:
// Get 'TerminalDisplay' (_view) background color
emit getBackgroundColor();
emit getBackgroundColor(terminator);
break;
}
}
......@@ -794,25 +794,32 @@ void Session::sendSignal(int signal)
}
}
void Session::reportColor(SessionAttributes r, const QColor& c)
void Session::reportColor(SessionAttributes r, const QColor& c, uint terminator)
{
#define to65k(a) (QStringLiteral("%1").arg(int(((a)*0xFFFF)), 4, 16, QLatin1Char('0')))
QString msg = QStringLiteral("\033]%1;rgb:").arg(r)
+ to65k(c.redF()) + QLatin1Char('/')
+ to65k(c.greenF()) + QLatin1Char('/')
+ to65k(c.blueF()) + QLatin1Char('\a');
+ to65k(c.blueF());
// Match termination of OSC reply to termination of OSC request.
if (terminator == '\a') { // non standard BEL terminator
msg += QLatin1Char('\a');
} else { // standard 7-bit ST terminator
msg += QStringLiteral("\033\\");
}
_emulation->sendString(msg.toUtf8());
#undef to65k
}
void Session::reportForegroundColor(const QColor& c)
void Session::reportForegroundColor(const QColor& c, uint terminator)
{
reportColor(SessionAttributes::TextColor, c);
reportColor(SessionAttributes::TextColor, c, terminator);
}
void Session::reportBackgroundColor(const QColor& c)
void Session::reportBackgroundColor(const QColor& c, uint terminator)
{
reportColor(SessionAttributes::BackgroundColor, c);
reportColor(SessionAttributes::BackgroundColor, c, terminator);
}
bool Session::kill(int signal)
......
......@@ -395,9 +395,9 @@ public:
void sendSignal(int signal);
void reportColor(SessionAttributes r, const QColor &c);
void reportForegroundColor(const QColor &c);
void reportBackgroundColor(const QColor &c);
void reportColor(SessionAttributes r, const QColor& c, uint terminator);
void reportForegroundColor(const QColor &c, uint terminator);
void reportBackgroundColor(const QColor &c, uint terminator);
bool isReadOnly() const;
void setReadOnly(bool readOnly);
......@@ -737,7 +737,7 @@ Q_SIGNALS:
* Emitted when foreground request ("\033]10;?\a") terminal code received.
* Terminal is expected send "\033]10;rgb:RRRR/GGGG/BBBB\a" response.
*/
void getForegroundColor();
void getForegroundColor(uint terminator);
/**
* Emitted when background request ("\033]11;?\a") terminal code received.
......@@ -746,7 +746,7 @@ Q_SIGNALS:
* Originally implemented to support vim's background detection feature
* (without explicitly setting 'bg=dark' within local/remote vimrc)
*/
void getBackgroundColor();
void getBackgroundColor(uint terminator);
private Q_SLOTS:
void done(int, QProcess::ExitStatus);
......@@ -775,7 +775,7 @@ private Q_SLOTS:
// Relays the signal from Emulation and sets _isPrimaryScreen
void onPrimaryScreenInUse(bool use);
void sessionAttributeRequest(int id);
void sessionAttributeRequest(int id, uint terminator);
/**
* Requests that the color the text for any tabs associated with
......
......@@ -551,16 +551,16 @@ void SessionController::sendSignal(QAction* action)
_sessionDisplayConnection->session()->sendSignal(signal);
}
void SessionController::sendForegroundColor()
void SessionController::sendForegroundColor(uint terminator)
{
const QColor c = _sessionDisplayConnection->view()->getForegroundColor();
_sessionDisplayConnection->session()->reportForegroundColor(c);
_sessionDisplayConnection->session()->reportForegroundColor(c, terminator);
}
void SessionController::sendBackgroundColor()
void Konsole::SessionController::sendBackgroundColor(uint terminator)
{
const QColor c = _sessionDisplayConnection->view()->getBackgroundColor();
_sessionDisplayConnection->session()->reportBackgroundColor(c);
_sessionDisplayConnection->session()->reportBackgroundColor(c, terminator);
}
void SessionController::toggleReadOnly()
......
......@@ -257,8 +257,8 @@ private Q_SLOTS:
void handleWebShortcutAction();
void configureWebShortcuts();
void sendSignal(QAction *action);
void sendForegroundColor();
void sendBackgroundColor();
void sendForegroundColor(uint terminator);
void sendBackgroundColor(uint terminator);
void toggleReadOnly();
// other
......
Markdown is supported
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