templates/README.md
author rjp <zimpenfish@gmail.com>
Mon, 23 Jan 2023 16:39:02 +0000
changeset 267 5b91a65ba95a
parent 217 e01f94e81794
permissions -rw-r--r--
Update to handle non-int64 IDs Pleroma/Akkoma and GotoSocial use opaque IDs rather than `int64`s like Mastodon which means that `madon` can't talk to either of those. This commit updates everything that can be an ID to `madon.ActivityID` which is an alias for `string` - can't create a specific type for it since there's more than a few places where they're concatenated directly to strings for URLs, etc. Which means it could just as easily be a direct `string` type itself but I find that having distinct types can often make the code more readable and understandable. One extra bit is that `statusOpts` has grown a `_hasReplyTo` boolean to indicate whether the `--in-reply-to` flag was given or not because we can't distinguish because "empty because default" or "empty because given and empty". Another way around this would be to set the default to some theoretically impossible or unlikely string but you never know when someone might spin up an instance where, e.g., admin posts have negative integer IDs.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
94
4c0206d283e5 Update template README
Mikael Berthe <mikael@lilotux.net>
parents: 86
diff changeset
     1
# Themes and Templates
23
2ba1ea451669 Add template samples
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     2
2ba1ea451669 Add template samples
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     3
This folder contains sample templates to customize madonctl output.
2ba1ea451669 Add template samples
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     4
86
9e846c5af138 Update template README
Mikael Berthe <mikael@lilotux.net>
parents: 82
diff changeset
     5
Feel free to contribute if you have nice templates or if you want to work on themes as well!
9e846c5af138 Update template README
Mikael Berthe <mikael@lilotux.net>
parents: 82
diff changeset
     6
9e846c5af138 Update template README
Mikael Berthe <mikael@lilotux.net>
parents: 82
diff changeset
     7
## Configuration
9e846c5af138 Update template README
Mikael Berthe <mikael@lilotux.net>
parents: 82
diff changeset
     8
9e846c5af138 Update template README
Mikael Berthe <mikael@lilotux.net>
parents: 82
diff changeset
     9
The template prefix directory can be set in the configuration file with the
9e846c5af138 Update template README
Mikael Berthe <mikael@lilotux.net>
parents: 82
diff changeset
    10
'template_directory' setting, or with the `MADONCTL_TEMPLATE_DIRECTORY`
9e846c5af138 Update template README
Mikael Berthe <mikael@lilotux.net>
parents: 82
diff changeset
    11
environment variable.\
9e846c5af138 Update template README
Mikael Berthe <mikael@lilotux.net>
parents: 82
diff changeset
    12
If set, template files are looked up relatively from this repository first
9e846c5af138 Update template README
Mikael Berthe <mikael@lilotux.net>
parents: 82
diff changeset
    13
(unless they are absolute paths or start with "./" or "../").
9e846c5af138 Update template README
Mikael Berthe <mikael@lilotux.net>
parents: 82
diff changeset
    14
9e846c5af138 Update template README
Mikael Berthe <mikael@lilotux.net>
parents: 82
diff changeset
    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
9e846c5af138 Update template README
Mikael Berthe <mikael@lilotux.net>
parents: 82
diff changeset
    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
9e846c5af138 Update template README
Mikael Berthe <mikael@lilotux.net>
parents: 82
diff changeset
    19
9e846c5af138 Update template README
Mikael Berthe <mikael@lilotux.net>
parents: 82
diff changeset
    20
## Themes
9e846c5af138 Update template README
Mikael Berthe <mikael@lilotux.net>
parents: 82
diff changeset
    21
9e846c5af138 Update template README
Mikael Berthe <mikael@lilotux.net>
parents: 82
diff changeset
    22
To use a theme, simply specify the theme name with the --theme flag (the
9e846c5af138 Update template README
Mikael Berthe <mikael@lilotux.net>
parents: 82
diff changeset
    23
--output=theme flag is implied):
82
9ac2281c07d7 Add 'template_directory' setting
Mikael Berthe <mikael@lilotux.net>
parents: 23
diff changeset
    24
86
9e846c5af138 Update template README
Mikael Berthe <mikael@lilotux.net>
parents: 82
diff changeset
    25
    madonctl timeline --limit=2 --theme=ansi
9e846c5af138 Update template README
Mikael Berthe <mikael@lilotux.net>
parents: 82
diff changeset
    26
    madonctl accounts statuses --limit 5 --theme ansi
9e846c5af138 Update template README
Mikael Berthe <mikael@lilotux.net>
parents: 82
diff changeset
    27
9e846c5af138 Update template README
Mikael Berthe <mikael@lilotux.net>
parents: 82
diff changeset
    28
    madonctl --theme=ansi accounts notifications --list
9e846c5af138 Update template README
Mikael Berthe <mikael@lilotux.net>
parents: 82
diff changeset
    29
    madonctl --theme=ansi stream
9e846c5af138 Update template README
Mikael Berthe <mikael@lilotux.net>
parents: 82
diff changeset
    30
9e846c5af138 Update template README
Mikael Berthe <mikael@lilotux.net>
parents: 82
diff changeset
    31
Currently, if a template is missing, madonctl will fall back to the _plain_
9e846c5af138 Update template README
Mikael Berthe <mikael@lilotux.net>
parents: 82
diff changeset
    32
output format.  (In the future it might just fail with an error message.)
94
4c0206d283e5 Update template README
Mikael Berthe <mikael@lilotux.net>
parents: 86
diff changeset
    33
143
abfa3aa97b51 Update documentation
Mikael Berthe <mikael@lilotux.net>
parents: 141
diff changeset
    34
You can set up madonctl so that a theme is used by default.  See the
abfa3aa97b51 Update documentation
Mikael Berthe <mikael@lilotux.net>
parents: 141
diff changeset
    35
[configuration](../configuration.md) page for details.
abfa3aa97b51 Update documentation
Mikael Berthe <mikael@lilotux.net>
parents: 141
diff changeset
    36
94
4c0206d283e5 Update template README
Mikael Berthe <mikael@lilotux.net>
parents: 86
diff changeset
    37
## Templates
4c0206d283e5 Update template README
Mikael Berthe <mikael@lilotux.net>
parents: 86
diff changeset
    38
4c0206d283e5 Update template README
Mikael Berthe <mikael@lilotux.net>
parents: 86
diff changeset
    39
Here's an example using a template with ANSI color escape codes (for UNIX/Linux):
4c0206d283e5 Update template README
Mikael Berthe <mikael@lilotux.net>
parents: 86
diff changeset
    40
4c0206d283e5 Update template README
Mikael Berthe <mikael@lilotux.net>
parents: 86
diff changeset
    41
    madonctl timeline --limit 2 --template-file ansi-status.tmpl
4c0206d283e5 Update template README
Mikael Berthe <mikael@lilotux.net>
parents: 86
diff changeset
    42
4c0206d283e5 Update template README
Mikael Berthe <mikael@lilotux.net>
parents: 86
diff changeset
    43
### Template development
4c0206d283e5 Update template README
Mikael Berthe <mikael@lilotux.net>
parents: 86
diff changeset
    44
143
abfa3aa97b51 Update documentation
Mikael Berthe <mikael@lilotux.net>
parents: 141
diff changeset
    45
Here's a list of available commands (please check the Go template documentation
abfa3aa97b51 Update documentation
Mikael Berthe <mikael@lilotux.net>
parents: 141
diff changeset
    46
for the built-in functions):
141
abaf660dc3fc Update documentation
Mikael Berthe <mikael@lilotux.net>
parents: 120
diff changeset
    47
abaf660dc3fc Update documentation
Mikael Berthe <mikael@lilotux.net>
parents: 120
diff changeset
    48
Function | Description
abaf660dc3fc Update documentation
Mikael Berthe <mikael@lilotux.net>
parents: 120
diff changeset
    49
-------- | -----------
217
e01f94e81794 Typo in documentation
Mikael Berthe <mikael@lilotux.net>
parents: 143
diff changeset
    50
`fromunix UNIXTIMESTAMP`  | converts from UNIX timestamp to date
143
abfa3aa97b51 Update documentation
Mikael Berthe <mikael@lilotux.net>
parents: 141
diff changeset
    51
`tolocal TEXTRFC3339DATE` | converts a RFC3339 date string to a local time
abfa3aa97b51 Update documentation
Mikael Berthe <mikael@lilotux.net>
parents: 141
diff changeset
    52
`fromhtml HTMLTEXT`       | converts HTML to plain text
abfa3aa97b51 Update documentation
Mikael Berthe <mikael@lilotux.net>
parents: 141
diff changeset
    53
`wrap TEXT`       | rewrap text, with indent and max width
abfa3aa97b51 Update documentation
Mikael Berthe <mikael@lilotux.net>
parents: 141
diff changeset
    54
`trim TEXT`       | trims text whitespace
abfa3aa97b51 Update documentation
Mikael Berthe <mikael@lilotux.net>
parents: 141
diff changeset
    55
`color COLORSPEC` | sends an ANSI color code sequence
141
abaf660dc3fc Update documentation
Mikael Berthe <mikael@lilotux.net>
parents: 120
diff changeset
    56
143
abfa3aa97b51 Update documentation
Mikael Berthe <mikael@lilotux.net>
parents: 141
diff changeset
    57
*COLORSPEC* is a string with the following format: `[FGCOLOR][,BGCOLOR[,STYLE]]`
abfa3aa97b51 Update documentation
Mikael Berthe <mikael@lilotux.net>
parents: 141
diff changeset
    58
or `reset`.
94
4c0206d283e5 Update template README
Mikael Berthe <mikael@lilotux.net>
parents: 86
diff changeset
    59
98
dd260cff924e Minor documentation updates
Mikael Berthe <mikael@lilotux.net>
parents: 94
diff changeset
    60
Examples:
94
4c0206d283e5 Update template README
Mikael Berthe <mikael@lilotux.net>
parents: 86
diff changeset
    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
4c0206d283e5 Update template README
Mikael Berthe <mikael@lilotux.net>
parents: 86
diff changeset
    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
```