Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

x/netzo/deps/question/mod.ts>question

Full-stack Deno framework for building business web apps like internal tools, dashboards, admin panels and automated workflows.
Go to Latest
function question
import { question } from "https://deno.land/x/netzo@0.4.62/deps/question/mod.ts";

Creates a list of selectable items from which one item can be chosen. If no items are available to be selected this will return undefined without a question prompt.

This control supports filtering by the label set by the option. To get started with the default configuration set the filtering list option to true. It will try to match the characters input with the label values.

The filtering has support to be able to search by exact label value, highlight the sections on the label that is matching the string, only sort the options by the string instead to removing the non matching options, and sort the options by specificity rank or the specified manual sorting.

Controls:

  • Ctrl+c will have the question canceled and return undefined.
  • Ctrl+d will exit the whole script no questions asked with a Deno.exit().
  • Up arrow will move the selected item up once if able.
  • Down arrow will move the selected item down once if able.
  • Home will move the selected item up to the start if able.
  • End will move the selected item down to the end if able.
  • PageUp will move the selected item up by the actual list window size if able.
  • PageDown will move the selected item down by the actual list window size if able.
  • Enter will return the currently selected item.

Requires --unstable until Deno version 1.27.

Parameters

type: "list"

The list type.

label: string

The label the question will have.

options: string[]

The options the user has to choose from.

optional
listOptions: ListOptions

Returns

Promise<string | undefined>

The selected option or undefined if canceled or empty.

Creates a list of selectable items from which one item can be chosen. If no items are available to be selected this will return undefined without a question prompt.

The options parameter can also be a plain object where the key is the label and the value is the result if that option was picked.

This control supports filtering by the label set by the option. To get started with the default configuration set the filtering list option to true. It will try to match the characters input with the label values.

The filtering has support to be able to search by exact label value, highlight the sections on the label that is matching the string, only sort the options by the string instead to removing the non matching options, and sort the options by specificity rank or the specified manual sorting.

Controls:

  • Ctrl+c will have the question canceled and return undefined.
  • Ctrl+d will exit the whole script no questions asked with a Deno.exit().
  • Up arrow will move the selected item up once if able.
  • Down arrow will move the selected item down once if able.
  • Home will move the selected item up to the start if able.
  • End will move the selected item down to the end if able.
  • PageUp will move the selected item up by the actual list window size if able.
  • PageDown will move the selected item down by the actual list window size if able.
  • Enter will return the currently selected item.

Requires --unstable until Deno version 1.27.

Parameters

type: "list"

The list type.

label: string

The label the question will have.

options: Record<string, T>

The options the user has to choose from.

optional
listOptions: ListOptions

Returns

Promise<T | undefined>

The selected option or undefined if canceled or empty.

Creates a list of selectable items from which one item will be chosen. If no items are available to be selected this will return undefined without a question prompt.

This control supports filtering by the label set by the option. To get started with the default configuration set the filtering checkbox option to true. It will try to match the characters input with the label values.

The filtering has support to be able to search by exact label value, highlight the sections on the label that is matching the string, only sort the options by the string instead to removing the non matching options, and sort the options by specificity rank or the specified manual sorting.

Controls:

  • Ctrl+c will have the question canceled and return undefined.
  • Ctrl+d will exit the whole script no questions asked with a Deno.exit().
  • Ctrl+a will select/deselect all options.
  • Up arrow will move the selected item up once if able.
  • Down arrow will move the selected item down once if able.
  • Home will move the selected item up to the start if able.
  • End will move the selected item down to the end if able.
  • PageUp will move the selected item up by the actual list window size if able.
  • PageDown will move the selected item down by the actual list window size if able.
  • Space will mark/unmark the selected item.
  • Enter will return all marked items in a list.

Requires --unstable until Deno version 1.27.

Parameters

type: "checkbox"

The checkbox type.

label: string

The label the question will have.

options: string[]

The options the user has to choose from.

optional
checkboxOptions: CheckboxOptions

Returns

Promise<string[] | undefined>

The marked options or undefined if canceled or empty.

Creates a list of selectable items from which one item will be chosen. If no items are available to be selected this will return undefined without a question prompt.

The options parameter is a plain object where the key is the label and the value is a object definition how the option is represented in the list and with a value. The representation keys are:

  • dependencies: This is a value that takes a index, label, or a list of indices and labels to express the reliance of a different option. So whenever any dependant option is select this one is too. Same for deselects.
  • selected: This makes the option selected by default. If the option depends on any other options They will also be selected.
const options = {
  'Value 1': { value: 1 },
  'Value 2': { value: 2 },
  'Value 3': { value: 3 },
}
const options = {
  'Value 1': { value: 1 },
  'Value 2': { value: 2, dependencies: ['Value 1'] },
  'Value 3': { value: 3, selected: true },
}

This control supports filtering by the label set by the option. To get started with the default configuration set the filtering checkbox option to true. It will try to match the characters input with the label values.

The filtering has support to be able to search by exact label value, highlight the sections on the label that is matching the string, only sort the options by the string instead to removing the non matching options, and sort the options by specificity rank or the specified manual sorting.

Controls:

  • Ctrl+c will have the question canceled and return undefined.
  • Ctrl+d will exit the whole script no questions asked with a Deno.exit().
  • Ctrl+a will select/deselect all options.
  • Up arrow will move the selected item up once if able.
  • Down arrow will move the selected item down once if able.
  • Home will move the selected item up to the start if able.
  • End will move the selected item down to the end if able.
  • PageUp will move the selected item up by the actual list window size if able.
  • PageDown will move the selected item down by the actual list window size if able.
  • Space will mark/unmark the selected item.
  • Enter will return all marked items in a list.

Requires --unstable until Deno version 1.27.

Parameters

type: "checkbox"

The checkbox type.

label: string

The label the question will have.

options: Record<string, ObjectOption<T>>

The options the user has to choose from.

optional
checkboxOptions: CheckboxOptions

Returns

Promise<T[] | undefined>

The marked options or undefined if canceled or empty.

Create a confirmation question that resolves to a true or false based on user input. It takes an undefined, true, or false value as the default value. Each of the default value types has an effect on how the prompt looks like.

  • undefined will suffix the prompt with [y/n]
  • true will suffix the prompt with [Y/n]
  • false will suffix the prompt with [y/N]

The only valid values are anything starting with y or n uppercase or lowercase. The y and n is derived from the positive and negative labels. You can customize the labels in the options object The prompt can be canceled and will then return undefined.

Controls:

  • Ctrl+c will have the question canceled and return undefined.
  • Ctrl+d will exit the whole script no questions asked with a Deno.exit().
  • Up arrow or Home key will move the cursor to the start of the prompt text.
  • Down arrow or End key will move the cursor to the end of the prompt text.
  • Left arrow will move the cursor one step to the left once if able.
  • Right arrow will move the cursor one step to the right once if able.
  • Enter will return the parsed result of the text.

Requires --unstable until Deno version 1.27.

Parameters

type: "confirm"

The confirm type.

label: string

The label the question will have.

optional
defaultValue: boolean | ConfirmOptions | undefined

The value that will determine the resulting value if none was provided.

Returns

Promise<boolean | undefined>

The boolean value from the answer or undefined if canceled.

Create a generic text input question requesting the user to input text in a free form format. A default value can be provided and if the free form text input is blank that value will be used instead.

Controls:

  • Ctrl+c will have the question canceled and return undefined.
  • Ctrl+d will exit the whole script no questions asked with a Deno.exit().
  • Up arrow or Home key will move the cursor to the start of the prompt text.
  • Down arrow or End key will move the cursor to the end of the prompt text.
  • Left arrow will move the cursor one step to the left once if able.
  • Right arrow will move the cursor one step to the right once if able.
  • Enter will return the test inputted or the provided default value.

Requires --unstable until Deno version 1.27.

Parameters

type: "input"

The input type.

label: string

The label the question will have.

optional
defaultValue: string | undefined

The value that will determine the resulting value if none was provided.

Returns

Promise<string | undefined>

The answer text, default value text, or undefined if canceled.

Creates a free form text input that does not print the characters normally printed by the input prompt. The characters are substituted for a substitute string you can provide. If the substitute parameter is a boolean false no substitute characters will be printed.

The substitute string if longer than 1 character can be called a pattern and will also be printed in that pattern. So if you have a pattern of <> and that length of the text i 5 the substitution will look like <><><.

Controls:

  • Ctrl+c will have the question canceled and return undefined.
  • Ctrl+d will exit the whole script no questions asked with a Deno.exit().
  • Up arrow or Home key will move the cursor to the start of the prompt text.
  • Down arrow or End key will move the cursor to the end of the prompt text.
  • Left arrow will move the cursor one step to the left once if able.
  • Right arrow will move the cursor one step to the right once if able.
  • Enter will return the test inputted or the provided default value.

Requires --unstable until Deno version 1.27.

Parameters

type: "password"

The password type.

label: string

The label the question will have.

optional
substitute: boolean | string | undefined

The substitution string or boolean indicating if you want a substitution string.

Returns

Promise<string | undefined>

The answer text or undefined if canceled.