# `ExRatatui.Widgets.SlashCommands`
[🔗](https://github.com/mcass19/ex_ratatui/blob/v0.7.1/lib/ex_ratatui/widgets/slash_commands.ex#L1)

Slash command parsing and autocomplete popup rendering.

Provides utilities for detecting `/command` prefixes in text input,
matching against a list of registered commands, and rendering an
autocomplete popup with the `Popup` + `List` widgets.

## Usage

    commands = [
      %SlashCommands.Command{name: "help", description: "Show help"},
      %SlashCommands.Command{name: "clear", description: "Clear chat"},
      %SlashCommands.Command{name: "quit", description: "Exit the app"}
    ]

    case SlashCommands.parse(input_text) do
      {:command, prefix} ->
        matched = SlashCommands.match_commands(commands, prefix)
        popup_widgets = SlashCommands.render_autocomplete(matched, area: area)
        # Append popup_widgets to your render list

      :no_command ->
        # No slash command detected
    end

# `match_commands`

```elixir
@spec match_commands([ExRatatui.Widgets.SlashCommands.Command.t()], String.t()) :: [
  ExRatatui.Widgets.SlashCommands.Command.t()
]
```

Filters commands whose name or aliases start with the given prefix.

Case-insensitive matching. An empty prefix matches all commands.

## Examples

    iex> cmds = [%ExRatatui.Widgets.SlashCommands.Command{name: "help"}, %ExRatatui.Widgets.SlashCommands.Command{name: "clear"}]
    iex> ExRatatui.Widgets.SlashCommands.match_commands(cmds, "hel")
    [%ExRatatui.Widgets.SlashCommands.Command{name: "help", description: "", aliases: []}]

    iex> cmds = [%ExRatatui.Widgets.SlashCommands.Command{name: "help"}]
    iex> ExRatatui.Widgets.SlashCommands.match_commands(cmds, "")
    [%ExRatatui.Widgets.SlashCommands.Command{name: "help", description: "", aliases: []}]

# `parse`

```elixir
@spec parse(String.t()) :: {:command, String.t()} | :no_command
```

Parses input text to detect a slash command prefix.

Returns `{:command, prefix}` if the text starts with `/` (after optional
leading whitespace), or `:no_command` otherwise. The prefix is the text
between `/` and the first space.

## Examples

    iex> ExRatatui.Widgets.SlashCommands.parse("/help")
    {:command, "help"}

    iex> ExRatatui.Widgets.SlashCommands.parse("/he")
    {:command, "he"}

    iex> ExRatatui.Widgets.SlashCommands.parse("/")
    {:command, ""}

    iex> ExRatatui.Widgets.SlashCommands.parse("hello")
    :no_command

    iex> ExRatatui.Widgets.SlashCommands.parse("")
    :no_command

# `render_autocomplete`

```elixir
@spec render_autocomplete(
  [ExRatatui.Widgets.SlashCommands.Command.t()],
  keyword()
) :: [{ExRatatui.widget(), ExRatatui.Layout.Rect.t()}]
```

Builds a popup widget list for autocomplete display.

Returns a list of `{widget, rect}` tuples that can be appended to
your render output. Uses `Popup` + `List` widgets.

## Options

  * `:area` (required) — the `Rect` to position the popup in
  * `:selected` — zero-based index of the selected command (default `0`)
  * `:highlight_style` — style for the selected item
  * `:style` — style for non-selected items
  * `:percent_width` — popup width as percentage (default `50`)
  * `:percent_height` — popup height as percentage (default `40`)

## Examples

    iex> alias ExRatatui.Widgets.SlashCommands
    iex> alias ExRatatui.Widgets.SlashCommands.Command
    iex> commands = [%Command{name: "help", description: "Show help"}]
    iex> area = %ExRatatui.Layout.Rect{x: 0, y: 0, width: 80, height: 24}
    iex> [{%ExRatatui.Widgets.Popup{}, %ExRatatui.Layout.Rect{}}] = SlashCommands.render_autocomplete(commands, area: area)
    iex> :ok
    :ok

---

*Consult [api-reference.md](api-reference.md) for complete listing*
