summaryrefslogtreecommitdiffstats
path: root/lisp/kitty-remote-control.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/kitty-remote-control.el')
-rw-r--r--lisp/kitty-remote-control.el27
1 files changed, 27 insertions, 0 deletions
diff --git a/lisp/kitty-remote-control.el b/lisp/kitty-remote-control.el
index a5c988a..6fe7d31 100644
--- a/lisp/kitty-remote-control.el
+++ b/lisp/kitty-remote-control.el
@@ -84,5 +84,32 @@
`(("type" . "background")
("args" . ,cmd))))
+;; Clipboard handling: could be generalized
+(defvar kitty-rc-clipboard-max-length 10000
+ "Maximum length of characters copied to clipboard")
+(defun kitty-rc-copy-to-clipboard (string &optional append use-primary)
+ "Copy STRING to clipboard"
+ (if-let* ((out-len (+ (* (length string) 3) 2))
+ (allowed (< out-len kitty-rc-clipboard-max-length))
+ (out-str (base64-encode-string (encode-coding-string string 'binary)))
+ (pfx (concat "\e]52;" (if use-primary "p" "c") ";"))
+ (sfx "\e\\"))
+ (progn
+ (unless append
+ (send-string-to-terminal (concat pfx "!" sfx)))
+ (send-string-to-terminal (concat pfx out-str sfx))
+ (sit-for 0.1))
+ (message "Selection too long to send to terminal")))
+
+(defun kitty-rc-interprogram-cut-function (text)
+ (when select-enable-primary
+ (kitty-rc-copy-to-clipboard text nil t))
+ (when select-enable-clipboard
+ (kitty-rc-copy-to-clipboard text nil nil)))
+
+(defun kitty-rc-set-interprogram-cut-function ()
+ (interactive)
+ (setq interprogram-cut-function #'kitty-rc-interprogram-cut-function))
+
(provide 'kitty-remote-control)
;;; kitty-remote-control.el ends here