Back to Enquirer

Enquirer Cheatsheet

support/cheatsheet copy.md

2.4.06.2 KB
Original Source

Enquirer Cheatsheet

API

State and Status

  • state - The state contains the necessary properties for rendering each part of a prompt in the terminal.
  • status - A prompt's status is either pending, answered, or cancelled.

Styling

  • Styles - Styles are the semantic colors used consistently throughout the prompts.
  • Symbols - Unicode symbols
  • Elements - Elements combine styles, unicode symbols, and text for the various parts of a prompt.
  • Transforms - Transforms are responsible for formatting user input based on prompt state and status.
  • Themes

❯ Elements

An element is a functions that is responsible for combining the styles, text and unicode symbols to display for a specific part of prompt, based on prompt's state and status.

prefix message separator indicator

❯ Transforms

objects that consist of a render function and a result function. based on the state and status of the prompt.

❯ Terminology

Whenever possible, we attempted to use familiar concepts and terminology from HTML/CSS to describe prompt behavior and attributes.

termdescription
focusedThe currently targeted choice in a visible list of choices. Similar in concept to focus in HTML and CSS.
pointerMarks the choice that currently has focus. The symbol is often used for this, but the pointer is not always visible, as with the autocomplete prompt.
indicatorDesignates whether or not a choice is checked/enabled.
indexThe zero-based position of the pointer in the visible list of choices.
cursorThe zero-based position of the cursor relative to user input.
selectedThe position of the currently choice.
enabledThe position of the currently choice.
activeThe position of the currently choice.
elementElements are the various parts of a prompt. An element may consist of styles, text and unicode symbols.

❯ Keypresses

TODO - insert keypresses here.

<hr>

❯ Properties

Getters

termdescription
prompt.focusedGets the currently selected choice. Equivalent to prompt.choices[prompt.index].
<hr>

❯ Methods

termdescription
focusSets focus on the specified choice, if it can be focused.
<hr>

❯ Options

nametypedefaultdescription
stdinstreamprocess.stdinThe input stream to use for emitting keypress events.
stdoutstreamprocess.stdoutThe output stream to use for writing the prompt to the terminal.
autofocus`stringnumber`undefined
<hr>

❯ State

<hr>

❯ Styles

Styles are semantically-named functions that may be used for adding color (via ANSI style codes) to the various elements of a prompt.

Default palette

NameDefault colorsDescription
primarycyanUsed on the prompt indicator, choice pointers, and to style user input (the "answer") in the terminal after it's submitted.
dangerredUsed on error messages.
strongboldUsed on the user-defined prompt message
successgreenUsed on enabled choice indicators.
warningyellowNot used.
muteddimUsed on hints.
disabledgrayUsed on disabled choice messages.
darkdim.grayUsed by other styles.
defaultnoop (no styling is applied)Not used.
infostyles.primaryUsed by the confirm prompt for styling user-input.
inverseInverse of styles.primaryNot used.
complementComplement of styles.primaryNot used.
answeredstyles.primaryUsed in several prompts to style user input after submitted.
cancelledstyles.dangerUsed to style the prompt prefix when the prompt is cancelled.
completingstyles.defaultNot used.
pendingstyles.defaultNot used.
onstyles.successUsed on checked choice indicators.
offstyles.darkUsed on unchecked choice indicators (radio buttons, checkboxes, check marks, etc.)
activestyles.primary
selectedstyles.active.underline
placeholderstyles.primary.dim
highlightstyles.inverse

The [ansi-colors][] library is used to apply styling.

Applying styles

If you are a prompt author, styles may be accessed using prompt.styles (or this.styles inside a prompt instance), where each "style" is a function that wraps the returned string in ANSI codes.

<hr>

❯ Events

EventDescription
stateA clone of the prompt.state object is emitted for each keypress.
alertEmitted when prompt.alert() is called. This is useful for detecting invalid keypresses when output is not visible in the terminal (as in unit tests).
submitEmitted with the answer value when submitted by the user.
cancelEmitted when the prompt is terminated by the user or an error is thrown.
closeEmitted when the readline interface is closed and the input stream is paused.
runEmitted when the prompt has been initialized.