Drafter.Prompt.Choice (drafter v0.6.0)

Copy Markdown View Source

One entry of a Drafter.Prompt.select/3 or Drafter.Prompt.multiselect/3 list.

label is what is shown and value is what the prompt returns. hint is extra text shown dimmed after the label. A disabled choice is shown but cannot be picked.

new/1 accepts the shorter spellings a prompt takes:

iex> Drafter.Prompt.Choice.new("Phoenix")
%Drafter.Prompt.Choice{label: "Phoenix", value: "Phoenix"}

iex> Drafter.Prompt.Choice.new(:library)
%Drafter.Prompt.Choice{label: "library", value: :library}

iex> Drafter.Prompt.Choice.new({"Phoenix app", :phoenix})
%Drafter.Prompt.Choice{label: "Phoenix app", value: :phoenix}

iex> Drafter.Prompt.Choice.new(label: "Escript", value: :escript, hint: "one file")
%Drafter.Prompt.Choice{label: "Escript", value: :escript, hint: "one file"}

Summary

Types

What new/1 accepts: a choice, a string, an atom or number, a {label, value} pair, or a keyword list or map with :label and optionally :value, :hint and :disabled. A missing :value is the label.

t()

Functions

Build a choice from any of the spellings in input/0.

Types

input()

@type input() ::
  t()
  | String.t()
  | atom()
  | number()
  | {String.t(), term()}
  | keyword()
  | map()

What new/1 accepts: a choice, a string, an atom or number, a {label, value} pair, or a keyword list or map with :label and optionally :value, :hint and :disabled. A missing :value is the label.

t()

@type t() :: %Drafter.Prompt.Choice{
  disabled: boolean(),
  hint: String.t() | nil,
  label: String.t(),
  value: term()
}

Functions

new(choice)

@spec new(input()) :: t()

Build a choice from any of the spellings in input/0.