Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] support plugins that implement new commands #1309

Closed
wants to merge 41 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
736a25e
support for color theme plugins
geier Jun 24, 2023
2944bc6
create khal.api.__all__[]
geier Oct 26, 2023
c012763
add json option to at command
mattorib May 6, 2021
ba37507
added list json formatting
mattorib May 6, 2021
148688d
fix color wrap
mattorib May 7, 2021
e6ce833
fixed formatting
mattorib May 7, 2021
d6b209c
added missing tail reset
mattorib May 7, 2021
1dc28db
fix search formatter usage
mattorib May 7, 2021
7f2bc5c
fixed missing human_formatter
mattorib May 7, 2021
339d722
fix formatter usage in test
mattorib May 7, 2021
94bd650
added colors param to human formatter
mattorib May 7, 2021
01f44c8
fix formatter usage in test
mattorib May 7, 2021
3809a31
added cli tests
mattorib May 8, 2021
2eee84c
added json option to search
mattorib May 8, 2021
15fcb76
moved formatters to util
mattorib May 8, 2021
27f5a6f
add json to new
mattorib May 8, 2021
a9c0fde
corrected style
mattorib May 8, 2021
5e88921
added test for human_formatter width
mattorib May 8, 2021
323c849
update method docs
mattorib May 8, 2021
c5bb949
update usage doc
mattorib May 8, 2021
e2a058b
add json feature to changelog
mattorib May 8, 2021
ee9546b
rename event.format to event.attributes
mattorib May 8, 2021
e05a256
added special field formatting
mattorib May 8, 2021
cd49710
added missing formatter
mattorib May 9, 2021
07c96f6
add self to authors :)
mattorib May 9, 2021
6d0412d
add list of content attributes
mattorib May 10, 2021
a80fdaa
added all fields option for json
mattorib May 10, 2021
98eae0a
fix long lines
mattorib May 10, 2021
126263c
fix formatter mistakes
mattorib May 11, 2021
293fce7
remove unnecessary dict call
mattorib May 11, 2021
1b97108
remove mutable default arguments
mattorib May 11, 2021
35b24a3
add to json option docs
mattorib May 11, 2021
d52a564
added missing format template options
mattorib May 11, 2021
cf8d263
typo
mattorib May 11, 2021
a24400e
cli_test format()
geier Oct 27, 2023
1365f97
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 27, 2023
0e48b29
make ruff happy
geier Oct 27, 2023
4e555cb
mv cli, interactive_cli out of function call
geier Oct 28, 2023
4e7b398
delete dead code
geier Oct 28, 2023
05f11b3
support for plugins implementing new khal commands
geier Oct 28, 2023
34a3e39
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,4 @@ Raúl Medina - raulmgcontact [at] gmail (dot] com
Matthew Rademaker - matthew.rademaker [at] gmail [dot] com
Valentin Iovene - val [at] too [dot] gy
Julian Wollrath
Mattori Birnbaum - me [at] mattori [dot] com - https://mattori.com
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ not released yet
* NEW properties of ikhal themes (dark and light) can now be overriden from the
config file (via the new [palette] section, check the documenation)
* NEW timedelta strings can now have a leading `+`, e.g. `+1d`
* NEW Add `--json` option to output event data as JSON objects

0.11.2
======
Expand Down
57 changes: 53 additions & 4 deletions doc/source/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,21 @@ Several options are common to almost all of :program:`khal`'s commands
url-separator
A separator: " :: " that appears when there is a url.

duration
The duration of the event in terms of days, hours, months, and seconds
(abbreviated to `d`, `h`, `m`, and `s` respectively).

repeat-pattern
The raw iCal recurrence rule if the event is repeating.

all-day
A boolean indicating whether it is an all-day event or not.

categories
The categories of the event.

By default, all-day events have no times. To see a start and end time anyway simply
add `-full` to the end of any template with start/end, for instance
add `-full` to the end of any template with start/end or duration, for instance
`start-time` becomes `start-time-full` and will always show start and end times (instead
of being empty for all-day events).

Expand All @@ -191,6 +204,40 @@ Several options are common to almost all of :program:`khal`'s commands
khal list --format "{title} {description}"


.. option:: --json FIELD ...

Works similar to :option:`--format`, but instead of defining a format string a JSON
object is created for each specified field. The matching events are collected into
a JSON array. This option accepts the following subset of :option:`--format`
template options

::

title, description, uid, start, start-long, start-date,
start-date-long, start-time, end, end-long, end-date,
end-date-long, end-time, start-full, start-long-full,
start-date-full, start-date-long-full, start-time-full,
end-full, end-long-full, end-date-full, end-date-long-full,
end-time-full, repeat-symbol, location, calendar,
calendar-color, start-style, to-style, end-style,
start-end-time-style, end-necessary, end-necessary-long,
status, cancelled, organizer, url, duration, duration-full,
repeat-pattern, all-day, categories


Note that `calendar-color` will be the actual color name rather than the ANSI color code,
and the `repeat-symbol`, `status`, and `cancelled` values will have leading/trailing
whitespace stripped. Additionally, if only the special value `all` is specified then
all fields will be enabled.

Below is an example command which prints a JSON list of objects containing the title and
description of all events today.

::

khal list --json title --json description


.. option:: --day-format DAYFORMAT

works similar to :option:`--format`, but for day headings. It only has a few
Expand Down Expand Up @@ -231,8 +278,9 @@ shows all events scheduled for a given date (or datetime) range, with custom
formatting:
::

khal list [-a CALENDAR ... | -d CALENDAR ...] [--format FORMAT]
[--day-format DAYFORMAT] [--once] [--notstarted] [START [END | DELTA] ]
khal list [-a CALENDAR ... | -d CALENDAR ...]
[--format FORMAT] [--json FIELD ...] [--day-format DAYFORMAT]
[--once] [--notstarted] [START [END | DELTA] ]

START and END can both be given as dates, datetimes or times (it is assumed
today is meant in the case of only a given time) in the formats configured in
Expand Down Expand Up @@ -270,7 +318,8 @@ start.

::

khal at [-a CALENDAR ... | -d CALENDAR ...] [--format FORMAT]
khal at [-a CALENDAR ... | -d CALENDAR ...]
[--format FORMAT] [--json FIELD ...]
[--notstarted] [[START DATE] TIME | now]

calendar
Expand Down
10 changes: 10 additions & 0 deletions khal/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from typing import Callable, Dict

from .ui.colors import register_color_theme

_plugin_commands: Dict[str, Callable] = {}

def register_command(name: str, command: Callable):
_plugin_commands[name] = command

__all__ = ["register_color_theme", "register_command"]
Loading