PhoenixGenApiTui.State (phoenix_gen_api_tui v0.1.0)

Copy Markdown View Source

State struct and pure navigation logic for the PhoenixGenApi TUI explorer.

All state transitions are pure functions: handle_key(state, key) -> state. No side effects, no processes — just data transformation.

Summary

Functions

Returns the breadcrumb trail for the header.

Clears any notice or error message in the state.

Returns the items for the currently active detail tab.

Processes a key press and returns the updated state.

Returns the list of items shown in the navigation panel.

Creates a new state from introspection data.

Refreshes the introspection data attached to the state. Returns a new state with updated data, preserving navigation context where possible.

Returns the cached search query (updated on search input changes).

Types

t()

@type t() :: %PhoenixGenApiTui.State{
  current_function: struct() | nil,
  current_service: PhoenixGenApiTui.Introspection.ServiceInfo.t() | nil,
  current_tab: tab(),
  detail_overlay: struct() | nil,
  detail_selected: non_neg_integer(),
  focus: :nav | :detail,
  introspection: PhoenixGenApiTui.Introspection.t(),
  last_error: String.t() | nil,
  nav_selected: non_neg_integer(),
  nav_stack: [{atom(), tab()}],
  notice: String.t() | nil,
  search_input: reference() | nil,
  search_query: String.t(),
  searching: boolean(),
  show_help: boolean()
}

tab()

@type tab() ::
  :functions
  | :call_flows
  | :cluster
  | :health
  | :stats
  | :rate_limits
  | :errors
  | :system

Functions

clear_notice(state)

@spec clear_notice(t()) :: t()

Clears any notice or error message in the state.

detail_items(state)

@spec detail_items(t()) :: [term()]

Returns the items for the currently active detail tab.

handle_key(state, key)

@spec handle_key(t(), String.t()) :: t()

Processes a key press and returns the updated state.

Handles vim-style navigation (j/k/h/l), tab switching (tab, 1-6), enter/esc for selection and back-navigation, ? for help, and / for search.

new(introspection)

Creates a new state from introspection data.

Examples

iex> introspection = %PhoenixGenApiTui.Introspection{
...>   services: [%PhoenixGenApiTui.Introspection.ServiceInfo{name: MyApp.Services.UserService, functions: []}],
...>   call_flows: [], cluster_view: %{}, health_check: %{}, statistics: %{}, rate_limits: %{},
...>   status: :ok, loaded_at: 0
...> }
iex> state = PhoenixGenApiTui.State.new(introspection)
iex> state.current_service.name
MyApp.Services.UserService
iex> state.current_tab
:functions

iex> state = PhoenixGenApiTui.State.new(%PhoenixGenApiTui.Introspection{services: [], call_flows: [], cluster_view: %{}, health_check: %{}, statistics: %{}, rate_limits: %{}})
iex> state.current_service
nil

refresh(state)

@spec refresh(t()) :: t()

Refreshes the introspection data attached to the state. Returns a new state with updated data, preserving navigation context where possible.

search_query(state)

@spec search_query(t()) :: String.t()

Returns the cached search query (updated on search input changes).