Now finally it's possible to enable OSC52 for Debian's konsole!

Since konsole 24.05.2 was packaged (thanks a lot of that!)  you can apply
upstream changes
to use it.

See: https://invent.kde.org/utilities/konsole/-/merge_requests/767

That's not yet in 24.05.2 but I refactored the patchset to apply correctly
(see attached).

You need to rebuild konsole packages with those patches to use it.

For those unfamiliar, the benefit of OSC52 support is the ability to copy
to clipboard from a terminal,
so even in Wayland session when you are doing ssh to some remote host, you
can copy to clipboard
from neovim running there or any editor that supports OSC52.

It's really a major usability feature, so may be it's worth including this
in the official Debian patches
until it lands in the newer versions.

Have fun!

Shmerl.
--- a/src/Vt102Emulation.cpp
+++ b/src/Vt102Emulation.cpp
@@ -12,7 +12,9 @@
 #include <cstdio>
 
 // Qt
+#include <QApplication>
 #include <QBuffer>
+#include <QClipboard>
 #include <QEvent>
 #include <QKeyEvent>
 #include <QTimer>
@@ -1153,6 +1155,43 @@
 
         return;
     }
+
+    if (attribute == Clipboard) {
+        // Clipboard
+        QStringList params = value.split(QLatin1Char(';'));
+        if (params.length() == 0) {
+            return;
+        }
+
+        bool clipboard = false;
+        bool selection = false;
+        if (params[0].isEmpty() || params[0].contains(QLatin1Char('c')) || params[0].contains(QLatin1Char('s'))) {
+            clipboard = true;
+        }
+        if (params[0].contains(QLatin1Char('p'))) {
+            selection = true;
+        }
+
+        if (params.length() == 2) {
+            // Copy to clipboard
+            if (clipboard) {
+                QApplication::clipboard()->setText(QString::fromUtf8(QByteArray::fromBase64(params[1].toUtf8())), QClipboard::Clipboard);
+            }
+            if (selection) {
+                QApplication::clipboard()->setText(QString::fromUtf8(QByteArray::fromBase64(params[1].toUtf8())), QClipboard::Selection);
+            }
+        } else {
+            // Clear clipboard
+            if (clipboard) {
+                QApplication::clipboard()->clear(QClipboard::Clipboard);
+            }
+            if (selection) {
+                QApplication::clipboard()->clear(QClipboard::Selection);
+            }
+        }
+
+        return;
+    }
 
     if (value == QLatin1String("?")) {
         // pass terminator type indication here, because OSC response terminator
--- a/src/Vt102Emulation.h
+++ b/src/Vt102Emulation.h
@@ -126,7 +126,6 @@
     void resetModes();
 
     void resetTokenizer();
-#define MAX_TOKEN_LENGTH 256 // Max length of tokens (e.g. window title)
     void addToCurrentToken(uint cc);
     int tokenBufferPos;
 
@@ -183,6 +182,7 @@
     enum osc {
         // https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Operating-System-Commands
         ReportColors = 4,
+        Clipboard = 52,
         ResetColors = 104,
         // https://gitlab.freedesktop.org/Per_Bothner/specifications/blob/master/proposals/semantic-prompts.md
         SemanticPrompts = 133,

Reply via email to