| 1 |
.. _commands-display: |
| 2 |
|
| 3 |
Display Commands |
| 4 |
================ |
| 5 |
|
| 6 |
Display command is type of command that modifies item data before displaying. |
| 7 |
The modified data are only used for displaying the item and are not stored. |
| 8 |
|
| 9 |
The command is executed just before an item needs to be displayed. This can |
| 10 |
sometimes happen multiple times for the same item if the data or |
| 11 |
configuration changes or the tab was unloaded. |
| 12 |
|
| 13 |
Display commands can be created in Command dialog by setting Type of Action |
| 14 |
to :ref:`command-dialog-display`. |
| 15 |
|
| 16 |
Use ``data()`` to retrieve current item data and ``setData()`` to set the |
| 17 |
data to display (these are not stored permanently). |
| 18 |
|
| 19 |
E.g. use slightly different color for plain text items. |
| 20 |
|
| 21 |
.. code-block:: js |
| 22 |
|
| 23 |
copyq: |
| 24 |
if ( str(data(mimeText)) && !str(data(mimeHtml)) ) { |
| 25 |
html = escapeHtml(data(mimeText)) |
| 26 |
setData(mimeHtml, '<span style="color:#764">' + html + '</span>') |
| 27 |
} |
| 28 |
|
| 29 |
E.g. try to interpret text as Markdown (with ``marked`` external utility). |
| 30 |
|
| 31 |
.. code-block:: js |
| 32 |
|
| 33 |
copyq: |
| 34 |
var text = data(mimeText) |
| 35 |
var result = execute('marked', null, text) |
| 36 |
if (result && result.exit_code == 0) { |
| 37 |
setData(mimeHtml, result.stdout) |
| 38 |
} |