summaryrefslogtreecommitdiff
path: root/docs/features/clipboard.rst
blob: a4b9cdf21ef7fda4eb3c21d969c198142193f00f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
Clipboard Integration
=====================

Nearly every operating system has some notion of a short-term storage area
which can be accessed by any program. Usually this is called the clipboard, but
sometimes people refer to it as the paste buffer.

``cmd2`` integrates with the operating system clipboard using the `pyperclip
<https://github.com/asweigart/pyperclip>`_ module. Command output can be sent
to the clipboard by ending the command with a greater than symbol:

.. code-block:: text

    mycommand args >

Think of it as though you are redirecting output to an unnamed, ephemeral
place, you know, like the clipboard. You can also append output to the current
contents of the clipboard by ending the command with two greater than symbols:

.. code-block:: text

    mycommand arg1 arg2 >>


Developers
----------

You can control whether the above user features of adding output to the
operating system clipboard are allowed for the user by setting the
:attr:`~cmd2.Cmd.allow_clipboard` attribute. The default value is ``True``.
Set it to ``False`` and the above functionality will generate an error
message instead of adding the output to the clipboard.
:attr:`~cmd2.Cmd.allow_clipboard` can be set upon initialization, and you can
change it at any time from within your code.

If you would like your ``cmd2`` based application to be able to use the
clipboard in additional or alternative ways, you can use the following methods
(which work uniformly on Windows, macOS, and Linux).

.. automodule:: cmd2.clipboard
    :members: