Fans events out from the terminal driver to the processes that want them.
One manager exists per session. Producers cast events to it; it delivers each one
to every subscriber whose filter accepts it, as the message
{:tui_event, event}. The event shapes are the ones listed in Drafter.Event.
Drafter.Event.Manager.subscribe(self(), &Drafter.Event.key_event?/1)
receive do
{:tui_event, {:key, key}} -> key
endA subscriber is monitored and dropped when it exits, so unsubscribing on shutdown is not required. Subscribing the same pid twice replaces its filter.
The :app_pid given at start receives every deliverable event regardless of the
subscriber list.
{:bracketed_paste, _} is withheld unless Drafter.Clipboard.paste_enabled?/0
returns true; every other event is always deliverable.
Functions without an explicit manager argument resolve it through
Drafter.Session.Context under the :event_manager key, so they address the
caller's own session.
Summary
Functions
Returns a specification to start this module under a supervisor.
Always returns :ok immediately. Retained for callers in the runtime loop.
Deliver event to this session's subscribers.
Deliver each of events in order to this session's subscribers.
Start a manager.
Subscribe subscriber_pid to this session's manager.
Subscribe subscriber_pid to manager, for a manager that is not registered
under this module's name.
Returns once every event cast before this call has been dispatched.
As sync/0, for a manager that is not globally registered.
Stop delivering events to subscriber_pid, defaulting to the calling process.
Types
@type event_filter() :: (Drafter.Event.t() -> boolean()) | :all
@type subscriber() :: pid()
@type subscription() :: {subscriber(), event_filter()}
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec drain_queue() :: :ok
Always returns :ok immediately. Retained for callers in the runtime loop.
@spec send_event(Drafter.Event.t()) :: :ok
Deliver event to this session's subscribers.
Asynchronous; use sync/0 to wait for delivery.
@spec send_events([Drafter.Event.t()]) :: :ok
Deliver each of events in order to this session's subscribers.
Asynchronous; use sync/0 to wait for delivery.
@spec start_link(keyword()) :: GenServer.on_start()
Start a manager.
Options:
:name— registered name, defaultDrafter.Event.Manager. Passnilto start it unregistered, which is what a session other than the local terminal does.:app_pid— a process that receives every deliverable event without subscribing.
@spec subscribe(pid(), event_filter()) :: :ok
Subscribe subscriber_pid to this session's manager.
Defaults to the calling process and to the :all filter. See subscribe_to/3
for the filter contract.
@spec subscribe_to(pid() | atom(), pid(), event_filter()) :: :ok
Subscribe subscriber_pid to manager, for a manager that is not registered
under this module's name.
filter is :all (the default) or a one-argument function returning true for
the events to deliver. A filter that raises is treated as no match. The
subscriber is monitored; a second subscription for the same pid replaces its
filter.
@spec sync() :: :ok
Returns once every event cast before this call has been dispatched.
A synchronous round trip through the manager, so it orders after earlier casts from the same caller. Call it before observing a subscriber's state to be sure the events sent to it have been delivered.
As sync/0, for a manager that is not globally registered.
@spec unsubscribe(pid()) :: :ok
Stop delivering events to subscriber_pid, defaulting to the calling process.
Unnecessary when the subscriber is exiting; the monitor removes it.