Drafter.Prompt.Style (drafter v0.6.0)

Copy Markdown View Source

The colours and symbols prompts are drawn with.

current/1 reads the colours from the active Drafter.Theme and the symbols from the active skin: :ascii gives 7-bit symbols, every other skin gives Unicode ones. Colours are left out when the NO_COLOR environment variable is set to anything but the empty string.

style = Drafter.Prompt.Style.current()
Drafter.Prompt.Style.segment(style, :accent, "?")

Roles

segment/3 styles text by role: :plain, :strong, :accent, :success, :error, :warning and :muted.

Symbols

symbol/2 looks up :question, :done, :failed, :pointer, :on, :off, :prompt, :separator, :info, :warning, :bar_full and :bar_empty. spinner/2 gives the spinner's symbol for a tick count.

Summary

Functions

The style for the calling process.

text styled for role.

The spinner's symbol at tick, cycling through the spinner's symbols.

The symbol named name.

Types

role()

@type role() :: :plain | :strong | :accent | :success | :error | :warning | :muted

t()

@type t() :: %Drafter.Prompt.Style{
  accent: Drafter.Draw.Segment.color(),
  color: boolean(),
  error: Drafter.Draw.Segment.color(),
  muted: Drafter.Draw.Segment.color(),
  spinner: [String.t()],
  success: Drafter.Draw.Segment.color(),
  symbols: %{required(atom()) => String.t()},
  warning: Drafter.Draw.Segment.color()
}

Functions

current(overrides \\ [])

@spec current(keyword()) :: t()

The style for the calling process.

overrides replaces fields of the result: :accent, :success, :error, :warning and :muted take {r, g, b} colours, :symbols a map merged over the built-in symbols, :spinner a list of symbols, and :color a boolean.

segment(style, role, text)

@spec segment(t(), role(), String.t()) :: Drafter.Draw.Segment.t()

text styled for role.

spinner(style, tick)

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

The spinner's symbol at tick, cycling through the spinner's symbols.

symbol(style, name)

@spec symbol(t(), atom()) :: String.t()

The symbol named name.