Drafter.ThemeManager (drafter v0.3.2)

Copy Markdown View Source

GenServer that holds the active theme and notifies the running application on change.

The active theme defaults to Drafter.Theme.dark_theme/0 on startup. Call set_theme/1 with a theme name string (e.g. "nord") to switch themes at runtime; the registered app process receives a {:theme_updated, theme} message which triggers a re-render. Use register_app/1 to associate the app loop PID.

Summary

Functions

Returns a specification to start this module under a supervisor.

The active theme for the calling session.

Register the app loop process to receive {:theme_updated, theme} on each change.

Switch the active theme by name, as Drafter.Theme.get_theme/1 resolves it.

Start a theme manager.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

get_current_theme()

@spec get_current_theme() :: Drafter.Theme.t()

The active theme for the calling session.

Resolved through Drafter.Session.Context, so it raises when no theme manager is reachable.

register_app(app_pid)

@spec register_app(pid()) :: :ok

Register the app loop process to receive {:theme_updated, theme} on each change.

Only one process is registered at a time; registering again replaces the previous one. Asynchronous.

set_theme(theme_name)

@spec set_theme(String.t()) :: :ok

Switch the active theme by name, as Drafter.Theme.get_theme/1 resolves it.

A name no built-in theme matches is silently ignored and the active theme is left alone. Asynchronous: returns :ok before the switch has happened.

start_link(opts \\ [])

@spec start_link(keyword()) :: GenServer.on_start()

Start a theme manager.

Options

  • :name - registered name, or nil to start it unnamed for a single session. Default: Drafter.ThemeManager.

Any other options are accepted and ignored; the starting theme is always Drafter.Theme.dark_theme/0.