Support for an arbitrary number of internal clipboard buffers to copy/paste from

This commit is contained in:
Kovid Goyal 2019-02-19 20:41:23 +05:30
parent 6507fd1ac2
commit cb2d162bec
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 56 additions and 1 deletions

View File

@ -7,10 +7,13 @@ To update |kitty|, :doc:`follow the instructions <binary>`.
0.14.0 [future]
---------------------
- macOS: The default behavior of the Option key has changed, to generating
- macOS: The default behavior of the Option key has changed. It now generates
unicode characters rather than acting as the Alt modifier. See
:opt:`macos_option_as_alt`.
- Support for an arbitrary number of internal clipboard buffers to copy/paste
from, see (:ref:`cpbuf`)
- macOS: Allow opening new kitty tabs/top-level windows from Finder
(:pull:`1350`)

View File

@ -36,6 +36,8 @@ kitty - the fast, featureful, GPU based terminal emulator
separate window using arbitrary programs of your choice. This is useful for
browsing the history comfortably in a pager or editor.
* Has :ref:`multiple copy/paste buffers <cpbuf>`, like vim.
.. figure:: screenshots/screenshot.png
:alt: Screenshot, showing three programs in the 'Tall' layout
@ -394,6 +396,23 @@ If you wish to store very large amounts of scrollback to view using the piping o
:sc:`show_scrollback` features, you can use the :opt:`scrollback_pager_history_size`
option.
.. _cpbuf:
Multiple copy/paste buffers
-----------------------------
In addition to being able to copy/paste from the system clipboard, in |kitty| you
can also setup an arbitrary number of copy paste buffers. To do so, simply add
something like the following to your :file:`kitty.conf`::
map f1 copy_to_buffer a
map f2 paste_from_buffer a
This will allow you to press :kbd:`F1` to copy the current selection to an
internal buffer named ``a`` and :kbd:`F2` to paste from that buffer. The buffer
names are arbitrary strings, so you can define as many such buffers as you
need.
Frequently Asked Questions
---------------------------------

View File

@ -106,6 +106,7 @@ class Boss:
def __init__(self, os_window_id, opts, args, cached_values, new_os_window_trigger):
set_draw_minimal_borders(opts)
self.clipboard_buffers = {}
self.update_check_process = None
self.window_id_map = WeakValueDictionary()
self.startup_colors = {k: opts[k] for k in opts if isinstance(opts[k], Color)}
@ -814,6 +815,28 @@ class Boss:
if self.opts.copy_on_select:
set_clipboard_string(text)
def copy_to_buffer(self, buffer_name):
w = self.active_window
if w is not None and not w.destroyed:
text = w.text_for_selection()
if text:
if buffer_name == 'clipboard':
set_clipboard_string(text)
elif buffer_name == 'primary':
set_primary_selection(text)
else:
self.clipboard_buffers[buffer_name] = text
def paste_from_buffer(self, buffer_name):
if buffer_name == 'clipboard':
text = get_clipboard_string()
elif buffer_name == 'primary':
text = get_primary_selection()
else:
text = self.clipboard_buffers.get(buffer_name)
if text:
self.paste_to_active_window(text)
def goto_tab(self, tab_num):
tm = self.active_tab_manager
if tm is not None:

View File

@ -140,6 +140,16 @@ def clear_terminal(func, rest):
return func, args
@func_with_args('copy_to_buffer')
def copy_to_buffer(func, rest):
return func, [rest]
@func_with_args('paste_from_buffer')
def paste_from_buffer(func, rest):
return func, [rest]
@func_with_args('neighboring_window')
def neighboring_window(func, rest):
rest = rest.lower()