Raxol.Playground.DemoHelpers (Raxol v2.6.0)

View Source

Shared helpers for playground demo TEA apps.

Small utilities that eliminate the most common duplication across demos while keeping demos self-contained and readable.

Summary

Functions

Moves a cursor index down (increment), clamped to max_index.

Returns "> " if index matches selected, else " ".

Moves a cursor index up (decrement), clamped to 0.

Cycles an index forward through a list length, wrapping around.

Returns the effective width for a demo element, clamping desired to the available width injected by the playground app. Falls back to desired when running outside the playground.

Navigate forward through input history.

Navigate backward through input history.

Functions

cursor_down(current, max_index)

@spec cursor_down(non_neg_integer(), non_neg_integer()) :: non_neg_integer()

Moves a cursor index down (increment), clamped to max_index.

cursor_prefix(index, selected)

@spec cursor_prefix(non_neg_integer(), non_neg_integer()) :: String.t()

Returns "> " if index matches selected, else " ".

cursor_up(current)

@spec cursor_up(non_neg_integer()) :: non_neg_integer()

Moves a cursor index up (decrement), clamped to 0.

cycle_next(current, count)

@spec cycle_next(non_neg_integer(), non_neg_integer()) :: non_neg_integer()

Cycles an index forward through a list length, wrapping around.

effective_width(model, desired)

@spec effective_width(map(), pos_integer()) :: pos_integer()

Returns the effective width for a demo element, clamping desired to the available width injected by the playground app. Falls back to desired when running outside the playground.

history_next(model)

@spec history_next(map()) :: map()

Navigate forward through input history.

Expects the model to have :input_history, :history_index, :input, and :cursor fields.

history_prev(model)

@spec history_prev(map()) :: map()

Navigate backward through input history.

Expects the model to have :input_history, :history_index, :input, and :cursor fields.