Drafter.SkinManager (drafter v0.3.1)

Copy Markdown View Source

Per-session GenServer that holds the active rendering skin and notifies the running application on change.

The skin controls which character set Drafter.CharacterSet returns for every widget lookup. Three built-in skins are available:

SkinDescription
:graphicalUnicode block + braille characters (default)
:wireframeUnicode box-drawing, block fill, minimal decoration
:ascii7-bit ASCII only — maximum compatibility

Switching skins at runtime causes all widgets to re-render using the new character set on the next frame.

Usage

Drafter.set_skin(:wireframe)
Drafter.set_skin(:ascii)
Drafter.set_skin(:graphical)

Drafter.SkinManager.get_current_skin()
Drafter.SkinManager.available_skins()

Summary

Functions

Returns the list of registered skin names.

Returns a specification to start this module under a supervisor.

The active skin atom.

Register the app loop process to receive {:skin_updated, skin} messages.

Switch the active skin, sending {:skin_updated, skin} to the registered app.

Start a skin manager.

Functions

available_skins()

@spec available_skins() :: [atom()]

Returns the list of registered skin names.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

get_current_skin()

@spec get_current_skin() :: atom()

The active skin atom.

Reads the calling process's own :drafter_skin first, then asks its session's skin manager, and finally falls back to :graphical when neither is set. Never raises, unlike set_skin/1 and register_app/1.

register_app(app_pid)

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

Register the app loop process to receive {:skin_updated, skin} messages.

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

set_skin(skin)

@spec set_skin(atom()) :: :ok

Switch the active skin, sending {:skin_updated, skin} to the registered app.

Asynchronous. Any atom is accepted, including one available_skins/0 does not list; character lookups then fall back to the built-in defaults. Resolved through Drafter.Session.Context, so it raises when no skin manager is reachable.

start_link(opts \\ [])

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

Start a skin manager.

Options

Any other options are accepted and ignored; the starting skin is always :graphical.