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

Copy Markdown View Source

Commands panel — displays available robot commands with execution state.

Shows each command name with a Ready / Blocked badge based on the current runtime state. Each row is a %ExRatatui.Text.Line{} so the badge can render in its own color (green for Ready, dim for Blocked) without affecting the surrounding text. The trailing result / executing rows render as colored badges too — green ✔ for success, red ✖ for failure, yellow ⏳ while a command is in flight.

Argument editing for commands with declared arguments is handled by BB.TUI.Panels.CommandEdit, which renders as a popup above this panel while state.commands.edit_mode? is true.

Pure function — takes state, returns a widget struct.

Summary

Functions

Checks whether a command can execute in the current runtime state.

Renders the commands panel as a List widget. Arrow keys select, Enter executes when focused.

Returns the title string for the commands panel (legacy, plain string).

Returns the rich-text panel title — the count renders bold-cyan.

Functions

command_ready?(arg1, runtime_state)

@spec command_ready?(map(), atom()) :: boolean()

Checks whether a command can execute in the current runtime state.

Examples

iex> BB.TUI.Panels.Commands.command_ready?(%{allowed_states: [:idle, :executing]}, :idle)
true

iex> BB.TUI.Panels.Commands.command_ready?(%{allowed_states: [:idle]}, :executing)
false

iex> BB.TUI.Panels.Commands.command_ready?(%{}, :idle)
true

render(state, focused?)

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

Renders the commands panel as a List widget. Arrow keys select, Enter executes when focused.

Examples

iex> state = %BB.TUI.State{
...>   commands: %BB.TUI.State.Commands{
...>     available: [%{name: :home, allowed_states: [:idle]}],
...>     selected: 0, result: nil, executing: nil
...>   },
...>   safety: %BB.TUI.State.Safety{runtime: :idle}
...> }
iex> %ExRatatui.Widgets.List{items: [%ExRatatui.Text.Line{spans: spans}]} =
...>   BB.TUI.Panels.Commands.render(state, false)
iex> Enum.map_join(spans, "", & &1.content)
"home  ● Ready"

title(state)

@spec title(BB.TUI.State.t()) :: String.t()

Returns the title string for the commands panel (legacy, plain string).

Examples

iex> state = %BB.TUI.State{commands: %BB.TUI.State.Commands{available: [%{name: :a}, %{name: :b}]}}
iex> BB.TUI.Panels.Commands.title(state)
" Commands (2) "

iex> state = %BB.TUI.State{commands: %BB.TUI.State.Commands{available: []}}
iex> BB.TUI.Panels.Commands.title(state)
" Commands "

title_line(state)

@spec title_line(BB.TUI.State.t()) :: ExRatatui.Text.Line.t()

Returns the rich-text panel title — the count renders bold-cyan.

Examples

iex> state = %BB.TUI.State{commands: %BB.TUI.State.Commands{available: [%{name: :a}]}}
iex> %ExRatatui.Text.Line{spans: spans} =
...>   BB.TUI.Panels.Commands.title_line(state)
iex> Enum.map_join(spans, "", & &1.content)
"  2  Commands (1) "

iex> state = %BB.TUI.State{commands: %BB.TUI.State.Commands{available: []}}
iex> %ExRatatui.Text.Line{spans: spans} =
...>   BB.TUI.Panels.Commands.title_line(state)
iex> Enum.map_join(spans, "", & &1.content)
"  2  Commands "