BB.TUI.Panels.Parameters (BB.TUI v0.1.0)

Copy Markdown View Source

Parameters panel — displays robot parameters grouped by path.

Renders a tab strip in the title when remote bridges have been discovered. The Local tab shows parameters from state.parameters.list (with schema metadata from state.parameters.metadata). Bridge tabs show entries from state.parameters.remote[bridge_name], which the app populates by calling BB.Parameter.list_remote/2 whenever the user switches to that tab.

Pure function — takes state, returns a widget struct.

Summary

Functions

Returns an edit hint suffix indicating how a parameter can be edited.

Formats a parameter path list as a dot-separated string.

Formats a parameter's Spark-declared type for the Type column.

Formats a parameter value for display.

Renders the parameters panel as a Table widget. Columns depend on the selected tab: the local tab shows Parameter | Value | Type, while a bridge tab shows Parameter | Value | Type populated from the remote fetch result.

Builds the panel title as a rich %Line{} carrying the tab strip.

Functions

edit_hint(val)

@spec edit_hint(term()) :: String.t()

Returns an edit hint suffix indicating how a parameter can be edited.

Examples

iex> BB.TUI.Panels.Parameters.edit_hint(42)
" [h/l]"

iex> BB.TUI.Panels.Parameters.edit_hint(3.14)
" [h/l]"

iex> BB.TUI.Panels.Parameters.edit_hint(true)
" [enter]"

iex> BB.TUI.Panels.Parameters.edit_hint(:fast)
""

format_path(path)

@spec format_path(list()) :: String.t()

Formats a parameter path list as a dot-separated string.

Examples

iex> BB.TUI.Panels.Parameters.format_path([:controller, :kp])
"controller.kp"

iex> BB.TUI.Panels.Parameters.format_path([:speed])
"speed"

format_type(arg1)

@spec format_type(map() | nil) :: String.t()

Formats a parameter's Spark-declared type for the Type column.

Returns "—" when no schema metadata is present. Atom types render as ":float"; option-tagged types like {:integer, [min: 0, max: 100]} render as their head atom — the bounds belong in the (future) edit popup, not in a one-line table cell.

Examples

iex> BB.TUI.Panels.Parameters.format_type(nil)
"—"

iex> BB.TUI.Panels.Parameters.format_type(%{type: nil})
"—"

iex> BB.TUI.Panels.Parameters.format_type(%{type: :float})
":float"

iex> BB.TUI.Panels.Parameters.format_type(%{type: {:integer, [min: 0, max: 100]}})
":integer"

iex> BB.TUI.Panels.Parameters.format_type(%{type: {:custom, MyMod, :validate, []}})
"{:custom, MyMod, :validate, []}"

iex> BB.TUI.Panels.Parameters.format_type(%{})
"—"

format_value(val)

@spec format_value(term()) :: String.t()

Formats a parameter value for display.

Examples

iex> BB.TUI.Panels.Parameters.format_value(42)
"42"

iex> BB.TUI.Panels.Parameters.format_value(3.14159)
"3.142"

iex> BB.TUI.Panels.Parameters.format_value(true)
"true"

iex> BB.TUI.Panels.Parameters.format_value(:fast)
":fast"

render(state, focused?)

@spec render(BB.TUI.State.t(), boolean()) :: struct()

Renders the parameters panel as a Table widget. Columns depend on the selected tab: the local tab shows Parameter | Value | Type, while a bridge tab shows Parameter | Value | Type populated from the remote fetch result.

Examples

iex> state = %BB.TUI.State{parameters: %BB.TUI.State.Parameters{list: [{[:speed], 100}, {[:controller, :kp], 0.5}]}}
iex> %ExRatatui.Widgets.Table{header: header} = BB.TUI.Panels.Parameters.render(state, false)
iex> header
["Parameter", "Value", "Type"]

iex> state = %BB.TUI.State{parameters: %BB.TUI.State.Parameters{list: []}}
iex> %ExRatatui.Widgets.Table{rows: rows} = BB.TUI.Panels.Parameters.render(state, false)
iex> rows
[["No parameters defined", "", ""]]

title_line(tabs, idx, count)

@spec title_line([atom() | {:bridge, atom()}], non_neg_integer(), non_neg_integer()) ::
  ExRatatui.Text.Line.t()

Builds the panel title as a rich %Line{} carrying the tab strip.

Single-tab (local-only) state renders as Parameters (N) with a bold-cyan count. Multi-tab state renders Parameters · Local | mavlink etc., with the active tab bold-cyan. The t shortcut to cycle tabs is surfaced in the bottom status bar.

Examples

iex> %ExRatatui.Text.Line{spans: spans} =
...>   BB.TUI.Panels.Parameters.title_line([:local], 0, 5)
iex> Enum.map_join(spans, "", & &1.content)
"  5  Parameters (5) "

iex> %ExRatatui.Text.Line{spans: spans} =
...>   BB.TUI.Panels.Parameters.title_line([:local], 0, 0)
iex> Enum.map_join(spans, "", & &1.content)
"  5  Parameters "

iex> %ExRatatui.Text.Line{spans: spans} =
...>   BB.TUI.Panels.Parameters.title_line([:local, {:bridge, :mavlink}], 1, 12)
iex> Enum.map_join(spans, "", & &1.content)
"  5  Parameters · Local | mavlink (12) "