MingaEditor.Shell behaviour (Minga v0.1.0)

Copy Markdown View Source

Behaviour for pluggable presentation shells.

A shell owns layout, chrome, input routing, buffer lifecycle, and tab/session queries. The editor dispatches these presentation concerns to the active shell.

Summary

Types

Why a buffer was added.

Structured GUI payload returned by a shell and encoded centrally by frontend protocol modules.

Shell-specific state. Each shell defines its own struct.

Workspace state (the editing context shared by all shells).

Callbacks

Returns the agent session pid for the user's current view.

Returns the currently active tab, or nil if the shell has no tabs.

Returns the kind of the active tab.

Runs after handle_gui_action/3 has been applied to full editor state.

Returns true when the shell can render through the asynchronous pipeline path.

Blurs shell-owned bottom-panel presentation during a window focus transition.

Returns a chrome struct with draw lists for each UI region.

Returns shell-specific data that affects chrome dirty tracking.

Returns a layout struct with named rectangles for each UI region.

Drops extension sources from feature state retained inside opaque shell state.

Drops one source from feature state retained inside opaque shell state.

Finds the file tab whose snapshotted workspace has pid as active buffer.

Returns structured GUI payload data for the active shell, or nil.

Handles an agent session going down and reports whether the shell owned it.

A managed agent session restarted and the shell should refresh pid references.

Handles a shell-specific event.

Handles a shell-specific GUI action from the native frontend.

Handles a remote session disconnect and reports whether the shell owned it.

Initializes shell state from config.

Returns the input handler stack for this shell.

An agent session emitted a background event.

Calculates shell state after a workflow has prepared inert buffer metadata.

The active buffer changed.

Returns whether this shell state owns an agent session pid. Every shell must define ownership for its own state shape.

Persists shell state outside the pure Runtime transition boundary.

Runs the full render pipeline and returns updated editor state.

Associates a session pid with a tab.

Synchronizes optional agent status held by a shell.

Tracks an agent-touched file in optional shell state.

Types

buffer_add_context()

@type buffer_add_context() :: :open | :preview

Why a buffer was added.

gui_payload()

@type gui_payload() :: {atom(), term()} | nil

Structured GUI payload returned by a shell and encoded centrally by frontend protocol modules.

shell_state()

@type shell_state() :: term()

Shell-specific state. Each shell defines its own struct.

workspace()

@type workspace() :: MingaEditor.Session.State.t()

Workspace state (the editing context shared by all shells).

Callbacks

active_session(shell_state)

@callback active_session(shell_state()) :: pid() | nil

Returns the agent session pid for the user's current view.

active_tab(shell_state)

@callback active_tab(shell_state()) :: MingaEditor.State.Tab.t() | nil

Returns the currently active tab, or nil if the shell has no tabs.

active_tab_kind(shell_state)

@callback active_tab_kind(shell_state()) :: atom()

Returns the kind of the active tab.

after_gui_action(editor_state, action)

(optional)
@callback after_gui_action(editor_state :: term(), action :: term()) :: term()

Runs after handle_gui_action/3 has been applied to full editor state.

async_render?(editor_state)

@callback async_render?(editor_state :: term()) :: boolean()

Returns true when the shell can render through the asynchronous pipeline path.

blur_bottom_panel(shell_state)

@callback blur_bottom_panel(shell_state()) :: shell_state()

Blurs shell-owned bottom-panel presentation during a window focus transition.

build_chrome(editor_state, layout, scrolls, cursor_info)

@callback build_chrome(
  editor_state :: term(),
  layout :: MingaEditor.Layout.t(),
  scrolls :: map(),
  cursor_info :: term()
) :: MingaEditor.RenderPipeline.Chrome.t()

Returns a chrome struct with draw lists for each UI region.

chrome_fingerprint(editor_state)

@callback chrome_fingerprint(editor_state :: term()) :: term()

Returns shell-specific data that affects chrome dirty tracking.

compute_layout(editor_state)

@callback compute_layout(editor_state :: term()) :: MingaEditor.Layout.t()

Returns a layout struct with named rectangles for each UI region.

drop_extension_feature_state_sources(shell_state)

@callback drop_extension_feature_state_sources(shell_state()) :: shell_state()

Drops extension sources from feature state retained inside opaque shell state.

drop_feature_state_source(shell_state, source)

@callback drop_feature_state_source(
  shell_state(),
  MingaEditor.FeatureState.source()
) :: shell_state()

Drops one source from feature state retained inside opaque shell state.

find_tab_by_buffer(shell_state, pid)

@callback find_tab_by_buffer(shell_state(), pid()) :: MingaEditor.State.Tab.t() | nil

Finds the file tab whose snapshotted workspace has pid as active buffer.

gui_payload(editor_state)

@callback gui_payload(editor_state :: term()) :: gui_payload() | nil

Returns structured GUI payload data for the active shell, or nil.

handle_agent_session_down(shell_state, session_pid, reason)

(optional)
@callback handle_agent_session_down(shell_state(), session_pid :: pid(), reason :: term()) ::
  {shell_state(), boolean()}

Handles an agent session going down and reports whether the shell owned it.

handle_agent_session_restarted(shell_state, old_session_pid, new_session_pid, reason)

(optional)
@callback handle_agent_session_restarted(
  shell_state(),
  old_session_pid :: pid(),
  new_session_pid :: pid(),
  reason :: term()
) :: {shell_state(), boolean()}

A managed agent session restarted and the shell should refresh pid references.

handle_event(shell_state, workspace, event)

@callback handle_event(shell_state(), workspace(), event :: term()) ::
  {shell_state(), workspace()}

Handles a shell-specific event.

handle_gui_action(shell_state, workspace, action)

@callback handle_gui_action(shell_state(), workspace(), action :: term()) ::
  {shell_state(), workspace()}

Handles a shell-specific GUI action from the native frontend.

handle_remote_session_disconnected(shell_state, session_pid)

(optional)
@callback handle_remote_session_disconnected(shell_state(), session_pid :: pid()) ::
  {shell_state(), boolean()}

Handles a remote session disconnect and reports whether the shell owned it.

init(opts)

@callback init(opts :: keyword()) :: shell_state()

Initializes shell state from config.

input_handlers(editor_state)

@callback input_handlers(editor_state :: term()) :: %{
  overlay: [MingaEditor.Input.dispatch_handler()],
  surface: [MingaEditor.Input.dispatch_handler()]
}

Returns the input handler stack for this shell.

on_agent_event(shell_state, workspace, session_pid, event)

@callback on_agent_event(
  shell_state(),
  workspace(),
  session_pid :: pid(),
  event :: term()
) ::
  {shell_state(), workspace()}

An agent session emitted a background event.

on_buffer_added(shell_state, prev_workspace, workspace, t)

@callback on_buffer_added(
  shell_state(),
  prev_workspace :: workspace(),
  workspace(),
  MingaEditor.Shell.BufferMetadata.t()
) :: {shell_state(), workspace()}

Calculates shell state after a workflow has prepared inert buffer metadata.

on_buffer_died(shell_state, workspace, dead_pid)

@callback on_buffer_died(shell_state(), workspace(), dead_pid :: pid()) ::
  {shell_state(), workspace()}

A buffer process died.

on_buffer_switched(shell_state, workspace)

@callback on_buffer_switched(shell_state(), workspace()) :: {shell_state(), workspace()}

The active buffer changed.

owns_agent_session?(shell_state, session_pid)

@callback owns_agent_session?(shell_state(), session_pid :: pid()) :: boolean()

Returns whether this shell state owns an agent session pid. Every shell must define ownership for its own state shape.

persist_shell_state(shell_state)

(optional)
@callback persist_shell_state(shell_state()) :: shell_state()

Persists shell state outside the pure Runtime transition boundary.

render(editor_state)

@callback render(editor_state :: term()) :: term()

Runs the full render pipeline and returns updated editor state.

set_tab_session(shell_state, tab_id, arg3)

@callback set_tab_session(shell_state(), tab_id :: term(), pid() | nil) :: shell_state()

Associates a session pid with a tab.

sync_agent_status(shell_state, session_pid, status)

(optional)
@callback sync_agent_status(shell_state(), session_pid :: pid(), status :: term()) ::
  shell_state()

Synchronizes optional agent status held by a shell.

track_agent_file(shell_state, session_pid, path)

(optional)
@callback track_agent_file(shell_state(), session_pid :: pid(), path :: String.t()) ::
  shell_state()

Tracks an agent-touched file in optional shell state.