diff --git a/docs/changelog.rst b/docs/changelog.rst index d3f9f8533..b82687970 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -25,6 +25,10 @@ To update |kitty|, :doc:`follow the instructions `. - icat kitten: Fix a regression that broke passing directories to icat (:iss:`1683`) +- clipboard kitten: Add a :opt:`kitty +kitten clipboard --wait-for-completion` + option to have the kitten wait till copying to clipboard is complete + (:iss:`1693`) + - Linux: Disable the Wayland backend on GNOME by default as GNOME has no support for server side decorations. Can be controlled by :opt:`linux_display_server`. diff --git a/kittens/clipboard/main.py b/kittens/clipboard/main.py index 59fda97d1..9ae135e49 100644 --- a/kittens/clipboard/main.py +++ b/kittens/clipboard/main.py @@ -22,6 +22,12 @@ class Clipboard(Handler): if self.data_to_send is not None: self.cmd.write_to_clipboard(self.data_to_send, self.args.use_primary) if not self.args.get_clipboard: + if self.args.wait_for_completion: + # ask kitty for the TN terminfo capability and + # only quit after a response is received + self.print('\x1bP+q544e\x1b\\', end='') + self.print('Waiting for completion...') + return self.quit_loop(0) return self.cmd.request_from_clipboard(self.args.use_primary) @@ -30,6 +36,15 @@ class Clipboard(Handler): self.clipboard_contents = text self.quit_loop(0) + def on_capability_response(self, name, val): + self.quit_loop(0) + + def on_interrupt(self): + self.quit_loop(1) + + def on_eot(self): + self.quit_loop(1) + OPTIONS = r''' --get-clipboard @@ -45,6 +60,13 @@ default=False type=bool-set Use the primary selection rather than the clipboard on systems that support it, such as X11. + + +--wait-for-completion +default=False +type=bool-set +Wait till the copy to clipboard is complete before exiting. Useful if running +the kitten in a dedicated, ephemeral window. '''.format help_text = '''\ Read or write to the system clipboard. @@ -54,6 +76,7 @@ To set the clipboard text, pipe in the new text on stdin. Use the :file:`stdout`. Note that you must enable reading of clipboard in :file:`kitty.conf` first. ''' + usage = '' diff --git a/kittens/tui/handler.py b/kittens/tui/handler.py index 127c7dbc5..78fa93598 100644 --- a/kittens/tui/handler.py +++ b/kittens/tui/handler.py @@ -84,6 +84,9 @@ class Handler: def on_clipboard_response(self, text, from_primary=False): pass + def on_capability_response(self, name, val): + pass + def write(self, data): if isinstance(data, str): data = data.encode('utf-8') diff --git a/kittens/tui/loop.py b/kittens/tui/loop.py index 39f6685e9..5081533a6 100644 --- a/kittens/tui/loop.py +++ b/kittens/tui/loop.py @@ -214,9 +214,20 @@ class Loop: self.handler.on_text(chunk, self.in_bracketed_paste) def _on_dcs(self, dcs): + debug(dcs) if dcs.startswith('@kitty-cmd'): import json self.handler.on_kitty_cmd_response(json.loads(dcs[len('@kitty-cmd'):])) + elif dcs.startswith('1+r'): + from binascii import unhexlify + vals = dcs[3:].split(';') + for q in vals: + parts = q.split('=', 1) + try: + name, val = parts[0], unhexlify(parts[1]).decode('utf-8', 'replace') + except Exception: + continue + self.handler.on_capability_response(name, val) def _on_csi(self, csi): q = csi[-1]