author | Mikael Berthe <mikael@lilotux.net> |
Sat, 04 Feb 2023 13:35:58 +0100 | |
changeset 271 | c8b8b7cc8896 |
parent 217 | e01f94e81794 |
permissions | -rw-r--r-- |
94 | 1 |
# Themes and Templates |
23 | 2 |
|
3 |
This folder contains sample templates to customize madonctl output. |
|
4 |
||
86 | 5 |
Feel free to contribute if you have nice templates or if you want to work on themes as well! |
6 |
||
7 |
## Configuration |
|
8 |
||
9 |
The template prefix directory can be set in the configuration file with the |
|
10 |
'template_directory' setting, or with the `MADONCTL_TEMPLATE_DIRECTORY` |
|
11 |
environment variable.\ |
|
12 |
If set, template files are looked up relatively from this repository first |
|
13 |
(unless they are absolute paths or start with "./" or "../"). |
|
14 |
||
15 |
The themes are located in the `themes` directory, inside the base template |
|
98
dd260cff924e
Minor documentation updates
Mikael Berthe <mikael@lilotux.net>
parents:
94
diff
changeset
|
16 |
directory (e.g. `$template_directory/themes/ansi/`). |
86 | 17 |
A theme is a collection of templates grouped in a theme directory (the name of |
98
dd260cff924e
Minor documentation updates
Mikael Berthe <mikael@lilotux.net>
parents:
94
diff
changeset
|
18 |
the directory is the name of the theme). |
86 | 19 |
|
20 |
## Themes |
|
21 |
||
22 |
To use a theme, simply specify the theme name with the --theme flag (the |
|
23 |
--output=theme flag is implied): |
|
82
9ac2281c07d7
Add 'template_directory' setting
Mikael Berthe <mikael@lilotux.net>
parents:
23
diff
changeset
|
24 |
|
86 | 25 |
madonctl timeline --limit=2 --theme=ansi |
26 |
madonctl accounts statuses --limit 5 --theme ansi |
|
27 |
||
28 |
madonctl --theme=ansi accounts notifications --list |
|
29 |
madonctl --theme=ansi stream |
|
30 |
||
31 |
Currently, if a template is missing, madonctl will fall back to the _plain_ |
|
32 |
output format. (In the future it might just fail with an error message.) |
|
94 | 33 |
|
143 | 34 |
You can set up madonctl so that a theme is used by default. See the |
35 |
[configuration](../configuration.md) page for details. |
|
36 |
||
94 | 37 |
## Templates |
38 |
||
39 |
Here's an example using a template with ANSI color escape codes (for UNIX/Linux): |
|
40 |
||
41 |
madonctl timeline --limit 2 --template-file ansi-status.tmpl |
|
42 |
||
43 |
### Template development |
|
44 |
||
143 | 45 |
Here's a list of available commands (please check the Go template documentation |
46 |
for the built-in functions): |
|
141 | 47 |
|
48 |
Function | Description |
|
49 |
-------- | ----------- |
|
217 | 50 |
`fromunix UNIXTIMESTAMP` | converts from UNIX timestamp to date |
143 | 51 |
`tolocal TEXTRFC3339DATE` | converts a RFC3339 date string to a local time |
52 |
`fromhtml HTMLTEXT` | converts HTML to plain text |
|
53 |
`wrap TEXT` | rewrap text, with indent and max width |
|
54 |
`trim TEXT` | trims text whitespace |
|
55 |
`color COLORSPEC` | sends an ANSI color code sequence |
|
141 | 56 |
|
143 | 57 |
*COLORSPEC* is a string with the following format: `[FGCOLOR][,BGCOLOR[,STYLE]]` |
58 |
or `reset`. |
|
94 | 59 |
|
98
dd260cff924e
Minor documentation updates
Mikael Berthe <mikael@lilotux.net>
parents:
94
diff
changeset
|
60 |
Examples: |
94 | 61 |
|
98
dd260cff924e
Minor documentation updates
Mikael Berthe <mikael@lilotux.net>
parents:
94
diff
changeset
|
62 |
``` |
dd260cff924e
Minor documentation updates
Mikael Berthe <mikael@lilotux.net>
parents:
94
diff
changeset
|
63 |
{{color "red"}}red text{{color "reset"}} |
dd260cff924e
Minor documentation updates
Mikael Berthe <mikael@lilotux.net>
parents:
94
diff
changeset
|
64 |
{{color ",red"}}red background{{color "reset"}} |
dd260cff924e
Minor documentation updates
Mikael Berthe <mikael@lilotux.net>
parents:
94
diff
changeset
|
65 |
{{color "white,,bold"}}bright white text{{color "reset"}} |
94 | 66 |
|
98
dd260cff924e
Minor documentation updates
Mikael Berthe <mikael@lilotux.net>
parents:
94
diff
changeset
|
67 |
Message: {{color "blue"}}{{.content | fromhtml | wrap " " 80 | trim}}{{color "reset"}} |
dd260cff924e
Minor documentation updates
Mikael Berthe <mikael@lilotux.net>
parents:
94
diff
changeset
|
68 |
``` |