2013-04-08 16:52:35 +00:00
|
|
|
|
Themes
|
|
|
|
|
======
|
|
|
|
|
|
|
|
|
|
This page describes how themes work in poezio and how to create or
|
|
|
|
|
modify one.
|
|
|
|
|
|
|
|
|
|
A theme contains color attributes and character definitions. Poezio can display
|
|
|
|
|
up to **256** colors if your terminal supports it. Most of the time,
|
|
|
|
|
if it doesn’t work, that’s because the **$TERM** environnment variable is
|
|
|
|
|
wrong. For example with tmux or screen, set it to **screen-256color**, in
|
|
|
|
|
**xterm**, set it to **xterm-256color**, etc.
|
|
|
|
|
|
|
|
|
|
If your terminal doesn’t have 256 colors, only 8 colors will be available,
|
|
|
|
|
and poezio will replace the colors by one of the 8 values available.
|
|
|
|
|
Thus, some theme files may not work properly if you only have 8 colors,
|
|
|
|
|
for example light gray on dark gray may be converted to black on black, making
|
|
|
|
|
the text impossible to read).
|
|
|
|
|
|
|
|
|
|
.. note:: The default theme should work properly in any case. If not, that’s a bug.
|
|
|
|
|
|
|
|
|
|
A theme file is a python file (with the .py extension) containing a
|
2021-11-14 20:49:09 +00:00
|
|
|
|
class, inheriting the *poezio.theming.Theme* class defined into the *theming*
|
2013-04-08 16:52:35 +00:00
|
|
|
|
poezio module.
|
|
|
|
|
|
2014-12-04 14:49:48 +00:00
|
|
|
|
To check how many colors your current terminal/$TERM supports, do:
|
2013-04-08 16:52:35 +00:00
|
|
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
|
|
|
|
|
tput colors
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Create a theme
|
|
|
|
|
--------------
|
|
|
|
|
|
|
|
|
|
To create a theme named foo, create a file named foo.py into the theme
|
2014-04-23 19:34:05 +00:00
|
|
|
|
directory (by default it’s :file:`~/.local/share/poezio/themes/`) and
|
|
|
|
|
add:
|
2013-04-08 16:52:35 +00:00
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
2021-11-14 20:49:09 +00:00
|
|
|
|
from poezio.theming import Theme
|
2013-04-08 16:52:35 +00:00
|
|
|
|
|
2021-11-14 20:49:09 +00:00
|
|
|
|
class FooTheme(Theme):
|
|
|
|
|
# Define here colors for that theme
|
2013-04-08 16:52:35 +00:00
|
|
|
|
theme = FooTheme()
|
|
|
|
|
|
|
|
|
|
To define a *color pair* and assign it to the *COLOR_NAME* option, just do
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
2021-11-14 20:49:09 +00:00
|
|
|
|
class FooTheme(Theme):
|
|
|
|
|
COLOR_NAME = (fg_color, bg_color, opt_attr)
|
2013-04-08 16:52:35 +00:00
|
|
|
|
|
2013-04-08 17:17:32 +00:00
|
|
|
|
You do not have to define all the :ref:`available-options`,
|
2013-04-08 16:52:35 +00:00
|
|
|
|
you can decide that your theme will only change some options, the other
|
|
|
|
|
one will just have the default value (from the default theme).
|
|
|
|
|
|
|
|
|
|
Colors and attributes
|
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
A color pair defines how the text will be displayed on the screen. It
|
2014-04-23 19:34:05 +00:00
|
|
|
|
has a **foreground color** (``fg_color``), a **background color**
|
|
|
|
|
(``bg_color``) and an **optional attribute** (``opt_attr``).
|
2013-04-08 16:52:35 +00:00
|
|
|
|
|
|
|
|
|
Colors
|
|
|
|
|
^^^^^^
|
2014-04-23 19:34:05 +00:00
|
|
|
|
A color is a number between ``-1`` and ``255``. If it is ``-1``, this is
|
|
|
|
|
the default color defined by your terminal (for example if your terminal
|
|
|
|
|
displays white text on black by default, a ``fg_color`` of ``-1`` is white,
|
|
|
|
|
and a ``bg_color`` of ``-1`` is black). If it’s between 0 and 256 it
|
|
|
|
|
represents one of the colors on this image:
|
2013-04-08 16:52:35 +00:00
|
|
|
|
|
2013-04-09 23:37:23 +00:00
|
|
|
|
.. figure:: ./images/theme_256_colors.png
|
2013-04-08 16:52:35 +00:00
|
|
|
|
:alt: The list of all 256 colors
|
|
|
|
|
|
|
|
|
|
The list of all 256 colors
|
|
|
|
|
|
|
|
|
|
Attributes
|
|
|
|
|
^^^^^^^^^^
|
|
|
|
|
An attribute is a python string (so, it has to be surrounded by
|
2014-04-23 19:34:05 +00:00
|
|
|
|
simple or double quotes). It can be one of the following:
|
2013-04-08 16:52:35 +00:00
|
|
|
|
|
2014-04-23 19:34:05 +00:00
|
|
|
|
- ``'b'``: bold text
|
|
|
|
|
- ``'u'``: underlined text
|
2013-04-08 16:52:35 +00:00
|
|
|
|
|
|
|
|
|
Use a theme
|
|
|
|
|
-----------
|
2014-04-23 19:34:05 +00:00
|
|
|
|
To use a theme, just define the :term:`theme` option into the
|
|
|
|
|
:ref:`configuration file <config>` to the name of the theme you want
|
2013-04-08 16:52:35 +00:00
|
|
|
|
to use. If that theme is not found, the default theme will be used instead.
|
2014-04-23 19:34:05 +00:00
|
|
|
|
|
2013-04-08 16:52:35 +00:00
|
|
|
|
Note that the default theme is defined directly into poezio’s source code,
|
|
|
|
|
and not in a theme file.
|
|
|
|
|
|
|
|
|
|
Change the theme directory
|
|
|
|
|
--------------------------
|
2014-04-23 19:34:05 +00:00
|
|
|
|
To change the default theme directory
|
|
|
|
|
(:file:`~/.local/share/poezio/themes/` by default),
|
|
|
|
|
you have to change the :term:`themes_dir` option in the
|
|
|
|
|
:ref:`configuration file <config>` to the directory that
|
|
|
|
|
contains your theme files.
|
2013-04-08 16:52:35 +00:00
|
|
|
|
|
|
|
|
|
.. _available-options:
|
|
|
|
|
|
|
|
|
|
Available options
|
|
|
|
|
-----------------
|
|
|
|
|
|
|
|
|
|
.. warning:: This section is not complete.
|
|
|
|
|
|
|
|
|
|
All available options can be found into the default theme, which is into the
|
2013-04-08 17:17:32 +00:00
|
|
|
|
**theming.py** file from the poezio’s source code.
|
2014-04-23 19:34:05 +00:00
|
|
|
|
|
|
|
|
|
|
2016-07-27 17:05:27 +00:00
|
|
|
|
.. autoclass:: poezio.theming.Theme
|
2014-04-23 19:34:05 +00:00
|
|
|
|
|